Skip to content

Commit

Permalink
fix: update api method and test
Browse files Browse the repository at this point in the history
  • Loading branch information
cdummett committed Oct 19, 2023
1 parent 67c9fa6 commit 9915c7d
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 16 deletions.
36 changes: 33 additions & 3 deletions tests/vega_sim/api/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
ReferralSetStats,
PartyAmount,
ReferrerRewardsGenerated,
MakerFeesGenerated,
FeesStats,
Team,
TeamReferee,
Expand Down Expand Up @@ -1064,7 +1065,7 @@ def GetFeesStats(self, request, context):
market=request.market_id,
asset=request.asset_id,
epoch_seq=1,
total_rewards_paid=[
total_rewards_received=[
vega_protos.events.v1.events.PartyAmount(
party="referrer1", amount="1000"
)
Expand All @@ -1089,6 +1090,21 @@ def GetFeesStats(self, request, context):
party="referrer1", amount="1000"
)
],
total_maker_fees_received=[
vega_protos.events.v1.events.PartyAmount(
party="referrer1", amount="1000"
)
],
maker_fees_generated=[
vega_protos.events.v1.events.MakerFeesGenerated(
taker="taker1",
maker_fees_paid=[
vega_protos.events.v1.events.PartyAmount(
party="referrer1", amount="1000"
)
],
)
],
)
)

