Beispiel #1
0
    timenow = (datetime.datetime.now().hour * 60 +
               datetime.datetime.now().minute)
print("Market opened..........", datetime.datetime.now())

orderplaced = False
while orderplaced == False:
    timenow = (datetime.datetime.now().hour * 60 +
               datetime.datetime.now().minute)
    if timenow >= closetime:
        print("Market Closed.........", datetime.datetime.now())
        keep_running = False
        break
    try:
        LTP = kite.ltp(
            'NFO:{}'.format(tradingsymbol_nifty_future)
        )['NFO:{}'.format(
            tradingsymbol_nifty_future
        )]['last_price']  # This call downloads LTP from zerodha kite conncet API
        LTP = int(LTP)
        print(tradingsymbol_nifty_future, "LTP:", LTP, datetime.datetime.now())
        signal = get_signal(
            LTP
        )  # this statement pass data in function get_signal and return the signal
        if signal == 'BUY' or signal == 'SELL':
            try:
                orderid = kite.place_order(
                    exchange='NFO',
                    tradingsymbol=tradingsymbol_nifty_future,
                    transaction_type=signal,
                    quantity=int(
                        75),  # set the quantity in numptiple of lot size
from kiteconnect import KiteConnect
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)


# Fetch quote details
quote = kite.quote("NSE:INFY")

# Fetch last trading price of an instrument
ltp = kite.ltp("NSE:INFY")

# Fetch order details
orders = kite.orders()

# Fetch position details
positions = kite.positions()

# Fetch holding details
holdings = kite.holdings()
Beispiel #3
0
             't1_quantity': 0,
             'tradingsymbol': 'ASHOKLEY'}]"""

instrument_token = []
purchase_price = {}
quantity = {}

# Gets the instrument token and purchase price for each holding
for holding in holdings:
    instrument = "NSE:" + holding['tradingsymbol']
    instrument_token.append(instrument)
    purchase_price[instrument] = holding['average_price']
    quantity[instrument] = holding['quantity']

# Gets the last trading price
ltp_prices = kite.ltp(instrument_token)
pprint.pprint(ltp_prices)

# Check for each instrument token
for token in instrument_token:
    percent_less_check = -0.03
    percent_less_sell = -0.05
    if ltp_prices[token]['last_price'] - purchase_price[
            token] < percent_less_check * purchase_price[token]:
        print("Less than 3 percent, token = ", token[4:],
              "\nLast Traded Price", ltp_prices[token]['last_price'],
              "\nPurchase Price", purchase_price[token])

        # Commented so that while testing, orders don't get placed.
        """try:
            order_id = kite.place_order(tradingsymbol=token[4:]
from kiteconnect import KiteConnect

api_key=open('secret/api_key.txt','r').read()
api_secret=open('secret/api_secret.txt','r').read()


kite = KiteConnect(api_key=api_key)
kite.set_access_token(open('secret/access_token.txt','r').read())

def order():
    orderid=kite.place_order(tradingsymbol="INFY", 
                            quantity="1", 
                            exchange="NSE", 
                            transaction_type="BUY", 
                            order_type="MARKET", 
                            product="CNC", 
                            validity="DAY", 
                            variety="regular")
    print(orderid)
order()

Lastprice=kite.ltp('NSE:INFY')
    
print(Lastprice)