Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
cdummett committed Sep 4, 2024
1 parent 682044b commit e00c604
Show file tree
Hide file tree
Showing 14 changed files with 507 additions and 199 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VEGA_SIM_VEGA_TAG=v0.78.0-preview.4
VEGA_SIM_VEGA_TAG=develop
VEGA_SIM_CONSOLE_TAG=develop
VEGA_DEFAULT_KEY_NAME='Key 1'
VEGA_SIM_NETWORKS_INTERNAL_TAG=main
Expand Down
12 changes: 10 additions & 2 deletions tests/vega_query/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@

logger = logging.getLogger(__name__)

DEFAULT_NETWORK = Network.NETWORK_TESTNET
DEFAULT_NETWORK = Network.NETWORK_LOCAL
DEFAULT_PORT_DATA_NODE = 56345


@fixture(scope="session")
def tds():
client = TradingDataService(network=DEFAULT_NETWORK)
client = TradingDataService(
network=DEFAULT_NETWORK, port_data_node=DEFAULT_PORT_DATA_NODE
)
yield client


Expand Down Expand Up @@ -106,3 +109,8 @@ def end_timestamp(tds: TradingDataService) -> int:
@fixture(scope="session")
def amms(tds: TradingDataService) -> List[protos.vega.events.v1.events.AMM]:
return tds.list_amms(max_pages=1)


@fixture(scope="session")
def epoch(tds: TradingDataService) -> protos.vega.vega.Epoch:
return tds.get_epoch()
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pytest

from vega_query.service.service_trading_data import TradingDataService
from tests.vega_query.fixtures import tds

import vega_protos.protos as protos


@pytest.mark.vega_query
def test_get_current_referral_program(tds: TradingDataService):
program = tds.get_current_referral_program()
if program is not None:
assert isinstance(program, protos.data_node.api.v2.trading_data.ReferralProgram)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pytest

from vega_query.service.service_trading_data import TradingDataService
from tests.vega_query.fixtures import tds

import vega_protos.protos as protos


