-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathexample.py
executable file
·42 lines (35 loc) · 1.7 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from supervisor.core.interface import Exchange
from supervisor.core.orders import Order
from supervisor import Supervisor
TEST_API_KEY = 'your-api-key'
TEST_API_SECRET = 'your-api-secret'
if __name__ == '__main__':
# Exchange is an interface-like class to call api methods
exchange = Exchange(api_key=TEST_API_KEY, api_secret=TEST_API_SECRET,
test=True, symbol='XBTUSD')
supervisor = Supervisor(interface=exchange)
# you can disable managing position or orders by set to False needed properties
# supervisor.manage_position = False
# supervisor.manage_orders = False
# create Order objects
stop_loss = Order(order_type='Stop', stop_px=2000, qty=10, side='Sell')
tp1 = Order(order_type='Limit', price=15000, qty=6, side='Sell', passive=True)
tp2 = Order(order_type='Limit', price=20000, qty=4, side='Sell', hidden=True)
trailing_stop = Order(order_type='Stop', stop_px=3000, qty=10, side='Sell')
# attach some callbacks to stop-loss, note that events starts with "_"
# DO NOT USE stop_cycle() method in callbacks!!! It causes deadlock
stop_loss._on_reject = lambda: print('Rejected')
stop_loss._on_fill = lambda: print('We lost position(')
input('Enter to run cycle')
supervisor.run_cycle()
input('Enter to add orders to needed')
supervisor.add_order(stop_loss)
supervisor.add_order(tp1)
supervisor.add_order(tp2)
supervisor.add_trailing_order(trailing_stop, offset=10) # order will trail on 10% distance from current price
input('Enter to enter position')
supervisor.stop_cycle()
supervisor.enter_by_market_order(10)
supervisor.run_cycle()
input('Enter to exit cycle')
supervisor.exit_cycle()