follower.py 1.6 KB

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