bot.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # DO NOT COPY: TOP SECRET
  2. # Illegal publishing will be charged with up to ₭500
  3. from math import ceil
  4. from random import uniform
  5. from secret_trading_tools import tradables_except_kollar, best_buy_order, cheapest_sell_order, \
  6. some_orders_on, buy, sell, old_order_is_just_expired, delete_order_on, \
  7. transactions_size_since_last_order_on, order_on, own_money, owned_amount, some_order_has_just_been_executed
  8. def follower():
  9. """
  10. The main algorithm
  11. """
  12. for tradable in tradables_except_kollar:
  13. create_order_on(tradable)
  14. while True:
  15. for tradable in tradables_except_kollar:
  16. if old_order_is_just_expired(tradable):
  17. create_order_on(tradable)
  18. if some_order_has_just_been_executed(tradable):
  19. if transactions_size_since_last_order_on(tradable) > 2 * order_on(tradable).amount:
  20. delete_order_on(tradable)
  21. create_order_on(tradable)
  22. def create_order_on(tradable):
  23. """
  24. This function places a new order on the given tradable
  25. """
  26. limit = uniform(best_buy_order, cheapest_sell_order)
  27. duration = 43200
  28. some_orders = some_orders_on(tradable) # returns us roughly log2(x) orders where x is the total # of orders
  29. some_amounts = [order.amount for order in some_orders]
  30. amount = ceil(sum(some_amounts) / len(some_amounts))
  31. stop_loss = False
  32. if limit - best_buy_order < cheapest_sell_order - limit:
  33. if limit * amount < own_money:
  34. buy(tradable, amount, limit, stop_loss, duration)
  35. else:
  36. if amount < owned_amount(tradable):
  37. sell(tradable, amount, limit, stop_loss, duration)
  38. if __name__ == '__main__':
  39. follower()