Fixed InventoryAccountWatcher to accept a perp market.

This commit is contained in:
Geoff Taylor 2022-03-23 11:02:18 +00:00
parent 8bbe48abaf
commit f70423f2fe
1 changed files with 18 additions and 5 deletions

View File

@ -23,8 +23,11 @@ from .account import Account
from .cache import Cache from .cache import Cache
from .group import Group from .group import Group
from .instrumentvalue import InstrumentValue from .instrumentvalue import InstrumentValue
from .markets import InventorySource, Market from .loadedmarket import LoadedMarket
from .markets import InventorySource
from .openorders import OpenOrders from .openorders import OpenOrders
from .perpmarket import PerpMarket
from .spotmarket import SpotMarket
from .watcher import Watcher from .watcher import Watcher
@ -65,7 +68,7 @@ class Inventory:
class InventoryAccountWatcher: class InventoryAccountWatcher:
def __init__( def __init__(
self, self,
market: Market, market: LoadedMarket,
account_watcher: Watcher[Account], account_watcher: Watcher[Account],
group_watcher: Watcher[Group], group_watcher: Watcher[Group],
all_open_orders_watchers: typing.Sequence[Watcher[OpenOrders]], all_open_orders_watchers: typing.Sequence[Watcher[OpenOrders]],
@ -78,9 +81,19 @@ class InventoryAccountWatcher:
] = all_open_orders_watchers ] = all_open_orders_watchers
self.cache_watcher: Watcher[Cache] = cache_watcher self.cache_watcher: Watcher[Cache] = cache_watcher
account: Account = account_watcher.latest account: Account = account_watcher.latest
self.spot_account_index: int = group_watcher.latest.slot_by_spot_market_address( if SpotMarket.isa(market):
market.address self.spot_account_index: int = (
).index group_watcher.latest.slot_by_spot_market_address(market.address).index
)
elif PerpMarket.isa(market):
self.spot_account_index = group_watcher.latest.slot_by_spot_market_address(
market.address
).index
else:
raise Exception(
f"Cannot find slot for market {market} in group {group_watcher.latest.address}"
)
base_value = InstrumentValue.find_by_symbol( base_value = InstrumentValue.find_by_symbol(
account.net_values, market.base.symbol account.net_values, market.base.symbol
) )