23
23
24
24
from nautilus_trader .adapters .betfair .constants import BETFAIR_VENUE
25
25
from nautilus_trader .adapters .betfair .data import BetfairDataClient
26
+ from nautilus_trader .adapters .betfair .data_types import BetfairSequenceCompleted
26
27
from nautilus_trader .adapters .betfair .data_types import BetfairStartingPrice
27
28
from nautilus_trader .adapters .betfair .data_types import BetfairTicker
28
29
from nautilus_trader .adapters .betfair .data_types import BSPOrderBookDelta
@@ -176,7 +177,12 @@ async def test_market_sub_image_market_def(data_client, mock_data_engine_process
176
177
# Assert - expected messages
177
178
mock_calls = mock_data_engine_process .call_args_list
178
179
result = [type (call .args [0 ]).__name__ for call in mock_data_engine_process .call_args_list ]
179
- expected = ["BettingInstrument" ] * 7 + ["InstrumentStatus" ] * 7 + ["OrderBookDeltas" ] * 7
180
+ expected = (
181
+ ["BettingInstrument" ] * 7
182
+ + ["InstrumentStatus" ] * 7
183
+ + ["OrderBookDeltas" ] * 7
184
+ + ["BetfairSequenceCompleted" ]
185
+ )
180
186
assert result == expected
181
187
182
188
# Assert - Check orderbook prices
@@ -219,21 +225,27 @@ def test_market_update(data_client, mock_data_engine_process):
219
225
def test_market_update_md (data_client , mock_data_engine_process ):
220
226
data_client .on_market_update (BetfairStreaming .mcm_UPDATE_md ())
221
227
result = [type (call .args [0 ]).__name__ for call in mock_data_engine_process .call_args_list ]
222
- expected = ["BettingInstrument" ] * 2 + ["InstrumentStatus" ] * 2
228
+ expected = ["BettingInstrument" ] * 2 + ["InstrumentStatus" ] * 2 + [ "BetfairSequenceCompleted" ]
223
229
assert result == expected
224
230
225
231
226
232
def test_market_update_live_image (data_client , mock_data_engine_process ):
227
233
data_client .on_market_update (BetfairStreaming .mcm_live_IMAGE ())
228
234
result = [type (call .args [0 ]).__name__ for call in mock_data_engine_process .call_args_list ]
229
- expected = ["OrderBookDeltas" ] + ["TradeTick" ] * 13 + ["OrderBookDeltas" ] + ["TradeTick" ] * 17
235
+ expected = (
236
+ ["OrderBookDeltas" ]
237
+ + ["TradeTick" ] * 13
238
+ + ["OrderBookDeltas" ]
239
+ + ["TradeTick" ] * 17
240
+ + ["BetfairSequenceCompleted" ]
241
+ )
230
242
assert result == expected
231
243
232
244
233
245
def test_market_update_live_update (data_client , mock_data_engine_process ):
234
246
data_client .on_market_update (BetfairStreaming .mcm_live_UPDATE ())
235
247
result = [type (call .args [0 ]).__name__ for call in mock_data_engine_process .call_args_list ]
236
- expected = ["TradeTick" , "OrderBookDeltas" ]
248
+ expected = ["TradeTick" , "OrderBookDeltas" , "BetfairSequenceCompleted" ]
237
249
assert result == expected
238
250
239
251
@@ -259,6 +271,7 @@ def test_market_bsp(data_client, mock_data_engine_process):
259
271
mock_call_args = [call .args [0 ] for call in mock_data_engine_process .call_args_list ]
260
272
result = Counter ([type (args ).__name__ for args in mock_call_args ])
261
273
expected = {
274
+ "BetfairSequenceCompleted" : 2 ,
262
275
"BettingInstrument" : 9 ,
263
276
"TradeTick" : 95 ,
264
277
"OrderBookDeltas" : 11 ,
@@ -300,6 +313,8 @@ def test_orderbook_updates(data_client, parser):
300
313
for raw_update in BetfairStreaming .market_updates ():
301
314
line = stream_decode (raw_update )
302
315
for update in parser .parse (mcm = line ):
316
+ if isinstance (update , BetfairSequenceCompleted ):
317
+ continue
303
318
if len (order_books ) > 1 and update .instrument_id != list (order_books )[1 ]:
304
319
continue
305
320
if isinstance (update , OrderBookDeltas ) and update .is_snapshot :
@@ -334,12 +349,13 @@ def test_orderbook_updates(data_client, parser):
334
349
def test_instrument_opening_events (data_client , parser ):
335
350
updates = BetfairDataProvider .market_updates ()
336
351
messages = parser .parse (updates [0 ])
337
- assert len (messages ) == 4
352
+ assert len (messages ) == 5
338
353
assert isinstance (messages [0 ], BettingInstrument )
339
354
assert isinstance (messages [2 ], InstrumentStatus )
340
355
assert messages [2 ].action == MarketStatusAction .PRE_OPEN
341
356
assert isinstance (messages [3 ], InstrumentStatus )
342
357
assert messages [3 ].action == MarketStatusAction .PRE_OPEN
358
+ assert isinstance (messages [4 ], BetfairSequenceCompleted )
343
359
344
360
345
361
def test_instrument_in_play_events (data_client , parser ):
@@ -389,8 +405,8 @@ def test_instrument_update(data_client, cache, parser):
389
405
def test_instrument_closing_events (data_client , parser ):
390
406
updates = BetfairDataProvider .market_updates ()
391
407
messages = parser .parse (updates [- 1 ])
392
- assert len (messages ) == 6
393
- ins1 , ins2 , status1 , status2 , close1 , close2 = messages
408
+ assert len (messages ) == 7
409
+ ins1 , ins2 , status1 , status2 , close1 , close2 , completed = messages
394
410
395
411
# Instrument1
396
412
assert isinstance (ins1 , BettingInstrument )
@@ -408,6 +424,8 @@ def test_instrument_closing_events(data_client, parser):
408
424
assert close2 .close_price == 0.0
409
425
assert close2 .close_type == InstrumentCloseType .CONTRACT_EXPIRED
410
426
427
+ assert isinstance (completed , BetfairSequenceCompleted )
428
+
411
429
412
430
def test_betfair_ticker (data_client , mock_data_engine_process ) -> None :
413
431
# Arrange
@@ -472,7 +490,7 @@ def test_betfair_orderbook(data_client, parser) -> None:
472
490
# Act, Assert
473
491
for update in BetfairDataProvider .market_updates ():
474
492
for message in parser .parse (update ):
475
- if isinstance (message , BettingInstrument | CustomData ):
493
+ if isinstance (message , BetfairSequenceCompleted | BettingInstrument | CustomData ):
476
494
continue
477
495
if message .instrument_id not in books :
478
496
books [message .instrument_id ] = create_betfair_order_book (
0 commit comments