diff options
Diffstat (limited to 'ccxt_wrapper.py')
-rw-r--r-- | ccxt_wrapper.py | 75 |
1 files changed, 40 insertions, 35 deletions
diff --git a/ccxt_wrapper.py b/ccxt_wrapper.py index d2c9b4c..f30c7d2 100644 --- a/ccxt_wrapper.py +++ b/ccxt_wrapper.py | |||
@@ -232,39 +232,9 @@ class poloniexE(poloniex): | |||
232 | 232 | ||
233 | return all_balances | 233 | return all_balances |
234 | 234 | ||
235 | def create_exchange_order(self, symbol, type, side, amount, price=None, params={}): | ||
236 | return super().create_order(symbol, type, side, amount, price=price, params=params) | ||
237 | |||
238 | def create_margin_order(self, symbol, type, side, amount, price=None, lending_rate=None, params={}): | ||
239 | if type == 'market': | ||
240 | raise ExchangeError(self.id + ' allows limit orders only') | ||
241 | self.load_markets() | ||
242 | method = 'privatePostMargin' + self.capitalize(side) | ||
243 | market = self.market(symbol) | ||
244 | price = float(price) | ||
245 | amount = float(amount) | ||
246 | if lending_rate is not None: | ||
247 | params = self.extend({"lendingRate": lending_rate}, params) | ||
248 | response = getattr(self, method)(self.extend({ | ||
249 | 'currencyPair': market['id'], | ||
250 | 'rate': self.price_to_precision(symbol, price), | ||
251 | 'amount': self.amount_to_precision(symbol, amount), | ||
252 | }, params)) | ||
253 | timestamp = self.milliseconds() | ||
254 | order = self.parse_order(self.extend({ | ||
255 | 'timestamp': timestamp, | ||
256 | 'status': 'open', | ||
257 | 'type': type, | ||
258 | 'side': side, | ||
259 | 'price': price, | ||
260 | 'amount': amount, | ||
261 | }, response), market) | ||
262 | id = order['id'] | ||
263 | self.orders[id] = order | ||
264 | return self.extend({'info': response}, order) | ||
265 | |||
266 | def order_precision(self, symbol): | 235 | def order_precision(self, symbol): |
267 | return 8 | 236 | self.load_markets() |
237 | return self.markets[symbol]['precision']['price'] | ||
268 | 238 | ||
269 | def transfer_balance(self, currency, amount, from_account, to_account): | 239 | def transfer_balance(self, currency, amount, from_account, to_account): |
270 | result = self.privatePostTransferBalance({ | 240 | result = self.privatePostTransferBalance({ |
@@ -382,14 +352,49 @@ class poloniexE(poloniex): | |||
382 | 352 | ||
383 | def create_order(self, symbol, type, side, amount, price=None, account="exchange", lending_rate=None, params={}): | 353 | def create_order(self, symbol, type, side, amount, price=None, account="exchange", lending_rate=None, params={}): |
384 | """ | 354 | """ |
385 | Wrapped to handle margin and exchange accounts | 355 | Wrapped to handle margin and exchange accounts, and get decimals |
386 | """ | 356 | """ |
357 | if type == 'market': | ||
358 | raise ExchangeError(self.id + ' allows limit orders only') | ||
359 | self.load_markets() | ||
387 | if account == "exchange": | 360 | if account == "exchange": |
388 | return self.create_exchange_order(symbol, type, side, amount, price=price, params=params) | 361 | method = 'privatePost' + self.capitalize(side) |
389 | elif account == "margin": | 362 | elif account == "margin": |
390 | return self.create_margin_order(symbol, type, side, amount, price=price, lending_rate=lending_rate, params=params) | 363 | method = 'privatePostMargin' + self.capitalize(side) |
364 | if lending_rate is not None: | ||
365 | params = self.extend({"lendingRate": lending_rate}, params) | ||
391 | else: | 366 | else: |
392 | raise NotImplementedError | 367 | raise NotImplementedError |
368 | market = self.market(symbol) | ||
369 | response = getattr(self, method)(self.extend({ | ||
370 | 'currencyPair': market['id'], | ||
371 | 'rate': self.price_to_precision(symbol, price), | ||
372 | 'amount': self.amount_to_precision(symbol, amount), | ||
373 | }, params)) | ||
374 | timestamp = self.milliseconds() | ||
375 | order = self.parse_order(self.extend({ | ||
376 | 'timestamp': timestamp, | ||
377 | 'status': 'open', | ||
378 | 'type': type, | ||
379 | 'side': side, | ||
380 | 'price': price, | ||
381 | 'amount': amount, | ||
382 | }, response), market) | ||
383 | id = order['id'] | ||
384 | self.orders[id] = order | ||
385 | return self.extend({'info': response}, order) | ||
386 | |||
387 | def price_to_precision(self, symbol, price): | ||
388 | """ | ||
389 | Wrapped to avoid float | ||
390 | """ | ||
391 | return ('{:.' + str(self.markets[symbol]['precision']['price']) + 'f}').format(price).rstrip("0").rstrip(".") | ||
392 | |||
393 | def amount_to_precision(self, symbol, amount): | ||
394 | """ | ||
395 | Wrapped to avoid float | ||
396 | """ | ||
397 | return ('{:.' + str(self.markets[symbol]['precision']['amount']) + 'f}').format(amount).rstrip("0").rstrip(".") | ||
393 | 398 | ||
394 | def common_currency_code(self, currency): | 399 | def common_currency_code(self, currency): |
395 | """ | 400 | """ |