Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: CFM bots #528

Open
wants to merge 37 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
d545acb
feat: Adding CFM scenario
TomMcL Oct 11, 2023
cfd6440
feat: CFM investigation
TomMcL Oct 14, 2023
7f1e7ee
feat: Adding to market trader sensitivity
TomMcL Oct 16, 2023
af54db8
feat: v3 wip
TomMcL Oct 24, 2023
36bab6a
Merge remote-tracking branch 'origin/develop' into feat/cfm_bot
TomMcL Oct 24, 2023
e27dec9
feat: Latest CFM
TomMcL Oct 25, 2023
7e5b192
feat: Tweaks to scenario
TomMcL Oct 25, 2023
3f3962f
Merge remote-tracking branch 'origin/develop' into feat/cfm_bot
TomMcL Oct 26, 2023
5da409c
feat: Volume CFM
TomMcL Oct 27, 2023
40771a1
feat: Working trade v3
TomMcL Oct 27, 2023
f68015c
fix: Fix broken extraction func
TomMcL Oct 31, 2023
337fc43
fix: Fix broken extraction func
TomMcL Oct 31, 2023
dffb920
Merge remote-tracking branch 'origin/develop' into feat/cfm_bot
TomMcL Oct 31, 2023
44110d1
feat: Fix up ledger transfers filter
TomMcL Oct 31, 2023
d514a66
feat: Remove unwanted changes
TomMcL Oct 31, 2023
cf838a6
feat: Extracting function call
TomMcL Nov 2, 2023
1aabbda
Merge remote-tracking branch 'origin/develop' into feat/cfm_bot
TomMcL Nov 15, 2023
76884ea
feat: Adding real MMs
TomMcL Nov 16, 2023
c2a3669
feat: Adding notebook
TomMcL Dec 11, 2023
60de7d8
feat: CFM changes
TomMcL Dec 28, 2023
cd835fb
Merge remote-tracking branch 'origin/develop' into feat/cfm_bot
TomMcL Feb 6, 2024
5fc5d96
feat: Don't break on position empty dict
TomMcL Feb 6, 2024
040e9e8
Merge remote-tracking branch 'origin/develop' into feat/cfm_bot
TomMcL Feb 16, 2024
55ed4ef
feat: Running CFM bot
TomMcL Feb 22, 2024
d6820cb
feat: bots
TomMcL Mar 5, 2024
f59ea83
Merge remote-tracking branch 'origin/develop' into feat/cfm_bot
TomMcL Mar 6, 2024
8396f8d
feat: AMM config
TomMcL Mar 12, 2024
efd7f09
feat: Bounds check
TomMcL Mar 12, 2024
7a658b5
feat: Bounds check
TomMcL Mar 12, 2024
af3a049
feat: Bounds check
TomMcL Mar 12, 2024
0298453
feat: Bounds check
TomMcL Mar 12, 2024
9572d96
feat: Bounds check
TomMcL Mar 12, 2024
6927874
feat: Bounds check
TomMcL Mar 12, 2024
36b0bf6
feat: Bounds check
TomMcL Mar 12, 2024
5101355
feat: new market
TomMcL Mar 20, 2024
3b3b33f
feat: Fix eqs
TomMcL Mar 22, 2024
9662971
feat: Updates
TomMcL Apr 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
355 changes: 355 additions & 0 deletions notebooks/vAMM.ipynb

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions vega_sim/api/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ class Order:
"market_id",
"asset",
"timestamp",
"margin_mode",
"margin_factor",
],
)

