Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

Commit

Permalink
Added simple events and fills properties to event queues.
Browse files Browse the repository at this point in the history
  • Loading branch information
Geoff Taylor committed Mar 8, 2022
1 parent 6f7d402 commit a5ce59f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
22 changes: 21 additions & 1 deletion mango/perpeventqueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,26 @@ def accounts_to_crank(self) -> typing.Sequence[PublicKey]:

return distinct

@property
def events(self) -> typing.Sequence[PerpEvent]:
return [*self.processed_events, *self.unprocessed_events]

@property
def fills(self) -> typing.Sequence[PerpFillEvent]:
fills: typing.List[PerpFillEvent] = []
for event in self.events:
if isinstance(event, PerpFillEvent):
fills += [event]
return fills

@property
def liquidations(self) -> typing.Sequence[PerpLiquidateEvent]:
liquidations: typing.List[PerpLiquidateEvent] = []
for event in self.events:
if isinstance(event, PerpLiquidateEvent):
liquidations += [event]
return liquidations

def subscribe(
self,
context: Context,
Expand All @@ -380,7 +400,7 @@ def events_for_account(
self, mango_account_address: PublicKey
) -> typing.Sequence[PerpEvent]:
events: typing.List[PerpEvent] = []
for event in [*self.processed_events, *self.unprocessed_events]:
for event in self.events:
if mango_account_address in event.accounts_to_crank:
events += [event]
return events
Expand Down
12 changes: 12 additions & 0 deletions mango/serumeventqueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,18 @@ def accounts_to_crank(self) -> typing.Sequence[PublicKey]:

return distinct

@property
def events(self) -> typing.Sequence[SerumEvent]:
return [*self.processed_events, *self.unprocessed_events]

@property
def fills(self) -> typing.Sequence[SerumEvent]:
fills: typing.List[SerumEvent] = []
for event in self.events:
if event.event_flags.fill:
fills += [event]
return fills

@property
def capacity(self) -> int:
return len(self.unprocessed_events) + len(self.processed_events)
Expand Down

0 comments on commit a5ce59f

Please sign in to comment.