Skip to content

Commit

Permalink
handle unsub for oracles
Browse files Browse the repository at this point in the history
  • Loading branch information
crispheaney committed Dec 16, 2024
1 parent 1ff07f3 commit 4fc0e35
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/driftpy/accounts/polling/drift_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def __init__(
self.program = program
self.is_subscribed = False
self.callbacks: dict[str, int] = {}
self.oracle_callbacks: dict[str, int] = {}

self.perp_market_indexes = perp_market_indexes
self.spot_market_indexes = spot_market_indexes
Expand Down Expand Up @@ -148,7 +149,7 @@ async def add_oracle(self, oracle: Pubkey, oracle_source: OracleSource):
callback_id = self.bulk_account_loader.add_account(
oracle, self._get_oracle_callback(oracle_id, oracle_source)
)
self.callbacks[oracle_id] = callback_id
self.oracle_callbacks[oracle_id] = callback_id

await self._wait_for_oracle(3, oracle_id)

Expand Down Expand Up @@ -181,7 +182,14 @@ async def unsubscribe(self):
self.bulk_account_loader.remove_account(
Pubkey.from_string(pubkey_str), callback_id
)

for oracle_id, callback_id in self.oracle_callbacks.items():
self.bulk_account_loader.remove_account(
Pubkey.from_string(oracle_id.split("-")[0]), callback_id
)

self.callbacks.clear()
self.oracle_callbacks.clear()

def get_state_account_and_slot(self) -> Optional[DataAndSlot[StateAccount]]:
return self.state
Expand Down

0 comments on commit 4fc0e35

Please sign in to comment.