def __init__(self, logger, handle_market_orders=False): OrderLevelBookListener.__init__(self, logger) OrderEventListener.__init__(self, logger) self._market_to_order_book = {} self._market_to_event_to_priority = NDeepDict(depth=2) self._market_to_event_to_priority_before = NDeepDict(depth=2) self._handle_market_orders = handle_market_orders
def __init__(self, logger): OrderLevelBookListener.__init__(self, logger) self._market_to_subchain_id_to_time = NDeepDict( depth=2, default_factory=list ) # this a list of tuples (start_time, end_time) self._market_to_side_to_prev_tob_subchain_ids = NDeepDict( depth=2, default_factory=set)
def __init__(self, logger): OrderLevelBookListener.__init__(self, logger) OrderEventListener.__init__(self, logger) self._market_to_side_prev_price = NDeepDict(depth=2) self._market_side_price_time = NDeepDict(depth=3) # market to side to price to last time it was top of book self._market_side_best_price = NDeepDict(depth=2) self._event_id_to_last_time_crossed = {} self._event_id_to_last_time_tob = {}
def test_1_deep_with_default_list_access(): d = NDeepDict(1, int) assert len(d) == 0 # setting something should work d[['a']] = 1 assert len(d) == 1 # getting 'a' should work assert d[['a']] == 1 assert d.get(['a']) == 1 # getting 'b' should return the default of 0 assert d[['b']] == 0 assert d.get(['b']) == 0 # length should now be two because b was created on the get assert len(d) == 2 assert 'b' in d assert 'a' in d # modifying an unknown int should work too assert not 'c' in d d[['c']] += 1 assert d[['c']] == 1
def test_none_default_1_deep(): d = NDeepDict(1) d[['a']] = 16 assert d.get(['a']) == 16 assert d.get(['c']) is None with pytest.raises(KeyError): x = d[['c']]
def test_one_level_contains_none_default(): d = NDeepDict(1) d[['a']] = 1 assert ['a'] in d assert 'a' in d assert ['b'] not in d assert 'b' not in d
def test_4_deep_create_at_once_standard_access(): d = NDeepDict(4) assert len(d) == 0, "Starts completely empty" d["level1"]["level2"]["level3"]["level4"] = 5 assert "level1" in d assert "level2" in d["level1"] assert "level3" in d["level1"]["level2"] assert "level4" in d["level1"]["level2"]["level3"] assert d["level1"]["level2"]["level3"]["level4"] == 5
def test_4_deep_create_at_once_list_access(): d = NDeepDict(4) assert len(d) == 0, "Starts completely empty" d[["level1", "level2", "level3", "level4"]] = 5 assert len(d) == 1 assert "level1" in d assert "level2" in d[["level1"]] assert "level3" in d[["level1", "level2"]] assert "level4" in d[["level1", "level2", "level3"]] assert len(d) == 1 assert d[["level1", "level2", "level3", "level4"]] == 5
def test_1_deep_del_standard_access(): d = NDeepDict(4) d[['a1','a1b1','a1b1c1']] = "test value" d[['a2','a2b1','a2b1c1']] = "test value 2" d[['a1','a1b2','a1b2c1']] = "test value 3" d[['a1','a1b1','a1b1c2']] = "test value 4" d[['a1','a1b1','a1b1c3']] = "test value 5" assert 'a1b1c2' in d['a1']['a1b1'] del d[['a1', 'a1b1', 'a1b1c2']] assert 'a1b1c2' not in d['a1']['a1b1'], "was deleted so should be gone" assert 'a1b1c1' in d['a1']['a1b1'], "was not deleted so should be there" assert 'a1b1c3' in d['a1']['a1b1'], "was not deleted so should be there" assert 'a2b1c1' in d['a2']['a2b1'], "was not deleted so should be there" assert 'a1b2c1' in d['a1']['a1b2'], "was not deleted so should be there"
def test_2_deep_with_default_list_access(): d = NDeepDict(2, int) assert len(d) == 0, "Nothing is in new dict so length is 0" assert len(d[['a']]) == 0, "Nothing is in the second level dict so should be 0" assert len(d) == 1, "Looking for length of 'a' above should have added it to the first level dict, so now first level length is 0" assert d['b'] == {} assert 'b' in d assert len(d[['b']]) == 0 d[['b','level2-a']], "Getting a key for first time in second level dict, so should create an item in b" assert len(d[['b']]) == 1 assert d[['b','level2-a']] == 0 d[['b', 'level2-b']] += 50 assert d[['b','level2-b']] == 50 assert d.get(['b',"level2-b"]) == 50
def test_1_deep_with_no_default_list_access(): d = NDeepDict(1, None) assert len(d) == 0 # setting something should work d[['a']] = 1 assert len(d) == 1 # getting 'a' should work assert d[['a']] == 1 assert d.get(['a']) == 1 # getting 'b' should return the default of None with pytest.raises(KeyError): d[['b']] d.get(['b']) # length should still be 1 because getting 'b' shouldn't have added anything assert len(d) == 1 assert 'b' not in d assert 'a' in d
def __init__(self, logger): OrderLevelBookListener.__init__(self, logger) self._market_to_subchain_id_to_time = NDeepDict(depth=2, default_factory=list) self._market_to_side_to_prev_tob_subchain_id = NDeepDict(depth=2)
def test_first_none_default_2_deep(): d = NDeepDict(2) d[['a', 'b']] = 16 assert d.get(['d', 'e']) is None
def __init__(self, logger): OrderLevelBookListener.__init__(self, logger) self._market_chain_id_ticks = NDeepDict(2) self._market_side_tob = {} self._market_side_tob[BID_SIDE] = defaultdict() self._market_side_tob[ASK_SIDE] = defaultdict()
def __init__(self, logger): OrderEventListener.__init__(self, logger) # storing this market -> user -> count type -> count self._event_counts = NDeepDict(3, int)
def __init__(self, logger): OrderLevelBookListener.__init__(self, logger) OrderEventListener.__init__(self, logger) self._market_event_id_aggressive_act = NDeepDict(depth=2) self._market_to_orderbook = defaultdict(lambda: None) self._market_to_agg_acts_to_close = defaultdict(set)