follower.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from math import ceil
  2. from random import uniform
  3. from secret_trading_tools import tradables_except_kollar, flip_a_coin, cheapest_buy_order, best_sell_order, place_order, \
  4. some_orders_on, buy, sell, old_order_is_expired, delete_order_on, transactions_size_since_last_order_on, order_on
  5. def create_order_on(tradable):
  6. """
  7. This function places a new order on the given tradable
  8. """
  9. limit = uniform(cheapest_buy_order, best_sell_order)
  10. duration = 43200
  11. some_orders = some_orders_on(tradable)
  12. some_amounts = [tradable.amount for tradable in some_orders]
  13. amount = ceil(sum(some_amounts) / len(some_amounts))
  14. stop_loss = False
  15. if flip_a_coin() == 'heads':
  16. buy(tradable, amount, limit, stop_loss, duration)
  17. else:
  18. sell(tradable, amount, limit, stop_loss, duration)
  19. for tradable in tradables_except_kollar:
  20. create_order_on(tradable)
  21. while True:
  22. for tradable in tradables_except_kollar:
  23. if old_order_is_expired(tradable):
  24. delete_order_on(tradable)
  25. create_order_on(tradable)
  26. if transactions_size_since_last_order_on(tradable) > 2 * order_on(tradable).amount:
  27. delete_order_on(tradable)
  28. create_order_on(tradable)