def nanoseconds():
return int(time.time() * 1000000000)
+ def is_dust_trade(self, amount, rate):
+ if abs(amount) < decimal.Decimal("0.000001"):
+ return True
+ if abs(amount * rate) < decimal.Decimal("0.0001"):
+ return True
+ return False
+
def fetch_margin_balance(self):
"""
portfolio.market.privatePostGetMarginPosition({"currencyPair": "BTC_DASH"})
self.fetch_mouvements()
self.mark_disappeared_order()
-
+ self.mark_dust_amount_remaining_order()
self.mark_finished_order()
- # FIXME: consider open order with dust remaining as closed
- def dust_amount_remaining(self):
- return self.remaining_amount() < Amount(self.amount.currency, D("0.001"))
+ def mark_dust_amount_remaining_order(self):
+ if self.market.ccxt.is_dust_trade(self.remaining_amount().value, self.rate):
+ self.status = "closed_dust_remaining"
def remaining_amount(self):
return self.amount - self.filled_amount()
self.assertEqual("0.0000001", self.s.price_to_precision("BAR", D("0.0000001")))
self.assertEqual("0", self.s.price_to_precision("FOO", D("0.000001")))
+ def test_is_dust_trade(self):
+ self.assertTrue(self.s.is_dust_trade(D("0.0000009"), D("1000")))
+ self.assertTrue(self.s.is_dust_trade(D("0.000001"), D("10")))
+ self.assertFalse(self.s.is_dust_trade(D("0.000001"), D("100")))
order.cancel()
self.m.ccxt.cancel_order.assert_not_called()
- def test_dust_amount_remaining(self):
+ def test_mark_dust_amount_remaining(self):
order = portfolio.Order("buy", portfolio.Amount("ETH", 10),
D("0.1"), "BTC", "long", self.m, "trade")
- order.remaining_amount = mock.Mock(return_value=portfolio.Amount("ETH", 1))
- self.assertFalse(order.dust_amount_remaining())
+ self.m.ccxt.is_dust_trade.return_value = False
+ order.mark_dust_amount_remaining_order()
+ self.assertEqual("pending", order.status)
- order.remaining_amount = mock.Mock(return_value=portfolio.Amount("ETH", D("0.0001")))
- self.assertTrue(order.dust_amount_remaining())
+ self.m.ccxt.is_dust_trade.return_value = True
+ order.mark_dust_amount_remaining_order()
+ self.assertEqual("closed_dust_remaining", order.status)
@mock.patch.object(portfolio.Order, "fetch")
@mock.patch.object(portfolio.Order, "filled_amount", return_value=portfolio.Amount("ETH", 1))
"status": "foo",
"datetime": "timestamp"
}
+ self.m.ccxt.is_dust_trade.return_value = False
order.fetch()
self.m.ccxt.fetch_order.assert_called_once_with(45)