-
Notifications
You must be signed in to change notification settings - Fork 9
/
kc_orders.py
43 lines (38 loc) · 1.62 KB
/
kc_orders.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
from kiteconnect import KiteConnect
import logging
import os
#generate trading session
access_token = open("access_token.txt",'r').read()
key_secret = open("api_key.txt",'r').read().split()
kite = KiteConnect(api_key=key_secret[0])
kite.set_access_token(access_token)
def placeMarketOrder(symbol,buy_sell,quantity):
# Place an intraday market order on NSE
if buy_sell == "buy":
t_type=kite.TRANSACTION_TYPE_BUY
elif buy_sell == "sell":
t_type=kite.TRANSACTION_TYPE_SELL
kite.place_order(tradingsymbol=symbol,
exchange=kite.EXCHANGE_NSE,
transaction_type=t_type,
quantity=quantity,
order_type=kite.ORDER_TYPE_MARKET,
product=kite.PRODUCT_MIS,
variety=kite.VARIETY_REGULAR)
def placeBracketOrder(symbol,buy_sell,quantity,atr,price):
# Place an intraday market order on NSE
if buy_sell == "buy":
t_type=kite.TRANSACTION_TYPE_BUY
elif buy_sell == "sell":
t_type=kite.TRANSACTION_TYPE_SELL
kite.place_order(tradingsymbol=symbol,
exchange=kite.EXCHANGE_NSE,
transaction_type=t_type,
quantity=quantity,
order_type=kite.ORDER_TYPE_LIMIT,
price=price, #BO has to be a limit order, set a low price threshold
product=kite.PRODUCT_MIS,
variety=kite.VARIETY_BO,
squareoff=int(6*atr),
stoploss=int(3*atr),
trailing_stoploss=2)