-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorder.py
57 lines (48 loc) · 1.53 KB
/
order.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import time
from global_config import *
from logger import myLogger
class Order:
def __init__(self, bitmex):
self.bitmex = bitmex
def market_order(self, quantity):
ts = str(round(time.time()))
if quantity >= 0:
text = 'Enter Market Long'
clOrdID = f'market-long-{ts}-entry'
else:
text = 'Enter Market Short'
clOrdID = f'market-short-{ts}-entry'
myLogger.log_market_order(
quantity=quantity,
timestamp=ts
)
if PLACE_TRADES:
self.bitmex.Order.Order_new(
symbol="XBTUSD",
ordType="Market",
orderQty=int(quantity),
text=text,
clOrdID=clOrdID
).result()
def limit_order(self, quantity, price):
ts = str(round(time.time()))
if quantity >= 0:
text = f'Enter Market Long at {price}'
clOrdID = f'limit-long-{ts}-entry-{price}'
else:
text = f'Enter Market Short at {price}'
clOrdID = f'limit-short-{ts}-entry-{price}'
myLogger.log_limit_order(
quantity=quantity,
timestamp=ts,
price=price
)
if PLACE_TRADES:
self.bitmex.Order.Order_cancelAll().result()
self.bitmex.Order.Order_new(
symbol="XBTUSD",
price=price,
orderQty=int(quantity),
text=text,
clOrdID=clOrdID
).result()