MCPcopy Create free account
hub / github.com/ccxt/ccxt / ArrayCache

Class ArrayCache

python/ccxt/async_support/base/ws/cache.py:62–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60
61
62class ArrayCache(BaseCache):
63 def __init__(self, max_size=None):
64 super(ArrayCache, self).__init__(max_size)
65 self.hashmap = {}
66 self._nested_new_updates_by_symbol = False
67 self._new_updates_by_symbol = {}
68 self._clear_updates_by_symbol = {}
69 self._all_new_updates = 0
70 self._clear_all_updates = False
71
72 def getLimit(self, symbol, limit):
73 if symbol is None:
74 new_updates_value = self._all_new_updates
75 self._clear_all_updates = True
76 else:
77 new_updates_value = self._new_updates_by_symbol.get(symbol)
78 if new_updates_value is not None and self._nested_new_updates_by_symbol:
79 new_updates_value = len(new_updates_value)
80 self._clear_updates_by_symbol[symbol] = True
81
82 if new_updates_value is None:
83 return limit
84 elif limit is not None:
85 return min(new_updates_value, limit)
86 else:
87 return new_updates_value
88
89 def append(self, item):
90 self._deque.append(item)
91 if self._clear_all_updates:
92 self._clear_all_updates = False
93 self._clear_updates_by_symbol.clear()
94 self._all_new_updates = 0
95 self._new_updates_by_symbol.clear()
96 if self._clear_updates_by_symbol.get(item['symbol']):
97 self._clear_updates_by_symbol[item['symbol']] = False
98 self._new_updates_by_symbol[item['symbol']] = 0
99 self._new_updates_by_symbol[item['symbol']] = self._new_updates_by_symbol.get(item['symbol'], 0) + 1
100 self._all_new_updates = (self._all_new_updates or 0) + 1
101
102
103class ArrayCacheByTimestamp(BaseCache):

Callers 15

test_safe_methodsFunction · 0.90
handle_tradesMethod · 0.90
handle_tradeMethod · 0.90
handle_tradesMethod · 0.90
handle_liquidationMethod · 0.90
handle_tradesMethod · 0.90
handle_tradesMethod · 0.90
handle_liquidationMethod · 0.90
handle_my_liquidationMethod · 0.90
handle_tradeMethod · 0.90
handle_tradeMethod · 0.90
handle_uta_tradeMethod · 0.90

Calls

no outgoing calls

Tested by 2

test_safe_methodsFunction · 0.72
test_ws_cacheFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…