def test_instance_creation(self): order = BybitPerpetualInFlightOrder(client_order_id="C1", exchange_order_id="X1", trading_pair="BTC-USDT", order_type=OrderType.LIMIT, trade_type=TradeType.SELL, price=Decimal("35000"), amount=Decimal("1.1"), leverage=10, position=PositionAction.OPEN.name) self.assertEqual("C1", order.client_order_id) self.assertEqual("X1", order.exchange_order_id) self.assertEqual("BTC-USDT", order.trading_pair) self.assertEqual(OrderType.LIMIT, order.order_type) self.assertEqual(TradeType.SELL, order.trade_type) self.assertEqual(Decimal("35000"), order.price) self.assertEqual(Decimal("1.1"), order.amount) self.assertEqual(Decimal("0"), order.executed_amount_base) self.assertEqual(Decimal("0"), order.executed_amount_quote) self.assertEqual(order.quote_asset, order.fee_asset) self.assertEqual(Decimal("0"), order.fee_paid) self.assertEqual("Created", order.last_state) self.assertEqual(10, order.leverage) self.assertEqual(PositionAction.OPEN.name, order.position)
def test_update_with_trade_update_quote_amount_for_non_usdt_orders(self): order = BybitPerpetualInFlightOrder(client_order_id="C1", exchange_order_id="X1", trading_pair="BTC-USD", order_type=OrderType.LIMIT, trade_type=TradeType.SELL, price=Decimal("35000"), amount=Decimal("1.1"), leverage=10, position=PositionAction.OPEN.name) valid_trade_update = { "symbol": "BTCUSD", "side": "Buy", "order_id": "X1", "exec_id": "T1", "order_link_id": "C1", "price": "8000", "order_qty": 10000, "exec_type": "Trade", "exec_qty": 10000, "exec_fee": "0.09375", "leaves_qty": 0, "is_maker": False, "trade_time": "2020-01-14T14:07:23.629Z" } update_result = order.update_with_trade_update(valid_trade_update) self.assertTrue(update_result) self.assertEqual(Decimal("10000"), order.executed_amount_base) self.assertEqual(Decimal("1.25"), order.executed_amount_quote) self.assertEqual(Decimal("0.09375"), order.fee_paid)
def test_fee_asset_is_base_asset_for_non_usdt_quote(self): order = BybitPerpetualInFlightOrder(client_order_id="C1", exchange_order_id="X1", trading_pair="BTC-USD", order_type=OrderType.LIMIT, trade_type=TradeType.SELL, price=Decimal("35000"), amount=Decimal("1.1"), leverage=10, position=PositionAction.OPEN.name) self.assertEqual(order.base_asset, order.fee_asset)