diff options
Diffstat (limited to 'ccxt_wrapper.py')
-rw-r--r-- | ccxt_wrapper.py | 82 |
1 files changed, 47 insertions, 35 deletions
diff --git a/ccxt_wrapper.py b/ccxt_wrapper.py index d2c9b4c..c4aa94d 100644 --- a/ccxt_wrapper.py +++ b/ccxt_wrapper.py | |||
@@ -66,6 +66,13 @@ class poloniexE(poloniex): | |||
66 | def nanoseconds(): | 66 | def nanoseconds(): |
67 | return int(time.time() * 1000000000) | 67 | return int(time.time() * 1000000000) |
68 | 68 | ||
69 | def is_dust_trade(self, amount, rate): | ||
70 | if abs(amount) < decimal.Decimal("0.000001"): | ||
71 | return True | ||
72 | if abs(amount * rate) < decimal.Decimal("0.0001"): | ||
73 | return True | ||
74 | return False | ||
75 | |||
69 | def fetch_margin_balance(self): | 76 | def fetch_margin_balance(self): |
70 | """ | 77 | """ |
71 | portfolio.market.privatePostGetMarginPosition({"currencyPair": "BTC_DASH"}) | 78 | portfolio.market.privatePostGetMarginPosition({"currencyPair": "BTC_DASH"}) |
@@ -232,39 +239,9 @@ class poloniexE(poloniex): | |||
232 | 239 | ||
233 | return all_balances | 240 | return all_balances |
234 | 241 | ||
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): | 242 | def order_precision(self, symbol): |
267 | return 8 | 243 | self.load_markets() |
244 | return self.markets[symbol]['precision']['price'] | ||
268 | 245 | ||
269 | def transfer_balance(self, currency, amount, from_account, to_account): | 246 | def transfer_balance(self, currency, amount, from_account, to_account): |
270 | result = self.privatePostTransferBalance({ | 247 | result = self.privatePostTransferBalance({ |
@@ -382,14 +359,49 @@ class poloniexE(poloniex): | |||
382 | 359 | ||
383 | def create_order(self, symbol, type, side, amount, price=None, account="exchange", lending_rate=None, params={}): | 360 | def create_order(self, symbol, type, side, amount, price=None, account="exchange", lending_rate=None, params={}): |
384 | """ | 361 | """ |
385 | Wrapped to handle margin and exchange accounts | 362 | Wrapped to handle margin and exchange accounts, and get decimals |
386 | """ | 363 | """ |
364 | if type == 'market': | ||
365 | raise ExchangeError(self.id + ' allows limit orders only') | ||
366 | self.load_markets() | ||
387 | if account == "exchange": | 367 | if account == "exchange": |
388 | return self.create_exchange_order(symbol, type, side, amount, price=price, params=params) | 368 | method = 'privatePost' + self.capitalize(side) |
389 | elif account == "margin": | 369 | elif account == "margin": |
390 | return self.create_margin_order(symbol, type, side, amount, price=price, lending_rate=lending_rate, params=params) | 370 | method = 'privatePostMargin' + self.capitalize(side) |
371 | if lending_rate is not None: | ||
372 | params = self.extend({"lendingRate": lending_rate}, params) | ||
391 | else: | 373 | else: |
392 | raise NotImplementedError | 374 | raise NotImplementedError |
375 | market = self.market(symbol) | ||
376 | response = getattr(self, method)(self.extend({ | ||
377 | 'currencyPair': market['id'], | ||
378 | 'rate': self.price_to_precision(symbol, price), | ||
379 | 'amount': self.amount_to_precision(symbol, amount), | ||
380 | }, params)) | ||
381 | timestamp = self.milliseconds() | ||
382 | order = self.parse_order(self.extend({ | ||
383 | 'timestamp': timestamp, | ||
384 | 'status': 'open', | ||
385 | 'type': type, | ||
386 | 'side': side, | ||
387 | 'price': price, | ||
388 | 'amount': amount, | ||
389 | }, response), market) | ||
390 | id = order['id'] | ||
391 | self.orders[id] = order | ||
392 | return self.extend({'info': response}, order) | ||
393 | |||
394 | def price_to_precision(self, symbol, price): | ||
395 | """ | ||
396 | Wrapped to avoid float | ||
397 | """ | ||
398 | return ('{:.' + str(self.markets[symbol]['precision']['price']) + 'f}').format(price).rstrip("0").rstrip(".") | ||
399 | |||
400 | def amount_to_precision(self, symbol, amount): | ||
401 | """ | ||
402 | Wrapped to avoid float | ||
403 | """ | ||
404 | return ('{:.' + str(self.markets[symbol]['precision']['amount']) + 'f}').format(amount).rstrip("0").rstrip(".") | ||
393 | 405 | ||
394 | def common_currency_code(self, currency): | 406 | def common_currency_code(self, currency): |
395 | """ | 407 | """ |