-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathCombinedEntrySTLPTarget.txt
More file actions
55 lines (42 loc) · 1.56 KB
/
CombinedEntrySTLPTarget.txt
File metadata and controls
55 lines (42 loc) · 1.56 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
from kiteconnect import KiteConnect
import time
# Enter position values
Qty = 75
S1 = "NIFTY2170115850CE"
S2 = "NIFTY2170115850PE"
entryPrice = 190
stopLoss = 200
targetPrice = 170
# Initialise
kite = KiteConnect(api_key="ENTERYOURAPIKEY")
kite.set_access_token("ENTERYOURACCESSTOKEN")
# Function to place orders
def placeOrders(trans_type):
try:
kite.place_order(tradingsymbol=S1, variety='regular', exchange='NFO', transaction_type=trans_type,
quantity=Qty, order_type='MARKET', product='MIS')
except: print("Order placement failed")
try:
kite.place_order(tradingsymbol=S2, variety='regular', exchange='NFO', transaction_type=trans_type,
quantity=Qty, order_type='MARKET', product='MIS')
except: print("Order placement failed")
# Loop for entry orders
while True:
try:
combinedPremium = kite.ltp(['NFO:'+S1])['NFO:'+S1]['last_price'] + kite.ltp(['NFO:'+S2])['NFO:'+S2]['last_price']
except: continue
print("Combined Premium = ", combinedPremium)
if (combinedPremium >= entryPrice):
placeOrders('SELL')
break
time.sleep(5) # Change as per your need
# Loop for stoploss/target orders
while True:
try:
combinedPremium = kite.ltp(['NFO:'+S1])['NFO:'+S1]['last_price'] + kite.ltp(['NFO:'+S2])['NFO:'+S2]['last_price']
except: continue
print("Combined Premium = ", combinedPremium)
if (combinedPremium >= stopLoss or combinedPremium <= targetPrice):
placeOrders('BUY') # Stoploss/Target hit
break
time.sleep(5) # Change as per your need