Expand Down Expand Up @@ -915,6 +917,7 @@ def _trade_from_proto(
def _margin_level_from_proto(
margin_level: vega_protos.vega.MarginLevels, decimal_spec: DecimalSpec
) -> MarginLevels:
print(margin_level)
return MarginLevels(
maintenance_margin=num_from_padded_int(
margin_level.maintenance_margin, decimal_spec.asset_decimals
Expand All @@ -932,6 +935,8 @@ def _margin_level_from_proto(
market_id=margin_level.market_id,
asset=margin_level.asset,
timestamp=margin_level.timestamp,
margin_mode=margin_level.margin_mode,
margin_factor=float(margin_level.margin_factor),
)


Expand Down
6 changes: 4 additions & 2 deletions vega_sim/api/data_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,12 +627,14 @@ def list_ledger_entries(
base_request.date_range.CopyFrom(
data_node_protos_v2.trading_data.DateRange(
start_timestamp=(
from_datetime.timestamp() * 1e9
int(from_datetime.timestamp() * 1e9)
if from_datetime is not None
else None
),
end_timestamp=(
to_datetime.timestamp() * 1e9 if to_datetime is not None else None
int(to_datetime.timestamp() * 1e9)
if to_datetime is not None
else None
),
)
)
Expand Down
1 change: 0 additions & 1 deletion vega_sim/api/market.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@

"""

import copy
import functools
import logging
from typing import Optional, Union
Expand Down
74 changes: 65 additions & 9 deletions vega_sim/devops/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,21 @@

"""

from vega_sim.devops.scenario import DevOpsScenario

from vega_sim.scenario.common.agents import (
ArbitrageLiquidityProvider,
ExponentialShapedMarketMaker,
)

from vega_sim.devops.classes import (
AuctionTraderArgs,
MarketMakerArgs,
MarketManagerArgs,
AuctionTraderArgs,
RandomTraderArgs,
SensitiveTraderArgs,
SimulationArgs,
)

from vega_sim.devops.scenario import DevOpsScenario
from vega_sim.scenario.common.agents import (
ArbitrageLiquidityProvider,
ExponentialShapedMarketMaker,
)
from vega_sim.scenario.common.utils.price_process import Granularity, LivePrice
from vega_sim.scenario.constant_function_market.agents import CFMV3MarketMaker

SCENARIOS = {
"ETHUSD": lambda: DevOpsScenario(
Expand Down Expand Up @@ -247,4 +245,62 @@
state_update_freq=10,
tag="agent",
),
"amm_market_maker_ethusd": lambda: CFMV3MarketMaker(
wallet_name=None,
key_name=None,
market_name=None,
asset_name=None,
num_steps=0,
tick_spacing=0.005,
num_levels=15,
initial_asset_mint=0,
commitment_amount=0,
price_width_above=2.0,
price_width_below=0.98,
max_loss_at_bound_above=0.7,
max_loss_at_bound_below=0.7,
initial_price=0.1674,
base_balance=100_000,
),
# "amm_market_maker_kepusd_prod": lambda: CFMV3MarketMaker(
# wallet_name=None,
# key_name=None,
# market_name=None,
# asset_name=None,
# num_steps=0,
# tick_spacing=0.001,
# num_levels=13,
# initial_asset_mint=0,
# commitment_amount=500,
# bound_perc=0.17,
# fee_amount=0.001,
# price_width_above=0.3,
# price_width_below=0.4,
# margin_multiple_at_lower=0.1,
# margin_multiple_at_upper=0.1,
# initial_price=0.1381,
# base_balance=3000,
# position_offset=2600,
# ),
"amm_market_maker_hlpusd_prod": lambda: CFMV3MarketMaker(
wallet_name=None,
key_name=None,
market_name=None,
asset_name=None,
num_steps=0,
tick_spacing=0.5,
num_levels=13,
initial_asset_mint=0,
commitment_amount=500,
bound_perc=0.17,
fee_amount=0.001,
price_width_above=4,
price_width_below=0.99,
margin_multiple_at_lower=0.5,
margin_multiple_at_upper=0.5,
initial_price=4,
base_balance=3000,
position_offset=0,
order_validity_length=60,
),
}
15 changes: 8 additions & 7 deletions vega_sim/devops/run_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,16 @@ def main():
with VegaServiceNetwork(
network=Network[args.network],
run_with_console=args.console,
run_with_wallet=True,
) as vega:
if agent is not None:
agent.asset_name = vega.data_cache.asset_from_feed(
asset_id=vega.market_info(
vega.find_market_id(
name=agent.market_name, raise_on_missing=True
)
).tradable_instrument.instrument.future.settlement_asset
).details.symbol
market_info = vega.market_info(
vega.find_market_id(name=agent.market_name, raise_on_missing=True)
)
agent.asset_name = (
market_info.tradable_instrument.instrument.perpetual.settlement_asset
or market_info.tradable_instrument.instrument.future.settlement_asset
)

scenario.run_iteration(
vega=vega,
Expand Down
4 changes: 2 additions & 2 deletions vega_sim/devops/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def configure_agents(
random_state=random_state
)
else:
self.price_process = get_live_price(product=self.binance_code)
self.price_process = None # get_live_price(product=self.binance_code)

if self.scenario_wallet.market_creator_agent is None:
raise ValueError(
Expand Down Expand Up @@ -270,7 +270,7 @@ def configure_agents(
if kwargs.get("network", Network.FAIRGROUND) == Network.NULLCHAIN:
kwargs["agent"].price_process_generator = iter(self.price_process)

kwargs["agent"].order_validity_length = self.step_length_seconds
kwargs["agent"].order_validity_length = 10 * self.step_length_seconds

agents.append(kwargs.get("agent", None))

Expand Down
2 changes: 2 additions & 0 deletions vega_sim/environment/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,13 +544,15 @@ def _run(

def step(self, vega: VegaServiceNetwork) -> None:
t = time.time()
print("Stepping")
state = self.state_func(vega)
logging.debug(f"Get state took {time.time() - t} seconds.")
for agent in (
sorted(self.agents, key=lambda _: self.random_state.random())
if self.random_agent_ordering
else self.agents
):
agent.step(state)
try:
agent.step(state)
except Exception as e:
Expand Down
10 changes: 8 additions & 2 deletions vega_sim/local_data_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ def start_live_feeds(
market_ids=market_ids,
party_ids=party_ids,
)
self.initialise_transfer_monitoring()
if start_high_load_feeds:
self.initialise_transfer_monitoring()
self.initialise_market_data(
market_ids,
)
Expand Down Expand Up @@ -360,7 +361,10 @@ def initialise_assets(self):
self._asset_from_feed[asset.id] = asset

def initialise_accounts(self):
base_accounts = data.list_accounts(data_client=self._trading_data_client)
base_accounts = data.list_accounts(
data_client=self._trading_data_client,
pub_key="683a68eab083f765a93d342bb15e2fed41a9d8f9a61212b6af1e11e883620125",
)

with self.account_lock:
for account in base_accounts:
Expand Down Expand Up @@ -447,6 +451,7 @@ def initialise_market_data(
def initialise_transfer_monitoring(
self,
):
return
base_transfers = []

base_transfers.extend(
Expand All @@ -458,6 +463,7 @@ def initialise_transfer_monitoring(
self._transfer_state_from_feed.setdefault(t.party_to, {})[t.id] = t

def initialise_network_parameters(self):
return
base_network_parameters = data.list_network_parameters(
data_client=self._trading_data_client
)
Expand Down
2 changes: 2 additions & 0 deletions vega_sim/network_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def manage_vega_processes(

if run_with_wallet:
vega_wallet_path = environ.get("VEGA_WALLET_PATH", "vegawallet")

vegaWalletProcess = _popen_process(
popen_args=[
vega_wallet_path,
Expand Down Expand Up @@ -198,6 +199,7 @@ def _find_network_config_toml(
),
]
)

for search_path in search_paths:
full_path = path.join(
search_path,
Expand Down
Loading