follower.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. place_order, some_orders_on, buy, sell, old_order_is_expired, delete_order_on, \
  6. transactions_size_since_last_order_on, order_on
  7. def create_order():
  8. """
  9. This function places a new order on the given tradable
  10. """
  11. limit = uniform(cheapest_buy_order, best_sell_order)
  12. duration = 43200
  13. some_orders = some_orders_on(tradable) # returns us roughly math.log2(x) orders where x is the total # of orders
  14. some_amounts = [order.amount for order in some_orders]
  15. amount = ceil(sum(some_amounts) / len(some_amounts))
  16. stop_loss = False
  17. if flip_a_coin() == 'heads':
  18. buy(tradable, amount, limit, stop_loss, duration)
  19. else:
  20. sell(tradable, amount, limit, stop_loss, duration)
  21. for tradable in tradables_except_kollar:
  22. create_order()
  23. while True:
  24. for tradable in tradables_except_kollar:
  25. if old_order_is_expired(tradable):
  26. delete_order_on(tradable)
  27. create_order()
  28. if transactions_size_since_last_order_on(tradable) > 2 * order_on(tradable).amount:
  29. delete_order_on(tradable)
  30. create_order()