return { "average": D("0.000001") }
if c1 == "ETH" and c2 == "BTC":
return { "average": D("0.1") }
+ if c1 == "FOO" and c2 == "BTC":
+ return { "average": D("0.1") }
self.fail("Should not be called with {}, {}".format(c1, c2))
get_ticker.side_effect = _get_ticker
repartition.return_value = {
- "DOGE": (D("0.25"), "short"),
- "BTC": (D("0.25"), "long"),
- "ETH": (D("0.25"), "long"),
- "XMR": (D("0.25"), "long"),
+ "DOGE": (D("0.20"), "short"),
+ "BTC": (D("0.20"), "long"),
+ "ETH": (D("0.20"), "long"),
+ "XMR": (D("0.20"), "long"),
+ "FOO": (D("0.20"), "long"),
}
m = market.Market(self.ccxt, self.market_args())
self.ccxt.fetch_all_balances.return_value = {
"total": D("5.0")
},
"BTC": {
- "exchange_free": D("0.075"),
+ "exchange_free": D("0.065"),
"exchange_used": D("0.02"),
- "exchange_total": D("0.095"),
- "margin_available": D("0.025"),
+ "exchange_total": D("0.085"),
+ "margin_available": D("0.035"),
"margin_in_position": D("0.01"),
- "margin_total": D("0.035"),
+ "margin_total": D("0.045"),
"total": D("0.13")
},
"ETH": {
"exchange_total": D("1.0"),
"total": D("1.0")
},
+ "FOO": {
+ "exchange_free": D("0.1"),
+ "exchange_used": D("0.0"),
+ "exchange_total": D("0.1"),
+ "total": D("0.1"),
+ },
}
m.balances.fetch_balances(tag="tag")
self.assertEqual(portfolio.Amount("BTC", "-0.025"),
new_repartition["DOGE"] - values_in_base["DOGE"])
- self.assertEqual(portfolio.Amount("BTC", "0.025"),
- new_repartition["ETH"] - values_in_base["ETH"])
self.assertEqual(0,
- new_repartition["ZRC"] - values_in_base["ZRC"])
+ new_repartition["ETH"] - values_in_base["ETH"])
+ self.assertIsNone(new_repartition.get("ZRC"))
self.assertEqual(portfolio.Amount("BTC", "0.025"),
new_repartition["XMR"])
+ self.assertEqual(portfolio.Amount("BTC", "0.015"),
+ new_repartition["FOO"] - values_in_base["FOO"])
compute_trades.reset_mock()
with self.subTest(available_balance_only=True, balance=0),\
m.report.log_order.assert_called_with(order_mock2, 2, new_order=new_order_mock)
new_order_mock.run.assert_called_once_with()
+ with self.subTest("disappearing order no action to do"), \
+ mock.patch("market.ReportStore"):
+ all_orders.reset_mock()
+ m = market.Market(self.ccxt, self.market_args())
+
+ order_mock1 = mock.Mock()
+ order_mock2 = mock.Mock()
+ all_orders.side_effect = [
+ [order_mock1, order_mock2],
+ [order_mock1, order_mock2],
+
+ [order_mock1, order_mock2],
+ [order_mock1, order_mock2],
+
+ []
+ ]
+
+ order_mock1.get_status.side_effect = ["open", "closed"]
+ order_mock2.get_status.side_effect = ["open", "error_disappeared"]
+
+ order_mock1.trade = mock.Mock()
+ trade_mock = mock.Mock()
+ order_mock2.trade = trade_mock
+
+ trade_mock.tick_actions_recreate.return_value = "tick1"
+ trade_mock.prepare_order.return_value = None
+
+ m.follow_orders()
+
+ trade_mock.tick_actions_recreate.assert_called_once_with(2)
+ trade_mock.prepare_order.assert_called_once_with(compute_value="tick1")
+ m.report.log_error.assert_called_once_with("follow_orders", message=mock.ANY)
+ m.report.log_order.assert_called_with(order_mock2, 2, finished=True)
+
@mock.patch.object(market.BalanceStore, "fetch_balances")
def test_move_balance(self, fetch_balances):
for debug in [True, False]:
method_mock = mock.Mock()
method_arguments.return_value = [
method_mock,
- ["foo2", "foo"]
+ ["foo2", "foo", "foo3"]
]
+ self.m.options = { "foo3": "coucou"}
method, args = processor.parse_args("action", {"foo": "bar", "foo2": "bar"}, {"foo": "bar2", "bla": "bla"})
self.assertEqual(method_mock, method)
- self.assertEqual({"foo": "bar2", "foo2": "bar"}, args)
+ self.assertEqual({"foo": "bar2", "foo2": "bar", "foo3": "coucou"}, args)
with mock.patch.object(processor, "method_arguments") as method_arguments:
method_mock = mock.Mock()