Skip to content

Commit

Permalink
feat: Remove commented section
Browse files Browse the repository at this point in the history
  • Loading branch information
TomMcL committed Sep 26, 2023
1 parent a6eee1f commit d54af86
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 25 deletions.
22 changes: 11 additions & 11 deletions vega_sim/api/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class MissingMarketError(Exception):
PriceLevel = namedtuple("PriceLevel", ["price", "number_of_orders", "volume"])


@dataclass
@dataclass(frozen=True)
class AccountData:
owner: str
balance: float
Expand All @@ -53,14 +53,14 @@ def account_id(self):
return f"{self.owner}-{self.type}-{self.market_id}-{self.asset}"


@dataclass
@dataclass(frozen=True)
class IcebergOrder:
peak_size: float
minimum_visible_size: float
reserved_remaining: float


@dataclass
@dataclass(frozen=True)
class Order:
price: float
size: float
Expand Down Expand Up @@ -127,20 +127,20 @@ class Order:
)


@dataclass
@dataclass(frozen=True)
class LiquidationPrice:
open_volume_only: float
including_buy_orders: float
including_sell_orders: float


@dataclass
@dataclass(frozen=True)
class MarginEstimate:
best_case: MarginLevels
worst_case: MarginLevels


@dataclass
@dataclass(frozen=True)
class LiquidationEstimate:
best_case: LiquidationPrice
worst_case: LiquidationPrice
Expand All @@ -153,7 +153,7 @@ class DecimalSpec:
asset_decimals: Optional[int] = None


@dataclass
@dataclass(frozen=True)
class LedgerEntry:
from_account: vega_protos.vega.AccountDetails
to_account: vega_protos.vega.AccountDetails
Expand All @@ -162,7 +162,7 @@ class LedgerEntry:
timestamp: int


@dataclass
@dataclass(frozen=True)
class AggregatedLedgerEntry:
timestamp: int
quantity: float
Expand All @@ -176,19 +176,19 @@ class AggregatedLedgerEntry:
to_account_market_id: str


@dataclass
@dataclass(frozen=True)
class MarketDepth:
buys: List[PriceLevel]
sells: List[PriceLevel]


@dataclass
@dataclass(frozen=True)
class OrdersBySide:
bids: List[Order]
asks: List[Order]


@dataclass
@dataclass(frozen=True)
class Fee:
maker_fee: float
infrastructure_fee: float
Expand Down
45 changes: 32 additions & 13 deletions vega_sim/local_data_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,32 +599,37 @@ def get_trades_from_stream(
def get_accounts_from_stream(
self,
market_id: Optional[str] = None,
asset_id: Optional[str] = None,
party_id: Optional[str] = None,
asset_id: Optional[str] = None,
) -> List[data.AccountData]:
"""Loads accounts for either a given party, market or both from stream.
Must pass one or the other
Args:
market_id:
optional str, Restrict to trades on a specific market
optional str, Restrict to accounts on a specific market
party_id:
optional str, Select only trades with a given id
optional str, Select only accounts with a given party id
asset_id:
optional str, Restrict to only accounts for a given asset
Returns:
List[AccountData], list of formatted trade objects which match the required
restrictions.
"""
if market_id is None and party_id is None:
raise Exception("At least one of market_id and party_id must be specified")

with self.account_lock:
to_check_keys = set()
if market_id is not None:
to_check_keys.update(
self._account_keys_for_market.get(market_id, set())
)
if party_id is not None:
to_check_keys.update(self._account_keys_for_party.get(party_id, set()))
if market_id is None and party_id is None:
to_check_keys = self._accounts_from_feed.keys()
else:
to_check_keys = set()
if market_id is not None:
to_check_keys.update(
self._account_keys_for_market.get(market_id, set())
)
if party_id is not None:
to_check_keys.update(
self._account_keys_for_party.get(party_id, set())
)
results = []
for key in to_check_keys:
acct = self._accounts_from_feed[key]
Expand All @@ -643,3 +648,17 @@ def get_accounts_from_stream(
results.append(acct)

return results

def get_all_accounts_from_stream(
self,
) -> List[data.AccountData]:
"""Loads all accounts stored.
Returns:
List[AccountData], list of formatted account objects
"""

with self.account_lock:
accts = list(self._accounts_from_feed.values())

return accts
2 changes: 1 addition & 1 deletion vega_sim/scenario/common/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -2865,7 +2865,7 @@ def step(self, vega_state: VegaState):
self.seen_trades.add(trade.id)
market_trades.setdefault(market.id, []).append(trade)

accounts = self.vega.list_accounts()
accounts = self.vega.get_accounts_from_stream()
self.states.append(
MarketHistoryData(
at_time=start_time,
Expand Down

0 comments on commit d54af86

Please sign in to comment.