sample project

jainsiddharthjain
can i get a sample script/project which simply takes data from market feeders, and a simple strategy implemented to start with.

Thanks
  • Imran
    placing limit orders and waiting to get it filled can be frustrating
    so we made this program
    just enter the stock symbol , price and buy price in a excel ...
    as soon as price reaches the level the program will automatically buy for us

    benefits:
    1. it does not block your margin until the prices reaches ....
    2. you can enter at best price levels... so eliminating emotional hurry to enter in a trade
    3. no need to continuously watch the screen to keep checking if the price has reached
    4. immediate order execution

    For any queries contact: [email protected]


    .........................................................................................................................
    from kiteconnect import KiteConnect
    from kiteconnect import KiteTicker
    from datetime import datetime, timedelta

    import logging;
    import openpyxl;
    import datetime,time,os;

    exel_data = {}
    """
    exel_data format :
    {instrument_token:[TIKER,price,"BUY/SELL",IsTradableBuySheet,IsTradableBuyProgram]}
    """

    kws = "";
    kite = "";

    def get_login(api_k,api_s):
    global kws,kite;
    kite = KiteConnect(api_key=api_k)

    print("[*] Generate access Token : ",kite.login_url())
    request_tkn = input("[*] Enter Your Request Token Here : ");

    data = kite.generate_session(request_tkn, api_secret=api_s)
    kite.set_access_token(data["access_token"])
    kws = KiteTicker(api_k, data["access_token"])


    api_k = "xxxxxxxxxx";
    api_s = "xxxxxxxxxxxxxxxxxx";

    trd_capital = int(input("[*] Enter Trading Capital (eg. 10000, 25000) : "));
    sltmp = float(input("[*] Enter Stoploss (eg. 2, 2.5) : "));
    tptmp = float(input("[*] Enter Square Off (eg. 3, 3.5) : "));

    get_login(api_k,api_s);


    def initialize_from_exel(ws):
    i = 1;
    sheet = openpyxl.load_workbook('buy.xlsx').active
    while sheet.cell(i,1).value!=None:
    d1 = (sheet.cell(i,1).value).split("/")
    d1[1] = int(d1[1])
    d2 = float(sheet.cell(i,2).value)
    d3 = (sheet.cell(i,3).value)
    d4 = (sheet.cell(i,4).value)

    try:
    d4 = exel_data[d1[1]][3]
    d5 = exel_data[d1[1]][4] #is trade is placed by program
    exel_data[d1[1]] = [d1[0],d2,d3,True if d4==1 else False,d5]
    except Exception as e:
    print("[+] Adding ",d1[0]," to List")
    ws.subscribe([d1[1]])
    ws.set_mode(ws.MODE_FULL,[d1[1]])
    exel_data[d1[1]] = [d1[0],d2,d3,True if d4==1 else False,True]

    i+=1;


    def do_buy_sell(instrument_token,company_data):
    global exel_data;
    global trd_capital,sltmp,tptmp;
    global kite;

    d = exel_data[instrument_token];
    if d[2]=='BUY' and d[3] and d[4]:
    quant = int(trd_capital//company_data['last_price']);
    sl = sltmp/quant
    tp = tptmp/quant
    if d[1]>=company_data['last_price']: #buy
    kite.place_order(tradingsymbol=d[0],price=company_data['last_price'],variety=kite.VARIETY_BO,exchange=kite.EXCHANGE_NSE,transaction_type=kite.TRANSACTION_TYPE_BUY,quantity=quant,squareoff=tp, stoploss=sl,order_type=kite.ORDER_TYPE_LIMIT,product=kite.PRODUCT_BO)
    exel_data[instrument_token][4] = False;
    print("BUY",quant," OF ",d[0]," ON TIME ",company_data['timestamp']," AT PRICE ",company_data['last_price']);



    if d[2]=='SELL' and d[3] and d[4]:
    quant = int(trd_capital//company_data['last_price']);
    sl = sltmp/quant
    tp = tptmp/quant
    if d[1]<=company_data['last_price']: #sell
    kite.place_order(tradingsymbol=d[0],price=company_data['last_price'],variety=kite.VARIETY_BO,exchange=kite.EXCHANGE_NSE,transaction_type=kite.TRANSACTION_TYPE_SELL,quantity=quant,squareoff=tp, stoploss=sl,order_type=kite.ORDER_TYPE_LIMIT,product=kite.PRODUCT_BO)
    exel_data[instrument_token][4] = False;
    print("SELL",quant," OF ",d[0]," ON TIME ",company_data['timestamp']," AT PRICE ",company_data['last_price']);


    def on_ticks(ws, ticks):
    global kite;

    if int(time.time())%15==0:
    initialize_from_exel(ws);

    for company_data in ticks:
    try:
    #print(company_data)
    do_buy_sell(company_data['instrument_token'],company_data);
    except Exception as e:
    pass;



    def on_connect(ws, response):
    initialize_from_exel(ws);

    # Assign the callbacks.

    kws.on_ticks = on_ticks
    kws.on_connect = on_connect

    kws.connect()
Sign In or Register to comment.