Agent Classes
Simulator to the code section the Agent Classes section allows you
to write code for certain agent classes. The agent class itself can be anything
you would like for your simulation, most AMM will have 3 different agents (but
this is just an example, you can identify more and integrate them easily). These
3 agents are lp
, arb
and trader
which stand for Liquidity Provider,
Arbitrager and Trader respectively.
Agent classes have to be defined in this section where each of the agent class
will allow you to specify an agent specific preStep
, featureVector
, step
and postStep
. These code classes will overwrite the default code block (to see
how that works look at the code section page.
This has been made because you probably want a Trader to perform a trade during it's step but the Liquidity Provider to provide liquidity. These are different operations which you will have to code here. The code blocks are all optional.
To get to know more about how to write the code blocks please refer to the instructions for each of the codeblocks here:
Format
name | type |
---|---|
type | array of { class: string, preStep?: string, featureVector?: string, step?: string, postStep?: string } |
required | true |
Example
agentClasses:
- class: "lp"
preStep: |
def custom_agent_class_pre_step(agent, environment, metric_collector):
pass
custom_agent_class_pre_step(a, b, metric_collector)
featureVector: |
def agent_feature_vector(agent, token, environment):
coins_abr = {
'BNT': 0,
'LINK': 1,
'ETH': 2,
'DAI': 3,
'WBTC': 4
}
# same as for traders, calculate asset specific features
vol = environment.get_state().token_states[token].volatility
change = environment.get_state().token_states[token].price_change
# calculate asset share
share = agent.get_wallet().get_token_share(token)
return np.array([coins_abr[token], change, vol, share])
step: |
def custom_agent_class_step(agent, token, action, quantity, environment, metric_collector):
try:
token_address = get_token_address(environment, token)
quantity = int(quantity)
if action == 1:
agent.set_latest_action("deposit")
agent.get_client().bancor_network.deposit(token_address, quantity).transact(generate_tx_details(agent.get_address()))
elif action == 2:
pending_withdrawals = agent.get_variable('withdrawal_request_ids_by_token')[token]
if len(pending_withdrawals) > 0:
agent.set_latest_action("withdrawal")
environment.get_client().bancor_network.withdraw(pending_withdrawals[0]).transact({'from': agent.get_address()})
else:
agent.set_latest_action("cooldown")
withdrawal_request_id = environment.get_client().bancor_network.initWithdrawal(
token_address, quantity).transact({'from': agent.get_address()})
agent.get_variable('withdrawal_request_ids_by_token')[token].append(withdrawal_request_id)
else:
agent.set_latest_action('nothing')
except:
agent.set_latest_action('nothing')
custom_agent_class_step(a, b, c, d, e, metric_collector)
postStep: |
def custom_agent_class_post_step(agent, environment, metric_collector):
pass
custom_agent_class_post_step(a, b, metric_collector)