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

Commit

Permalink
Added PERPORDERBOOKSIDE to AccountInfo converters.
Browse files Browse the repository at this point in the history
  • Loading branch information
Geoff Taylor committed Dec 22, 2021
1 parent eac3e89 commit 277e253
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bin/show-address
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ account_info: typing.Optional[mango.AccountInfo] = mango.AccountInfo.load(contex
if account_info is None:
raise Exception(f"No account found at address: {args.address}")

print(converter(account_info))
mango.output(converter(account_info))
16 changes: 15 additions & 1 deletion mango/accountinfoconverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

from decimal import Decimal

from solana.publickey import PublicKey

from .account import Account
from .accountinfo import AccountInfo
from .addressableaccount import AddressableAccount
Expand All @@ -27,10 +29,12 @@
from .layouts import layouts
from .lotsizeconverter import NullLotSizeConverter
from .openorders import OpenOrders
from .orderbookside import PerpOrderBookSide
from .perpeventqueue import PerpEventQueue
from .perpmarketdetails import PerpMarketDetails
from .serumeventqueue import SerumEventQueue
from .tokenbank import NodeBank, RootBank
from .token import Instrument, Token
from .tokenbank import NodeBank, RootBank, TokenBank


# # 🥭 build_account_info_converter function
Expand Down Expand Up @@ -69,5 +73,15 @@ def perp_market_details_loader(account_info: AccountInfo) -> PerpMarketDetails:
group: Group = Group.load(context, group_address)
return PerpMarketDetails.parse(account_info, group)
return perp_market_details_loader
elif account_type_upper == "PERPORDERBOOKSIDE":
class __FakePerpMarketDetails(PerpMarketDetails):
def __init__(self) -> None:
self.base_instrument = Instrument("UNKNOWNBASE", "Unknown Base", Decimal(0))
self.quote_token = TokenBank(Token("UNKNOWNQUOTE", "Unknown Quote",
Decimal(0), PublicKey(0)), PublicKey(0))
self.base_lot_size = Decimal(1)
self.quote_lot_size = Decimal(1)

return lambda account_info: PerpOrderBookSide.parse(account_info, __FakePerpMarketDetails())

raise Exception(f"Could not find AccountInfo converter for type {account_type}.")
7 changes: 6 additions & 1 deletion mango/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# [Email](mailto:[email protected])

import argparse
import collections
import enum
import json
import jsons
Expand Down Expand Up @@ -52,7 +53,11 @@ def output(obj: typing.Any) -> None:
print(json.dumps(jsons.dump(obj, strip_attr=("data", "logger", "lot_size_converter", "tokens", "tokens_by_index", "slots", "base_tokens", "base_tokens_by_index", "oracles", "oracles_by_index", "spot_markets", "spot_markets_by_index", "perp_markets", "perp_markets_by_index", "shared_quote_token", "liquidity_incentive_token"),
key_transformer=jsons.KEY_TRANSFORMER_CAMELCASE), sort_keys=True, indent=4))
else:
print(obj)
if isinstance(obj, collections.Sequence) and not isinstance(obj, str):
for item in obj:
print(item)
else:
print(obj)


# # 🥭 parse_args
Expand Down

0 comments on commit 277e253

Please sign in to comment.