Skip to content
Advertisement

How to define an array of action spaces?

I am trying to create a crypto trading bot that can trade multiple crypto coins simulatenously. So for example if I have n=4 coins (e.g. : 0-BTC, 1-ETH, 2-DOT, 3-SOL), then an example of action space would be something like:

action_spaces: [ 1000, 0.0, -3000, 2300]

Where:

  • BUY if action > 0
  • HOLD if action == 0
  • Sell if action < 0

So, in the given example the actions would be:

  • Index 0: Buy btc worth 1000 USDT
  • Index 1: Hold eth
  • Index 2: Sell DOT worth 3000 USDT
  • Index 3: Buy SOL worth of 2300 USDT

So for an n = x with crypto list: [crypto0, crypto1, crypto2, ..., cryptoX] how can I define an action space that has the form: action_space = [action0, action1, action2, ..., actionX]

Advertisement

Answer

I will suggest go with dictionaries. suppose you are having crypto list: [crypto0, crypto1, crypto2, ..., cryptoX] and action space [action0, action1, action2, ..., actionX].

crypto_list = ['crypto0', 'crypto1', 'crypto2', 'cryptoX']
action_space = ['action0', 'action1', 'action2', 'actionX']

cryto_action_map = dict(zip(crypto_list, action_space))

print(cryto_action_map)

which will give output like

{'crypto0': 'action0', 'crypto1': 'action1', 'crypto2': 'action2', 'cryptoX': 'actionX'}

from here you can iterate on each coin and action using items method.

for coin, action in cryto_action_map.items():
    if action > 0:
        # BUY logic
        
    elif action == 0:
        # HOLD logic
        
    elif action < 0:
        # SELL logic

REMEMBER crypto_list and action_space are 2 separate lists and both should have same length.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement