-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_order.py
More file actions
72 lines (48 loc) · 2.08 KB
/
basic_order.py
File metadata and controls
72 lines (48 loc) · 2.08 KB
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
from smartapi import SmartConnect
import os
import urllib
import json
from pyotp import TOTP
key_path = r"E:\OneDrive\Desktop\f"
os.chdir(key_path)
key_secret = open("key.txt","r").read().split()
obj=SmartConnect(api_key=key_secret[0])
data = obj.generateSession(key_secret[2],key_secret[3],TOTP(key_secret[4]).now())
feed_token = obj.getfeedToken()
instrument_url = "https://margincalculator.angelbroking.com/OpenAPI_File/files/OpenAPIScripMaster.json"
response = urllib.request.urlopen(instrument_url)
instrument_list = json.loads(response.read())
def token_lookup(ticker, instrument_list, exchange="NSE"):
for instrument in instrument_list:
if instrument["name"] == ticker and instrument["exch_seg"] == exchange and instrument["symbol"].split('-')[-1] == "EQ":
return instrument["token"]
def place_limit_order(instrument_list,ticker,buy_sell,price,quantity,exchange="NSE"):
params = {
"variety":"NORMAL",
"tradingsymbol":"{}-EQ".format(ticker),
"symboltoken":token_lookup(ticker, instrument_list),
"transactiontype":buy_sell,
"exchange":exchange,
"ordertype":"LIMIT",
"producttype":"INTRADAY",
"duration":"DAY",
"price":price,
"quantity":quantity
}
order = obj.placeOrder(params)
return order
def place_market_order(instrument_list,ticker,buy_sell,quantity,sl=0,sqof=0,exchange="NSE"):
params = {
"variety":"NORMAL",
"tradingsymbol":"{}-EQ".format(ticker),
"symboltoken":token_lookup(ticker, instrument_list),
"transactiontype":buy_sell,
"exchange":exchange,
"ordertype":"MARKET",
"producttype":"INTRADAY",
"duration":"DAY",
"quantity":quantity
}
order = obj.placeOrder(params)
return order
place_limit_order(instrument_list, "HDFC", "BUY", 2400, 1)