@pytest.mark.vega_query
def test_get_latest_volume_discount_program(tds: TradingDataService):
program = tds.get_current_volume_discount_program()
if program is not None:
assert isinstance(
program, protos.data_node.api.v2.trading_data.VolumeDiscountProgram
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pytest

from vega_query.service.service_trading_data import TradingDataService
from tests.vega_query.fixtures import tds

import vega_protos.protos as protos


@pytest.mark.vega_query
def test_get_latest_volume_rebate_program(tds: TradingDataService):
program = tds.get_current_volume_rebate_program()
if program is not None:
assert isinstance(
program, protos.data_node.api.v2.trading_data.VolumeRebateProgram
)
26 changes: 26 additions & 0 deletions tests/vega_query/service/service_trading_data/test_get_epoch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import pytest

from vega_query.service.service_trading_data import TradingDataService
from tests.vega_query.fixtures import tds, epoch

import vega_protos.protos as protos


@pytest.mark.vega_query
def test_get_epoch(tds: TradingDataService):
epoch = tds.get_epoch()
assert isinstance(epoch, protos.vega.vega.Epoch)


@pytest.mark.vega_query
def test_get_epoch_id(tds: TradingDataService, epoch: protos.vega.vega.Epoch):
id = epoch.seq
epoch = tds.get_epoch(id=id)
assert epoch.seq == id


@pytest.mark.vega_query
def test_get_epoch_block(tds: TradingDataService, epoch: protos.vega.vega.Epoch):
block = epoch.timestamps.first_block
epoch = tds.get_epoch(block=block)
assert epoch.timestamps.first_block == block
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import pytest

from vega_query.service.service_trading_data import TradingDataService
from tests.vega_query.fixtures import tds, parties

from typing import List

import vega_protos.protos as protos


@pytest.mark.vega_query
def test_get_volume_discount_stats(tds: TradingDataService):
for stat in tds.get_volume_discount_stats():
assert isinstance(
stat, protos.data_node.api.v2.trading_data.VolumeDiscountStats
)


@pytest.mark.vega_query
def test_get_volume_discount_stats_at_epoch(tds: TradingDataService):
at_epoch = 0
for stat in tds.get_volume_discount_stats(at_epoch=0):
assert stat.at_epoch == at_epoch


@pytest.mark.vega_query
def test_get_volume_discount_stats_party_id(
tds: TradingDataService, parties: List[str]
):
party_id = parties[0]
for stat in tds.get_volume_discount_stats(party_id=party_id):
assert stat.party_id == party_id
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import pytest

from vega_query.service.service_trading_data import TradingDataService
from tests.vega_query.fixtures import tds, parties

from typing import List

import vega_protos.protos as protos


@pytest.mark.vega_query
def test_get_volume_rebate_stats(tds: TradingDataService):
for stat in tds.get_volume_rebate_stats():
assert isinstance(stat, protos.data_node.api.v2.trading_data.VolumeRebateStats)


@pytest.mark.vega_query
def test_get_volume_rebate_stats_at_epoch(tds: TradingDataService):
at_epoch = 0
for stat in tds.get_volume_rebate_stats(at_epoch=0):
assert stat.at_epoch == at_epoch


@pytest.mark.vega_query
def test_get_volume_rebate_stats_party_id(tds: TradingDataService, parties: List[str]):
party_id = parties[0]
stats = tds.get_volume_rebate_stats(party_id=party_id)
for stat in stats:
assert stat.party_id == party_id
78 changes: 60 additions & 18 deletions vega_query/service/service_trading_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,9 +763,13 @@ def list_governance_data(
# # TODO: Implement method
# pass

# def get_epoch(self, max_pages: Optional[int] = None) -> Any:
# # TODO: Implement method
# pass
@log_client_method
def get_epoch(
self, id: Optional[int] = None, block: Optional[int] = None
) -> protos.vega.vega.Epoch:
return self.__stub.GetEpoch(
trading_data.GetEpochRequest(id=id, block=block)
).epoch

# def estimate_fee(self, max_pages: Optional[int] = None) -> Any:
# # TODO: Implement method
Expand Down Expand Up @@ -972,11 +976,11 @@ def list_funding_payments(
# # TODO: Implement method
# pass

# def get_current_referral_program(
# self, max_pages: Optional[int] = None
# ) -> Any:
# # TODO: Implement method
# pass
@log_client_method
def get_current_referral_program(self, max_pages: Optional[int] = None) -> Any:
return self.__stub.GetCurrentReferralProgram(
trading_data.GetCurrentReferralProgramRequest()
).current_referral_program

# def list_referral_sets(self, max_pages: Optional[int] = None) -> Any:
# # TODO: Implement method
Expand Down Expand Up @@ -1014,17 +1018,55 @@ def list_funding_payments(
# # TODO: Implement method
# pass

# def get_current_volume_discount_program(
# self, max_pages: Optional[int] = None
# ) -> Any:
# # TODO: Implement method
# pass
@log_client_method
def get_current_volume_discount_program(
self,
) -> trading_data.VolumeDiscountProgram:
return self.__stub.GetCurrentVolumeDiscountProgram(
trading_data.GetCurrentVolumeDiscountProgramRequest()
).current_volume_discount_program

# def get_volume_discount_stats(
# self, max_pages: Optional[int] = None
# ) -> Any:
# # TODO: Implement method
# pass
@log_client_method
def get_volume_discount_stats(
self,
at_epoch: Optional[int] = None,
party_id: Optional[int] = None,
max_pages: Optional[int] = None,
) -> List[trading_data.VolumeDiscountStats]:
return unroll_v2_pagination(
base_request=trading_data.GetVolumeDiscountStatsRequest(
at_epoch=at_epoch,
party_id=party_id,
),
request_func=lambda x: self.__stub.GetVolumeDiscountStats(x).stats,
extraction_func=lambda res: [i.node for i in res.edges],
max_pages=max_pages,
)

@log_client_method
def get_current_volume_rebate_program(
self,
) -> trading_data.VolumeRebateProgram:
return self.__stub.GetCurrentVolumeRebateProgram(
trading_data.GetCurrentVolumeRebateProgramRequest()
).current_volume_rebate_program

@log_client_method
def get_volume_rebate_stats(
self,
at_epoch: Optional[int] = None,
party_id: Optional[int] = None,
max_pages: Optional[int] = None,
) -> List[trading_data.VolumeRebateStats]:
return unroll_v2_pagination(
base_request=trading_data.GetVolumeRebateStatsRequest(
at_epoch=at_epoch,
party_id=party_id,
),
request_func=lambda x: self.__stub.GetVolumeRebateStats(x).stats,
extraction_func=lambda res: [i.node for i in res.edges],
max_pages=max_pages,
)

# def get_vesting_balances_summary(
# self, max_pages: Optional[int] = None
Expand Down
16 changes: 16 additions & 0 deletions vega_sim/scenario/benchmark/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,20 @@
),
],
),
"programs": BenchmarkScenario(
block_length_seconds=1,
step_length_seconds=30,
benchmark_configs=[
BenchmarkConfig(
market_config=configs.research.futr.BTCUSDT.CONFIG,
initial_price=70000,
annualised_volatility=1,
notional_trade_volume=100,
),
],
volume_discounts_enabled=True,
volume_rebate_enabled=True,
referrals_enabled=True,
initial_network_parameters={"market.fee.factors.infrastructureFee": "0.0002"},
),
}
32 changes: 32 additions & 0 deletions vega_sim/scenario/benchmark/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
ExponentialShapedMarketMaker,
MarketOrderTrader,
LimitOrderTrader,
ReferralProgramManager,
VolumeRebateProgramManager,
VolumeDiscountProgramManager,
)
from vega_sim.scenario.fuzzed_markets.agents import (
RiskyMarketOrderTrader,
Expand All @@ -35,6 +38,9 @@ def __init__(
block_length_seconds: float = 1,
step_length_seconds: Optional[float] = None,
initial_network_parameters: Dict[str, Any] = None,
volume_discounts_enabled: bool = False,
volume_rebate_enabled: bool = False,
referrals_enabled: bool = False,
output: bool = True,
):
super().__init__()
Expand All @@ -54,6 +60,9 @@ def __init__(
self.initial_network_parameters = (
initial_network_parameters if initial_network_parameters is not None else {}
)
self.volume_discounts_enabled = volume_discounts_enabled
self.volume_rebate_enabled = volume_rebate_enabled
self.referrals_enabled = referrals_enabled

def configure_agents(
self,
Expand All @@ -74,6 +83,29 @@ def configure_agents(
network_parameters=self.initial_network_parameters,
)
)

if self.referrals_enabled:
self.agents.append(
ReferralProgramManager(
wallet_name="ProgramManagers",
key_name="ReferralProgramManager",
)
)
if self.volume_discounts_enabled:
self.agents.append(
VolumeDiscountProgramManager(
wallet_name="ProgramManagers",
key_name="VolumeDiscountProgramManager",
)
)
if self.volume_rebate_enabled:
self.agents.append(
VolumeRebateProgramManager(
wallet_name="ProgramManagers",
key_name="VolumeRebateProgramManager",
)
)

for _, benchmark_config in enumerate(self.benchmark_configs):

market_name = benchmark_config.market_config.instrument.name
Expand Down
Loading

0 comments on commit e00c604

Please sign in to comment.