async def test_load_all_async_for_futures_markets( self, binance_http_client, live_logger, monkeypatch, ): # Arrange: prepare data for monkey patch # response1 = pkgutil.get_data( # package="tests.integration_tests.adapters.binance.resources.http_responses", # resource="http_wallet_trading_fee.json", # ) response2 = pkgutil.get_data( package= "tests.integration_tests.adapters.binance.resources.http_responses", resource="http_futures_market_exchange_info.json", ) responses = [response2] # Mock coroutine for patch async def mock_send_request( self, # noqa (needed for mock) http_method: str, # noqa (needed for mock) url_path: str, # noqa (needed for mock) payload: Dict[str, str], # noqa (needed for mock) ) -> bytes: return orjson.loads(responses.pop()) # Apply mock coroutine to client monkeypatch.setattr( target=BinanceHttpClient, name="send_request", value=mock_send_request, ) self.provider = BinanceFuturesInstrumentProvider( client=binance_http_client, logger=live_logger, account_type=BinanceAccountType.FUTURES_USDT, ) # Act await self.provider.load_all_async() # Assert assert self.provider.count == 3 assert (self.provider.find( InstrumentId(Symbol("BTCUSDT-PERP"), Venue("BINANCE"))) is not None) assert (self.provider.find( InstrumentId(Symbol("ETHUSDT-PERP"), Venue("BINANCE"))) is not None) assert (self.provider.find( InstrumentId(Symbol("BTCUSDT_220325"), Venue("BINANCE"))) is not None) assert len(self.provider.currencies()) == 3 assert "BTC" in self.provider.currencies() assert "ETH" in self.provider.currencies() assert "USDT" in self.provider.currencies()
async def test_load_equity_contract_instrument(self, mocker): # Arrange instrument_id = InstrumentId.from_str("AAPL.NASDAQ") contract = IBTestStubs.contract(symbol="AAPL") contract_details = IBTestStubs.contract_details("AAPL") mocker.patch.object( self.provider._client, "reqContractDetailsAsync", return_value=self.async_return_value([contract_details]), ) mocker.patch.object( self.provider._client, "qualifyContractsAsync", return_value=self.async_return_value([contract]), ) # Act await self.provider.load(secType="STK", symbol="AAPL", exchange="NASDAQ") equity = self.provider.find(instrument_id) # Assert assert InstrumentId(symbol=Symbol("AAPL"), venue=Venue("NASDAQ")) == equity.id assert equity.asset_class == AssetClass.EQUITY assert equity.asset_type == AssetType.SPOT assert 100 == equity.multiplier assert Price.from_str("0.01") == equity.price_increment assert 2, equity.price_precision
def test_parse_instrument_id_from_str(self): # Arrange instrument_id = InstrumentId(Symbol("AUD/USD"), Venue("SIM")) # Act result = InstrumentId.from_str(str(instrument_id)) # Assert assert instrument_id == result
def test_parse_instrument_id_from_str2(self): # Arrange instrument_id = InstrumentId(Symbol("CL"), Venue("NYMEX", broker="IB")) # Act result = InstrumentId.from_str(str(instrument_id)) # Assert assert result == instrument_id
def test_instrument_id_equality(self): # Arrange venue1 = InstrumentId(Symbol("AUD/USD"), Venue("SIM")) venue2 = InstrumentId(Symbol("AUD/USD"), Venue("IDEALPRO")) venue3 = InstrumentId(Symbol("GBP/USD"), Venue("SIM")) # Act, Assert assert venue1 == venue1 assert venue1 != venue2 assert venue1 != venue3
def test_instrument_id_equality(self): # Arrange instrument_id1 = InstrumentId(Symbol("AUD/USD"), Venue("SIM")) instrument_id2 = InstrumentId(Symbol("AUD/USD"), Venue("IDEALPRO")) instrument_id3 = InstrumentId(Symbol("GBP/USD"), Venue("SIM")) # Act, Assert assert instrument_id1 == instrument_id1 assert instrument_id1 != instrument_id2 assert instrument_id1 != instrument_id3
def test_bar_type_equality(self): # Arrange instrument_id1 = InstrumentId(Symbol("AUD/USD"), Venue("SIM")) instrument_id2 = InstrumentId(Symbol("GBP/USD"), Venue("SIM")) bar_spec = BarSpecification(1, BarAggregation.MINUTE, PriceType.BID) bar_type1 = BarType(instrument_id1, bar_spec) bar_type2 = BarType(instrument_id1, bar_spec) bar_type3 = BarType(instrument_id2, bar_spec) # Act, Assert assert bar_type1 == bar_type1 assert bar_type1 == bar_type2 assert bar_type1 != bar_type3
def adabtc_binance() -> CurrencySpot: """ Return the Binance ADA/BTC instrument for backtesting. Returns ------- CurrencySpot """ return CurrencySpot( instrument_id=InstrumentId( symbol=Symbol("ADA/BTC"), venue=Venue("BINANCE"), ), local_symbol=Symbol("ADABTC"), base_currency=ADA, quote_currency=BTC, price_precision=8, size_precision=8, price_increment=Price(1e-08, precision=8), size_increment=Quantity(1e-08, precision=8), lot_size=None, max_quantity=Quantity.from_int(90000000), min_quantity=Quantity.from_int(1), max_notional=None, min_notional=Money(0.00010000, BTC), max_price=Price(1000, precision=8), min_price=Price(1e-8, precision=8), margin_init=Decimal("0"), margin_maint=Decimal("0"), maker_fee=Decimal("0.0010"), taker_fee=Decimal("0.0010"), ts_event=0, ts_init=0, )
def btcusdt_binance() -> CurrencySpot: """ Return the Binance BTC/USDT instrument for backtesting. Returns ------- CurrencySpot """ return CurrencySpot( instrument_id=InstrumentId( symbol=Symbol("BTC/USDT"), venue=Venue("BINANCE"), ), local_symbol=Symbol("BTCUSDT"), base_currency=BTC, quote_currency=USDT, price_precision=2, size_precision=6, price_increment=Price(1e-02, precision=2), size_increment=Quantity(1e-06, precision=6), lot_size=None, max_quantity=Quantity(9000, precision=6), min_quantity=Quantity(1e-06, precision=6), max_notional=None, min_notional=Money(10.00000000, USDT), max_price=Price(1000000, precision=2), min_price=Price(0.01, precision=2), margin_init=Decimal(0), margin_maint=Decimal(0), maker_fee=Decimal("0.001"), taker_fee=Decimal("0.001"), ts_event=0, ts_init=0, )
def betting_instrument_id(): return InstrumentId( Symbol( "AmericanFootball,NFL,29678534,20220207-233000,ODDS,SPECIAL,1.179082386,50214,0.0" ), Venue("BETFAIR"), )
def ethusd_ftx() -> CurrencySpot: """ Return the FTX ETH/USD instrument for backtesting. Returns ------- CurrencySpot """ return CurrencySpot( instrument_id=InstrumentId( symbol=Symbol("ETH/USD"), venue=Venue("FTX"), ), local_symbol=Symbol("ETHUSD"), base_currency=ETH, quote_currency=USD, price_precision=1, size_precision=3, price_increment=Price(1e-01, precision=1), size_increment=Quantity(1e-03, precision=3), lot_size=None, max_quantity=Quantity(9000, precision=3), min_quantity=Quantity(1e-05, precision=3), max_notional=None, min_notional=Money(10.00, USD), max_price=None, min_price=Price(0.1, precision=1), margin_init=Decimal("0.9"), margin_maint=Decimal("0.9"), maker_fee=Decimal("0.0002"), taker_fee=Decimal("0.0007"), ts_event=0, ts_init=0, )
def test_order_pending_cancel_event_to_from_dict_and_str_repr(self): # Arrange uuid = UUID4() event = OrderPendingCancel( trader_id=TraderId("TRADER-001"), strategy_id=StrategyId("SCALPER-001"), account_id=AccountId("SIM", "000"), instrument_id=InstrumentId(Symbol("BTC/USDT"), Venue("BINANCE")), client_order_id=ClientOrderId("O-2020872378423"), venue_order_id=VenueOrderId("123456"), ts_event=0, event_id=uuid, ts_init=0, ) # Act, Assert assert OrderPendingCancel.from_dict( OrderPendingCancel.to_dict(event)) == event assert ( str(event) == "OrderPendingCancel(account_id=SIM-000, instrument_id=BTC/USDT.BINANCE, client_order_id=O-2020872378423, venue_order_id=123456, ts_event=0)" # noqa ) assert ( repr(event) == f"OrderPendingCancel(trader_id=TRADER-001, strategy_id=SCALPER-001, account_id=SIM-000, instrument_id=BTC/USDT.BINANCE, client_order_id=O-2020872378423, venue_order_id=123456, event_id={uuid}, ts_event=0, ts_init=0)" # noqa )
async def test_send_request_processes_message(self): # Arrange self.engine.start() handler = [] request = DataRequest( client_id=ClientId("RANDOM"), data_type=DataType( QuoteTick, metadata={ "instrument_id": InstrumentId(Symbol("SOMETHING"), Venue("RANDOM")), "from_datetime": None, "to_datetime": None, "limit": 1000, }, ), callback=handler.append, request_id=self.uuid_factory.generate(), ts_init=self.clock.timestamp_ns(), ) # Act self.engine.request(request) await asyncio.sleep(0.1) # Assert assert self.engine.message_qsize() == 0 assert self.engine.request_count == 1 # Tear Down self.engine.stop()
def test_get_btcusdt_when_loaded_returns_expected_instrument(self): # Arrange with open(TEST_PATH + "markets.json") as response: markets = json.load(response) with open(TEST_PATH + "currencies.json") as response: currencies = json.load(response) mock_client = MagicMock() mock_client.name = "Binance" mock_client.precisionMode = 2 mock_client.markets = markets mock_client.currencies = currencies provider = CCXTInstrumentProvider(client=mock_client) provider.load_all() instrument_id = InstrumentId(Symbol("BTC/USDT"), Venue("BINANCE")) # Act instrument = provider.find(instrument_id) # Assert self.assertEqual(Instrument, type(instrument)) self.assertEqual(AssetClass.CRYPTO, instrument.asset_class) self.assertEqual(AssetType.SPOT, instrument.asset_type) self.assertEqual(BTC, instrument.base_currency) self.assertEqual(USDT, instrument.quote_currency) self.assertEqual(USDT, instrument.settlement_currency)
def test_data_response_message_str_and_repr(self): # Arrange # Act correlation_id = self.uuid_factory.generate() response_id = self.uuid_factory.generate() instrument_id = InstrumentId(Symbol("AUD/USD"), IDEALPRO) response = DataResponse( provider=BINANCE.value, data_type=DataType(QuoteTick, metadata={"InstrumentId": instrument_id}), data=[], correlation_id=correlation_id, response_id=response_id, response_timestamp=self.clock.utc_now(), ) # Assert self.assertEqual("DataResponse(<QuoteTick> {'InstrumentId': InstrumentId('AUD/USD.IDEALPRO')})", str(response)) self.assertEqual( f"DataResponse(" f"provider=BINANCE, " f"data_type=<QuoteTick> {{'InstrumentId': InstrumentId('AUD/USD.IDEALPRO')}}, " f"correlation_id={correlation_id}, " f"id={response_id}, " f"timestamp=1970-01-01 00:00:00+00:00)", repr(response), )
def ethusd_bitmex() -> CryptoSwap: """ Return the BitMEX ETH/USD perpetual swap contract for backtesting. Returns ------- CryptoSwap """ return CryptoSwap( instrument_id=InstrumentId( symbol=Symbol("ETH/USD"), venue=Venue("BITMEX"), ), base_currency=ETH, quote_currency=USD, settlement_currency=BTC, is_inverse=True, price_precision=2, size_precision=0, price_increment=Price.from_str("0.05"), size_increment=Quantity.from_int(1), max_quantity=Quantity.from_int(10000000), min_quantity=Quantity.from_int(1), max_notional=None, min_notional=None, max_price=Price.from_str("1000000.00"), min_price=Price.from_str("0.05"), margin_init=Decimal("0.02"), margin_maint=Decimal("0.007"), maker_fee=Decimal("-0.00025"), taker_fee=Decimal("0.00075"), timestamp_origin_ns=0, timestamp_ns=0, )
def test_order_cancel_rejected_with_none_venue_order_id_event_to_from_dict_and_str_repr( self): # Arrange uuid = UUID4() event = OrderCancelRejected( trader_id=TraderId("TRADER-001"), strategy_id=StrategyId("SCALPER-001"), account_id=AccountId("SIM", "000"), instrument_id=InstrumentId(Symbol("BTC/USDT"), Venue("BINANCE")), client_order_id=ClientOrderId("O-2020872378423"), venue_order_id=None, reason="ORDER_DOES_NOT_EXIST", ts_event=0, event_id=uuid, ts_init=0, ) # Act, Assert assert OrderCancelRejected.from_dict( OrderCancelRejected.to_dict(event)) == event assert ( str(event) == "OrderCancelRejected(account_id=SIM-000, instrument_id=BTC/USDT.BINANCE, client_order_id=O-2020872378423, venue_order_id=None, reason=ORDER_DOES_NOT_EXIST, ts_event=0)" # noqa ) assert ( repr(event) == f"OrderCancelRejected(trader_id=TRADER-001, strategy_id=SCALPER-001, account_id=SIM-000, instrument_id=BTC/USDT.BINANCE, client_order_id=O-2020872378423, venue_order_id=None, reason=ORDER_DOES_NOT_EXIST, event_id={uuid}, ts_event=0, ts_init=0)" # noqa )
def ethusdt_binance() -> CurrencySpot: """ Return the Binance ETH/USDT instrument for backtesting. Returns ------- CurrencySpot """ return CurrencySpot( instrument_id=InstrumentId( symbol=Symbol("ETH/USDT"), venue=Venue("BINANCE"), ), base_currency=ETH, quote_currency=USDT, price_precision=2, size_precision=5, price_increment=Price(1e-02, precision=2), size_increment=Quantity(1e-05, precision=5), lot_size=None, max_quantity=Quantity(9000, precision=5), min_quantity=Quantity(1e-05, precision=5), max_notional=None, min_notional=Money(10.00, USDT), max_price=Price(1000000, precision=2), min_price=Price(0.01, precision=2), margin_init=Decimal("1.00"), margin_maint=Decimal("0.35"), maker_fee=Decimal("0.0001"), taker_fee=Decimal("0.0001"), timestamp_origin_ns=0, timestamp_ns=0, )
def test_order_updated_event_to_from_dict_and_str_repr(self): # Arrange uuid = UUID4() event = OrderUpdated( trader_id=TraderId("TRADER-001"), strategy_id=StrategyId("SCALPER-001"), account_id=AccountId("SIM", "000"), instrument_id=InstrumentId(Symbol("BTC/USDT"), Venue("BINANCE")), client_order_id=ClientOrderId("O-2020872378423"), venue_order_id=VenueOrderId("123456"), quantity=Quantity.from_int(500000), price=Price.from_str("1.95000"), trigger=None, ts_event=0, event_id=uuid, ts_init=0, ) # Act, Assert assert OrderUpdated.from_dict(OrderUpdated.to_dict(event)) == event assert ( str(event) == "OrderUpdated(account_id=SIM-000, instrument_id=BTC/USDT.BINANCE, client_order_id=O-2020872378423, venue_order_id=123456, quantity=500_000, price=1.95000, trigger=None, ts_event=0)" # noqa ) assert ( repr(event) == f"OrderUpdated(trader_id=TRADER-001, strategy_id=SCALPER-001, account_id=SIM-000, instrument_id=BTC/USDT.BINANCE, client_order_id=O-2020872378423, venue_order_id=123456, quantity=500_000, price=1.95000, trigger=None, event_id={uuid}, ts_event=0, ts_init=0)" # noqa )
def test_instrument_id_repr(self): # Arrange instrument_id = InstrumentId(Symbol("AUD/USD"), Venue("SIM")) # Act # Assert assert "InstrumentId('AUD/USD.SIM')" == repr(instrument_id)
def test_data_response_message_str_and_repr(self): # Arrange # Act correlation_id = self.uuid_factory.generate() response_id = self.uuid_factory.generate() instrument_id = InstrumentId(Symbol("AUD/USD"), IDEALPRO) response = DataResponse( client_id=ClientId(BINANCE.value), data_type=DataType(QuoteTick, metadata={"instrument_id": instrument_id}), data=[], correlation_id=correlation_id, response_id=response_id, timestamp_ns=self.clock.timestamp_ns(), ) # Assert self.assertEqual( "DataResponse(<QuoteTick> {'instrument_id': InstrumentId('AUD/USD.IDEALPRO')})", str(response), ) self.assertEqual( f"DataResponse(" f"client_id=BINANCE, " f"data_type=<QuoteTick> {{'instrument_id': InstrumentId('AUD/USD.IDEALPRO')}}, " f"correlation_id={correlation_id}, " f"id={response_id})", repr(response), )
def parse_order_status_http( account_id: AccountId, instrument: Instrument, data: Dict[str, Any], report_id: UUID4, ts_init: int, ) -> OrderStatusReport: client_id_str = data.get("clientId") price = data.get("price") avg_px = data["avgFillPrice"] created_at = int( pd.to_datetime(data["createdAt"], utc=True).to_datetime64()) return OrderStatusReport( account_id=account_id, instrument_id=InstrumentId(Symbol(data["market"]), FTX_VENUE), client_order_id=ClientOrderId(client_id_str) if client_id_str is not None else None, venue_order_id=VenueOrderId(str(data["id"])), order_side=OrderSide.BUY if data["side"] == "buy" else OrderSide.SELL, order_type=parse_order_type(data=data, price_str="price"), time_in_force=TimeInForce.IOC if data["ioc"] else TimeInForce.GTC, order_status=parse_order_status(data), price=instrument.make_price(price) if price is not None else None, quantity=instrument.make_qty(data["size"]), filled_qty=instrument.make_qty(data["filledSize"]), avg_px=Decimal(str(avg_px)) if avg_px is not None else None, post_only=data["postOnly"], reduce_only=data["reduceOnly"], report_id=report_id, ts_accepted=created_at, ts_last=created_at, ts_init=ts_init, )
def test_load_futures_contract_instrument(self): # Arrange mock_client = MagicMock() with open(TEST_PATH + "contract_details_cl.pickle", "rb") as file: details = pickle.load(file) # noqa (S301 possible security issue) print(details) mock_client.reqContractDetails.return_value = [details] provider = IBInstrumentProvider(client=mock_client) provider.connect() instrument_id = InstrumentId( symbol=Symbol("CL"), venue=Venue("NYMEX"), ) details = { "asset_class": "COMMODITY", "expiry": "20211119", "currency": "USD", "multiplier": 1000, } # Act provider.load(instrument_id, details) future = provider.find(instrument_id) # Assert assert instrument_id == future.id assert 1000, future.multiplier assert Price.from_str("0.01") == future.price_increment assert 2, future.price_precision
def test_get_audusd_when_loaded_returns_expected_instrument(self): # Arrange mock_client = MagicMock() with open(TEST_PATH + "instruments.json") as response: instruments = json.load(response) mock_client.request.return_value = instruments provider = OandaInstrumentProvider( client=mock_client, account_id="001", load_all=True ) instrument_id = InstrumentId(Symbol("AUD/USD"), Venue("OANDA")) # Act instrument = provider.find(instrument_id) # Assert self.assertEqual(Instrument, type(instrument)) self.assertEqual(AssetClass.FX, instrument.asset_class) self.assertEqual(AssetType.SPOT, instrument.asset_type) self.assertEqual(AUD, instrument.base_currency) self.assertEqual(USD, instrument.quote_currency) self.assertEqual(USD, instrument.settlement_currency)
async def run_test(): # Arrange self.engine.start() handler = [] request = DataRequest( client_id=ClientId("RANDOM"), data_type=DataType( QuoteTick, metadata={ "InstrumentId": InstrumentId(Symbol("SOMETHING"), Venue("RANDOM")), "FromDateTime": None, "ToDateTime": None, "Limit": 1000, }, ), callback=handler.append, request_id=self.uuid_factory.generate(), timestamp_ns=self.clock.timestamp_ns(), ) # Act self.engine.send(request) await asyncio.sleep(0.1) # Assert self.assertEqual(0, self.engine.message_qsize()) self.assertEqual(1, self.engine.request_count) # Tear Down self.engine.stop()
def test_venue_data_request_message_str_and_repr(self): # Arrange, Act handler = [].append request_id = self.uuid_factory.generate() request = DataRequest( client_id=None, venue=BINANCE, data_type=DataType( TradeTick, metadata={ # str data type is invalid "instrument_id": InstrumentId(Symbol("SOMETHING"), Venue("RANDOM")), "from_datetime": None, "to_datetime": None, "limit": 1000, }, ), callback=handler, request_id=request_id, ts_init=self.clock.timestamp_ns(), ) # Assert assert ( str(request) == "DataRequest(TradeTick{'instrument_id': InstrumentId('SOMETHING.RANDOM'), 'from_datetime': None, 'to_datetime': None, 'limit': 1000})" # noqa ) assert repr(request) == ( f"DataRequest(" f"client_id=None, " f"venue=BINANCE, " f"data_type=TradeTick{{'instrument_id': InstrumentId('SOMETHING.RANDOM'), 'from_datetime': None, 'to_datetime': None, 'limit': 1000}}, " f"callback={repr(handler)}, " f"id={request_id})")
def test_order_rejected_event_to_from_dict_and_str_repr(self): # Arrange uuid = UUID4() event = OrderRejected( trader_id=TraderId("TRADER-001"), strategy_id=StrategyId("SCALPER-001"), account_id=AccountId("SIM", "000"), instrument_id=InstrumentId(Symbol("BTC/USDT"), Venue("BINANCE")), client_order_id=ClientOrderId("O-2020872378423"), reason="INSUFFICIENT_MARGIN", ts_event=0, event_id=uuid, ts_init=0, ) # Act, Assert assert OrderRejected.from_dict(OrderRejected.to_dict(event)) == event assert ( str(event) == "OrderRejected(account_id=SIM-000, instrument_id=BTC/USDT.BINANCE, client_order_id=O-2020872378423, reason='INSUFFICIENT_MARGIN', ts_event=0)" # noqa ) assert ( repr(event) == f"OrderRejected(trader_id=TRADER-001, strategy_id=SCALPER-001, account_id=SIM-000, instrument_id=BTC/USDT.BINANCE, client_order_id=O-2020872378423, reason='INSUFFICIENT_MARGIN', event_id={uuid}, ts_event=0, ts_init=0)" # noqa )
def test_venue_data_response_message_str_and_repr(self): # Arrange, Act correlation_id = self.uuid_factory.generate() response_id = self.uuid_factory.generate() instrument_id = InstrumentId(Symbol("AUD/USD"), IDEALPRO) response = DataResponse( client_id=ClientId("IB"), venue=Venue("IDEALPRO"), data_type=DataType(QuoteTick, metadata={"instrument_id": instrument_id}), data=[], correlation_id=correlation_id, response_id=response_id, ts_init=self.clock.timestamp_ns(), ) # Assert assert ( str(response) == "DataResponse(QuoteTick{'instrument_id': InstrumentId('AUD/USD.IDEALPRO')})" ) assert repr(response) == ( f"DataResponse(" f"client_id=IB, " f"venue=IDEALPRO, " f"data_type=QuoteTick{{'instrument_id': InstrumentId('AUD/USD.IDEALPRO')}}, " f"correlation_id={correlation_id}, " f"id={response_id})")
def test_send_data_request_when_data_type_unrecognized_logs_and_does_nothing(self): # Arrange self.data_engine.register_client(self.binance_client) handler = [] request = DataRequest( client_id=ClientId(BINANCE.value), data_type=DataType( str, metadata={ # str data type is invalid "InstrumentId": InstrumentId(Symbol("SOMETHING"), Venue("RANDOM")), "FromDateTime": None, "ToDateTime": None, "Limit": 1000, }, ), callback=handler.append, request_id=self.uuid_factory.generate(), timestamp_ns=self.clock.timestamp_ns(), ) # Act self.data_engine.send(request) # Assert self.assertEqual(1, self.data_engine.request_count)
def test_order_initialized_event_to_from_dict_and_str_repr(self): # Arrange uuid = UUID4() event = OrderInitialized( trader_id=TraderId("TRADER-001"), strategy_id=StrategyId("SCALPER-001"), instrument_id=InstrumentId(Symbol("BTC/USDT"), Venue("BINANCE")), client_order_id=ClientOrderId("O-2020872378423"), order_side=OrderSide.BUY, order_type=OrderType.LIMIT, quantity=Quantity.from_str("0.561000"), time_in_force=TimeInForce.DAY, reduce_only=True, options={"price": "15200.10"}, order_list_id=OrderListId("1"), parent_order_id=None, child_order_ids=[ClientOrderId("O-2020872378424")], contingency=ContingencyType.OTO, contingency_ids=[ClientOrderId("O-2020872378424")], tags="ENTRY", event_id=uuid, ts_init=0, ) # Act, Assert assert OrderInitialized.from_dict( OrderInitialized.to_dict(event)) == event assert ( str(event) == f"OrderInitialized(instrument_id=BTC/USDT.BINANCE, client_order_id=O-2020872378423, side=BUY, type=LIMIT, quantity=0.561000, time_in_force=DAY, reduce_only=True, options={{'price': '15200.10'}}, order_list_id=1, parent_order_id=None, child_order_ids=['O-2020872378424'], contingency=OTO, contingency_ids=['O-2020872378424'], tags=ENTRY)" # noqa ) assert ( repr(event) == f"OrderInitialized(trader_id=TRADER-001, strategy_id=SCALPER-001, instrument_id=BTC/USDT.BINANCE, client_order_id=O-2020872378423, side=BUY, type=LIMIT, quantity=0.561000, time_in_force=DAY, reduce_only=True, options={{'price': '15200.10'}}, order_list_id=1, parent_order_id=None, child_order_ids=['O-2020872378424'], contingency=OTO, contingency_ids=['O-2020872378424'], tags=ENTRY, event_id={uuid}, ts_init=0)" # noqa )