forked from suresh-n/richdotin
-
Notifications
You must be signed in to change notification settings - Fork 2
/
api_helper.py
74 lines (58 loc) · 2.53 KB
/
api_helper.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from NorenRestApiPy.NorenApi import NorenApi
from threading import Timer
import pandas as pd
import time
import concurrent.futures
api = None
class Order:
def __init__(self, buy_or_sell:str = None, product_type:str = None,
exchange: str = None, tradingsymbol:str =None,
price_type: str = None, quantity: int = None,
price: float = None,trigger_price:float = None, discloseqty: int = 0,
retention:str = 'DAY', remarks: str = "tag",
order_id:str = None):
self.buy_or_sell=buy_or_sell
self.product_type=product_type
self.exchange=exchange
self.tradingsymbol=tradingsymbol
self.quantity=quantity
self.discloseqty=discloseqty
self.price_type=price_type
self.price=price
self.trigger_price=trigger_price
self.retention=retention
self.remarks=remarks
self.order_id=None
#print(ret)
def get_time(time_string):
data = time.strptime(time_string,'%d-%m-%Y %H:%M:%S')
return time.mktime(data)
class ShoonyaApiPy(NorenApi):
def __init__(self):
NorenApi.__init__(self, host='https://api.shoonya.com/NorenWClientTP/', websocket='wss://api.shoonya.com/NorenWSTP/', eodhost='https://api.shoonya.com/chartApi/getdata/')
global api
api = self
def place_basket(self, orders):
resp_err = 0
resp_ok = 0
result = []
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
future_to_url = {executor.submit(self.place_order, order): order for order in orders}
for future in concurrent.futures.as_completed(future_to_url):
url = future_to_url[future]
try:
result.append(future.result())
except Exception as exc:
print(exc)
resp_err = resp_err + 1
else:
resp_ok = resp_ok + 1
return result
def placeOrder(self,order: Order):
ret = NorenApi.place_order(self, buy_or_sell=order.buy_or_sell, product_type=order.product_type,
exchange=order.exchange, tradingsymbol=order.tradingsymbol,
quantity=order.quantity, discloseqty=order.discloseqty, price_type=order.price_type,
price=order.price, trigger_price=order.trigger_price,
retention=order.retention, remarks=order.remarks)
#print(ret)
return ret