forked from himanjim/TradingScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OrdersFormer.py
88 lines (70 loc) · 2.22 KB
/
OrdersFormer.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import csv
import locale
from datetime import datetime
import math
import time
from pytz import timezone
import ScrapUtils as nse_bse
import Utils as util
indian_timezone = timezone('Asia/Calcutta')
today_date_str = datetime.now(indian_timezone).strftime ('%b-%d-%Y')
def round_to_5(x, base=5):
if x < base:
return x
return base * round (x / base)
co_bo_blocked_stocks = []
with open ('C:/Users/Admin/Desktop/CM_Margin_'+ today_date_str + '.csv') as csv_file:
csv_reader = csv.reader (csv_file, delimiter=',')
for row in csv_reader:
if len(row[0].strip()) > 0:
co_bo_blocked_stocks.append(row[0].strip ())
stock_ids = [
'SAIL',
'PAGEIND',
'GLENMARK',
'ONGC',
'BALKRISIND',
'NBCC',
'BHARTIARTL',
'CESC',
'UNIONBANK',
'APOLLOHOSP',
]
orders = []
option_lots = nse_bse.get_nse_fo_lots ()
priority = 1
kite = util.intialize_kite_api()
for stock_id in stock_ids:
if stock_id in co_bo_blocked_stocks:
print('CO/BO blocked for stock_id:%s' %(stock_id))
continue
nse_stock_id = 'NSE:' + stock_id
last_close = kite.quote (nse_stock_id)[nse_stock_id]['last_price']
if stock_id in option_lots:
future_lot = option_lots[stock_id]
else:
future_lot = None
orig_future_lot = math.ceil (500000 / last_close)
locale.setlocale(locale.LC_ALL, '')
lot = int (orig_future_lot / 2)
order = {
'symbol': stock_id,
'nse_symbol': 'NSE:' + stock_id,
'future_lot': future_lot,
'orig_future_lot': orig_future_lot,
'priority': priority,
'trigger_price_pts': round (util.min_tick_size * round ((200 / lot) / util.min_tick_size), 2),
'traded_amount': locale.currency(last_close * lot, grouping=True),
'last_close': last_close,
'tag': None
}
orders.append (order)
priority += 1
time.sleep (1)
print ('[')
for order in orders:
print (' {')
for k, v in order.items ():
print (" '" + k + "':", [str (v), "'" + str (v) + "'"][k == 'symbol' or k == 'nse_symbol' or k == 'name' or k == 'traded_amount'] + ",")
print (' },')
print (']')