Expand All @@ -1106,7 +1122,7 @@ def GetFeesStats(self, request, context):
market="market_id",
asset="",
epoch_seq=1,
total_rewards_paid=[PartyAmount(party="referrer1", amount=100.0)],
total_rewards_received=[PartyAmount(party="referrer1", amount=100.0)],
referrer_rewards_generated=[
ReferrerRewardsGenerated(
referrer="referrer1",
Expand All @@ -1115,6 +1131,13 @@ def GetFeesStats(self, request, context):
],
referees_discount_applied=[PartyAmount(party="referrer1", amount=100.0)],
volume_discount_applied=[PartyAmount(party="referrer1", amount=100.0)],
total_maker_fees_received=[PartyAmount(party="referrer1", amount=100.0)],
maker_fees_generated=[
MakerFeesGenerated(
taker="taker1",
maker_fees_paid=[PartyAmount(party="referrer1", amount=100.0)],
)
],
)
assert get_fees_stats(
data_client=data_client,
Expand All @@ -1124,7 +1147,7 @@ def GetFeesStats(self, request, context):
market="",
asset="asset",
epoch_seq=1,
total_rewards_paid=[PartyAmount(party="referrer1", amount=100.0)],
total_rewards_received=[PartyAmount(party="referrer1", amount=100.0)],
referrer_rewards_generated=[
ReferrerRewardsGenerated(
referrer="referrer1",
Expand All @@ -1133,6 +1156,13 @@ def GetFeesStats(self, request, context):
],
referees_discount_applied=[PartyAmount(party="referrer1", amount=100.0)],
volume_discount_applied=[PartyAmount(party="referrer1", amount=100.0)],
total_maker_fees_received=[PartyAmount(party="referrer1", amount=100.0)],
maker_fees_generated=[
MakerFeesGenerated(
taker="taker1",
maker_fees_paid=[PartyAmount(party="referrer1", amount=100.0)],
)
],
)


Expand Down
46 changes: 39 additions & 7 deletions vega_sim/api/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,15 +310,36 @@ class ReferrerRewardsGenerated:
generated_reward: List[PartyAmount]


@dataclass(frozen=True)
class MakerFeesGenerated:
taker: float
maker_fees_paid: List[PartyAmount]


def _maker_fees_generated_from_proto(
maker_fees_generated: vega_protos.events.v1.events.MakerFeesGenerated,
decimal_spec: DecimalSpec,
):
return MakerFeesGenerated(
taker=maker_fees_generated.taker,
maker_fees_paid=[
_party_amount_from_proto(party_amount, decimal_spec)
for party_amount in maker_fees_generated.maker_fees_paid
],
)


@dataclass(frozen=True)
class FeesStats:
market: str
asset: str
epoch_seq: int
total_rewards_paid: List[PartyAmount]
total_rewards_received: List[PartyAmount]
referrer_rewards_generated: List[ReferrerRewardsGenerated]
referees_discount_applied: List[PartyAmount]
volume_discount_applied: List[PartyAmount]
total_maker_fees_received: List[PartyAmount]
maker_fees_generated: List[MakerFeesGenerated]


@dataclass(frozen=True)
Expand Down Expand Up @@ -1114,11 +1135,11 @@ def _fees_stats_from_proto(
market=fee_stats.market,
asset=fee_stats.asset,
epoch_seq=fee_stats.epoch_seq,
total_rewards_paid=[
total_rewards_received=[
_party_amount_from_proto(
party_amount=party_amount, decimal_spec=decimal_spec
)
for party_amount in fee_stats.total_rewards_paid
for party_amount in fee_stats.total_rewards_received
],
referrer_rewards_generated=[
_referrer_rewards_generated_from_proto(
Expand All @@ -1139,6 +1160,19 @@ def _fees_stats_from_proto(
)
for party_amount in fee_stats.volume_discount_applied
],
total_maker_fees_received=[
_party_amount_from_proto(
party_amount=party_amount, decimal_spec=decimal_spec
)
for party_amount in fee_stats.total_maker_fees_received
],
maker_fees_generated=[
_maker_fees_generated_from_proto(
maker_fees_generated=maker_fees_generated,
decimal_spec=decimal_spec,
)
for maker_fees_generated in fee_stats.maker_fees_generated
],
)


Expand Down Expand Up @@ -2304,17 +2338,15 @@ def get_fees_stats(
market_id: Optional[str] = None,
asset_id: Optional[str] = None,
epoch_seq: Optional[int] = None,
referrer: Optional[str] = None,
referee: Optional[str] = None,
party_id: Optional[str] = None,
asset_decimals: Optional[Dict[str, int]] = {},
) -> List[FeesStats]:
response = data_raw.get_fees_stats(
data_client=data_client,
market_id=market_id,
asset_id=asset_id,
epoch_seq=epoch_seq,
referrer=referrer,
referee=referee,
party_id=party_id,
)
return _fees_stats_from_proto(
fee_stats=response,
Expand Down
9 changes: 3 additions & 6 deletions vega_sim/api/data_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,8 +759,7 @@ def get_fees_stats(
market_id: Optional[str] = None,
asset_id: Optional[str] = None,
epoch_seq: Optional[int] = None,
referrer: Optional[str] = None,
referee: Optional[str] = None,
party_id: Optional[str] = None,
):
base_request = data_node_protos_v2.trading_data.GetFeesStatsRequest()
if market_id is not None:
Expand All @@ -769,10 +768,8 @@ def get_fees_stats(
setattr(base_request, "asset_id", asset_id)
if epoch_seq is not None:
setattr(base_request, "epoch_seq", epoch_seq)
if referrer is not None:
setattr(base_request, "referrer", referrer)
if referee is not None:
setattr(base_request, "referee", referee)
if party_id is not None:
setattr(base_request, "referrer", party_id)
return data_client.GetFeesStats(base_request).fees_stats


Expand Down
5 changes: 5 additions & 0 deletions vega_sim/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2858,12 +2858,17 @@ def get_fees_stats(
market_id: Optional[str] = None,
asset_id: Optional[str] = None,
epoch_seq: Optional[int] = None,
key_name: Optional[str] = None,
wallet_name: Optional[str] = None,
) -> List[data.FeesStats]:
return data.get_fees_stats(
data_client=self.trading_data_client_v2,
market_id=market_id,
asset_id=asset_id,
epoch_seq=epoch_seq,
party_id=self.wallet.public_key(key_name, wallet_name)
if key_name is not None
else None,
asset_decimals=self.asset_decimals,
)

Expand Down

0 comments on commit 9915c7d

Please sign in to comment.