Trading Bot - problem for testing

Back to General discussions forum

Rodion (admin)     2024-02-24 09:24:34
User avatar

Hi Friends!

UPD: this problem is live now.

Here some new problem is being prepared in which you can try your skills in writing code for automated trading on cryptocurrency exchange. Currently it is not listed and won't return "successful" verdict, but will tell how many profit you made.

I plan to convert it to "challenge" type so we have a ranking table and can see who is true master of auto-trading :)

Good thing is that it wants you to write trading function in Python.

However while it is not extremely complicated, I feel there could be some bugs or possible improvements, so that is why I invite you to try it and tell what may be wrong or lacking.

I'm not sure, whether "driver" code (one which runs your trading function) needs to be published. For now let me put it here (and sorry for it being so ugly formatted):

# here is prepended user's "tick(...)" function
# user can also declare global variables outside it

def main():
 ticks = [] # these are propagated from some data file in form of tuples (s, h, l, e)
 money = 100000
 order = None
 takeprof = None
 stoploss = None
 for t in ticks:
  cmd = tick(*t, order)
  closing = None
  if cmd.startswith('O'):
   cmd = cmd.split()
   if order is not None:
    print('Error: Trying to open new order while previous is not yet closed')
    return
   order = t[3]
   print('Opening at', order)
   if len(cmd) > 1:
    stoploss = int(cmd[1])
    if stoploss >= order:
     print('Error: StopLoss should be below current price')
     return
   if len(cmd) > 2:
    takeprof = int(cmd[2])
    if takeprof <= order:
     print('Error: TakeProfit should be above current price')
     return
  elif cmd == 'C':
   if order is None:
    print('Error: Trying to close order though it was not opened yet')
    return
   closing = t[3]
  elif cmd != '' and cmd is not None:
   print('Error: Bad command returned by trader function: ' + cmd)
   return
  if takeprof is not None and t[1] >= takeprof:
   closing = takeprof
  elif stoploss is not None and t[2] <= stoploss:
   closing = stoploss
  if closing is not None:
   print('Closing at ', closing, closing / order * 0.999)
   money *= closing / order
   money -= money / 1000
   order = None
   takeprof = None
   stoploss = None
 if order is not None:
  print('Closing at end', ticks[-1][3])
  money *= ticks[-1][3] / order
  money -= money / 1000
 print('Money at end:', round(money))
main()
Please login and solve 5 problems to be able to post at forum