1
1

follower.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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, flip_a_coin, cheapest_buy_order, best_sell_order, \
  5. some_orders_on, buy, sell, old_order_is_expired, delete_order_on, \
  6. transactions_size_since_last_order_on, order_on
  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_expired(tradable):
  16. create_order_on(tradable)
  17. if transactions_size_since_last_order_on(tradable) > 2 * order_on(tradable).amount:
  18. delete_order_on(tradable)
  19. create_order_on(tradable)
  20. def create_order_on(tradable):
  21. """
  22. This function places a new order on the given tradable
  23. """
  24. limit = uniform(cheapest_buy_order, best_sell_order)
  25. duration = 43200
  26. some_orders = some_orders_on(tradable) # returns us roughly math.log2(x) orders where x is the total # of orders
  27. some_amounts = [order.amount for order in some_orders]
  28. amount = ceil(sum(some_amounts) / len(some_amounts))
  29. stop_loss = False
  30. if flip_a_coin() == 'heads':
  31. buy(tradable, amount, limit, stop_loss, duration)
  32. else:
  33. sell(tradable, amount, limit, stop_loss, duration)
  34. if __name__ == '__main__':
  35. follower()