Skip to content

Commit

Permalink
consistent defaults for cached subscriber
Browse files Browse the repository at this point in the history
  • Loading branch information
soundsonacid committed Jul 22, 2024
1 parent 8dc64a5 commit c3ed1f4
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/driftpy/accounts/cache/drift_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ def __init__(
):
self.program = program
self.commitment = commitment
self.cache = {"spot_markets": {}, "perp_markets": {}, "oracle_price_data": {}}
self.cache = {
"spot_markets": [],
"perp_markets": [],
"oracle_price_data": {},
"state": None,
}
self.perp_market_indexes = perp_market_indexes
self.spot_market_indexes = spot_market_indexes
self.oracle_infos = oracle_infos
Expand All @@ -51,9 +56,10 @@ async def update_cache(self):
is_empty = all(not d for d in self.cache.values())
if is_empty:
self.cache = {
"spot_markets": {},
"perp_markets": {},
"spot_markets": [],
"perp_markets": [],
"oracle_price_data": {},
"state": None,
}

state_and_slot = await get_state_account_and_slot(self.program)
Expand Down Expand Up @@ -232,7 +238,12 @@ def get_oracle_price_data_and_slot_for_spot_market(
return None

async def unsubscribe(self):
self.cache = None
self.cache = {
"spot_markets": [],
"perp_markets": [],
"oracle_price_data": {},
"state": None,
}

def get_market_accounts_and_slots(self) -> list[DataAndSlot[PerpMarketAccount]]:
return self.cache["perp_markets"]
Expand Down

0 comments on commit c3ed1f4

Please sign in to comment.