@@ -98,8 +98,8 @@ def test_bento_given_initial_nbytes_returns_expected_metadata(self) -> None:
9898 # Assert
9999 assert data .dtype == np .dtype (
100100 [
101- ("nwords " , "u1" ),
102- ("type " , "u1" ),
101+ ("length " , "u1" ),
102+ ("rtype " , "u1" ),
103103 ("publisher_id" , "<u2" ),
104104 ("product_id" , "<u4" ),
105105 ("ts_event" , "<u8" ),
@@ -260,7 +260,7 @@ def test_to_df_with_mbo_data_returns_expected_record(self) -> None:
260260 assert df .iloc [0 ].action == "C"
261261 assert df .iloc [0 ].side == "A"
262262 assert df .iloc [0 ].price == 3722750000000
263- assert df .iloc [0 ].size == 11
263+ assert df .iloc [0 ].size == 12
264264 assert df .iloc [0 ].sequence == 1170352
265265
266266 def test_to_df_with_stub_ohlcv_data_returns_expected_record (self ) -> None :
@@ -380,7 +380,7 @@ def test_from_file_given_various_paths_returns_expected_metadata(
380380 assert data .schema == expected_schema
381381 assert data .compression == expected_compression
382382
383- def test_to_csv_writes_expected_file_to_disk (self ) -> None :
383+ def test_mbo_to_csv_writes_expected_file_to_disk (self ) -> None :
384384 # Arrange
385385 test_data_path = get_test_data_path (schema = Schema .MBO )
386386 data = FileBento (path = test_data_path )
@@ -394,10 +394,11 @@ def test_to_csv_writes_expected_file_to_disk(self) -> None:
394394 written = open (path , mode = "rb" ).read ()
395395 assert os .path .isfile (path )
396396 expected = (
397- b"ts_recv,ts_event,ts_in_delta,publisher_id,product_id,order_id,action,side,flags,pr" # noqa
398- b"ice,size,sequence\n 1609160400000704060,1609160400000429831,22993,1,5482,6" # noqa
399- b"47784973705,C,A,128,3722750000000,1,1170352\n 1609160400000711344,160916" # noqa
400- b"0400000431665,19621,1,5482,647784973631,C,A,128,3723000000000,1,1170353\n " # noqa
397+ b"ts_recv,ts_event,ts_in_delta,publisher_id,channel_id,product_id,order_id,act" # noqa
398+ b"ion,side,flags,price,size,sequence\n 1609160400000704060,16091604000004298" # noqa
399+ b"31,22993,1,0,5482,647784973705,C,A,128,3722750000000,1,1170352\n 160916040" # noqa
400+ b"0000711344,1609160400000431665,19621,1,0,5482,647784973631,C,A,128,372300000" # noqa
401+ b"0000,1,1170353\n "
401402 )
402403 if sys .platform == "win32" :
403404 expected = expected .replace (b"\n " , b"\r \n " )
@@ -406,7 +407,35 @@ def test_to_csv_writes_expected_file_to_disk(self) -> None:
406407 # Cleanup
407408 os .remove (path )
408409
409- def test_to_json_writes_expected_file_to_disk (self ) -> None :
410+ def test_mbp_1_to_csv_writes_expected_file_to_disk (self ) -> None :
411+ # Arrange
412+ test_data_path = get_test_data_path (schema = Schema .MBP_1 )
413+ data = FileBento (path = test_data_path )
414+
415+ path = "test.my_mbo.csv"
416+
417+ # Act
418+ data .to_csv (path )
419+
420+ # Assert
421+ written = open (path , mode = "rb" ).read ()
422+ assert os .path .isfile (path )
423+ expected = (
424+ b"ts_recv,ts_event,ts_in_delta,publisher_id,channel_id,product_id,action,side," # noqa
425+ b"depth,flags,price,size,sequence,bid_px_00,ask_px_00,bid_sz_00,ask_sz_00,bid_" # noqa
426+ b"oq_00,ask_oq_00\n 1609160400006136329,1609160400006001487,17214,1,,5482,A," # noqa
427+ b"A,0,128,3720500000000,1,1170362,3720250000000,3720500000000,24,11,15,9\n 1" # noqa
428+ b"609160400006246513,1609160400006146661,18858,1,,5482,A,A,0,128,3720500000000" # noqa
429+ b",1,1170364,3720250000000,3720500000000,24,12,15,10\n "
430+ )
431+ if sys .platform == "win32" :
432+ expected = expected .replace (b"\n " , b"\r \n " )
433+ assert written == expected
434+
435+ # Cleanup
436+ os .remove (path )
437+
438+ def test_mbo_to_json_writes_expected_file_to_disk (self ) -> None :
410439 # Arrange
411440 test_data_path = get_test_data_path (schema = Schema .MBO )
412441 data = FileBento (path = test_data_path )
@@ -420,12 +449,40 @@ def test_to_json_writes_expected_file_to_disk(self) -> None:
420449 written = open (path , mode = "rb" ).read ()
421450 assert os .path .isfile (path )
422451 assert written == (
423- b'{"ts_event":1609160400000429831,"ts_in_delta":22993,"publisher_id":1,"product_id":' # noqa
424- b'5482,"order_id":647784973705,"action":"C","side":"A","flags":128,"price":372' # noqa
425- b'2750000000,"size":1,"sequence":1170352}\n {"ts_event":160916040000043166' # noqa
426- b'5,"ts_in_delta":19621,"publisher_id":1,"product_id":5482,"order_id":647784973631,"' # noqa
427- b'action":"C","side":"A","flags":128,"price":3723000000000,"size":1,"sequenc' # noqa
428- b'e":1170353}\n '
452+ b'{"ts_event":1609160400000429831,"ts_in_delta":22993,"publisher_id":1,"channe' # noqa
453+ b'l_id":0,"product_id":5482,"order_id":647784973705,"action":"C","side":"A","f' # noqa
454+ b'lags":128,"price":3722750000000,"size":1,"sequence":1170352}\n {"ts_event"' # noqa
455+ b':1609160400000431665,"ts_in_delta":19621,"publisher_id":1,"channel_id":0,"pr' # noqa
456+ b'oduct_id":5482,"order_id":647784973631,"action":"C","side":"A","flags":128,"' # noqa
457+ b'price":3723000000000,"size":1,"sequence":1170353}\n '
458+ )
459+
460+ # Cleanup
461+ os .remove (path )
462+
463+ def test_mbp_1_to_json_writes_expected_file_to_disk (self ) -> None :
464+ # Arrange
465+ test_data_path = get_test_data_path (schema = Schema .MBP_1 )
466+ data = FileBento (path = test_data_path )
467+
468+ path = "test.my_mbo.json"
469+
470+ # Act
471+ data .to_json (path )
472+
473+ # Assert
474+ written = open (path , mode = "rb" ).read ()
475+ assert os .path .isfile (path )
476+ assert written == (
477+ b'{"ts_event":1609160400006001487,"ts_in_delta":17214,"publisher_id":1,"channe' # noqa
478+ b'l_id":null,"product_id":5482,"action":"A","side":"A","depth":0,"flags":128,"' # noqa
479+ b'price":3720500000000,"size":1,"sequence":1170362,"bid_px_00":3720250000000,"' # noqa
480+ b'ask_px_00":3720500000000,"bid_sz_00":24,"ask_sz_00":11,"bid_oq_00":15,"ask_o' # noqa
481+ b'q_00":9}\n {"ts_event":1609160400006146661,"ts_in_delta":18858,"publisher_' # noqa
482+ b'id":1,"channel_id":null,"product_id":5482,"action":"A","side":"A","depth":0,' # noqa
483+ b'"flags":128,"price":3720500000000,"size":1,"sequence":1170364,"bid_px_00":37' # noqa
484+ b'20250000000,"ask_px_00":3720500000000,"bid_sz_00":24,"ask_sz_00":12,"bid_oq_' # noqa
485+ b'00":15,"ask_oq_00":10}\n '
429486 )
430487
431488 # Cleanup
0 commit comments