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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat: AMM config
TomMcL committed Mar 12, 2024
commit 8396f8d7b1ef5e69a4b9b53092d992a39136fc96
5 changes: 5 additions & 0 deletions vega_sim/api/data.py
Original file line number Diff line number Diff line change
@@ -95,6 +95,8 @@ class Order:
"market_id",
"asset",
"timestamp",
"margin_mode",
"margin_factor",
],
)

@@ -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
@@ -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),
)


51 changes: 33 additions & 18 deletions vega_sim/devops/registry.py
Original file line number Diff line number Diff line change
@@ -4,25 +4,21 @@

"""

from vega_sim.devops.scenario import DevOpsScenario

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

from vega_sim.scenario.constant_function_market.agents import CFMV3MarketMaker

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(
@@ -255,14 +251,33 @@
market_name=None,
asset_name=None,
num_steps=0,
tick_spacing=10,
num_levels=25,
tick_spacing=0.005,
num_levels=15,
initial_asset_mint=0,
commitment_amount=0,
price_width_above=0.1,
price_width_below=0.1,
margin_usage_at_bound_above=0.9,
margin_usage_at_bound_below=0.9,
initial_price=59200,
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.004,
num_levels=15,
initial_asset_mint=0,
commitment_amount=500,
fee_amount=0.001,
price_width_above=2.0,
price_width_below=0.99,
max_loss_at_bound_above=0.9,
max_loss_at_bound_below=0.9,
initial_price=0.125,
base_balance=3000,
),
}
20 changes: 7 additions & 13 deletions vega_sim/devops/run_agent.py
Original file line number Diff line number Diff line change
@@ -112,20 +112,14 @@ def main():
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.perpetual.settlement_asset
or 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,
network=Network[args.network],
2 changes: 2 additions & 0 deletions vega_sim/environment/environment.py
Original file line number Diff line number Diff line change
@@ -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:
7 changes: 6 additions & 1 deletion vega_sim/local_data_cache.py
Original file line number Diff line number Diff line change
@@ -361,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:
@@ -448,6 +451,7 @@ def initialise_market_data(
def initialise_transfer_monitoring(
self,
):
return
base_transfers = []

base_transfers.extend(
@@ -459,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
)
5 changes: 3 additions & 2 deletions vega_sim/scenario/common/agents.py
Original file line number Diff line number Diff line change
@@ -1564,10 +1564,11 @@ def _move_side(
),
side=order.side,
expires_at=expires_at,
post_only=False,
post_only=True,
)

submissions.append(transaction)
if transaction is not None:
submissions.append(transaction)

if not cancel_and_replace and len(existing_orders) > len(new_shape):
for order in existing_orders[len(new_shape) :]:
Loading