Esempio n. 1
0
    def __init__(self, api_key, public_token, user_id, root=None):
        """

        :param api_key:
        :param public_token:
        :param user_id:
        :param root:
        """
        self.__call_time = arrow.utcnow().float_timestamp
        self._gm_name = self.__call_time
        WebSocket.__init__(self, api_key, public_token, user_id, root)
Esempio n. 2
0
def tick_init(api_key, public_token, id):
	kws = WebSocket(api_key, public_token, id)
	make_tick_df()
	#Remove below line before restarting in order to save data
	make_tick_file()
	num = int(input("Enter the number of stocks to subscribe\n"))
	set_subscription_list(num)
	# Assign the callbacks.
	kws.on_tick = on_tick
	kws.on_connect = on_connect

	# Infinite loop on the main thread. Nothing after this will run.
	# You have to use the pre-defined callbacks to manage subscriptions.
	kws.connect(True)
Esempio n. 3
0
      'lot_size': 40, 'instrument_type': 'CE', 'segment': 'NFO-OPT', 'exchange':
      'NFO'}

pe = {'instrument_token': '13873666', 'exchange_token': '54194',
      'tradingsymbol': 'BANKNIFTY17NOV25800PE', 'name': '', 'last_price':
      172.25, 'expiry': '2017-11-30', 'strike': 25800.0, 'tick_size': 0.05,
      'lot_size': 40, 'instrument_type': 'PE', 'segment': 'NFO-OPT', 'exchange':
      'NFO'}
"""

print("""
      Initializing websocket...
      """)
try:
    # Initialise.
    kws = WebSocket(api_key, access_token['public_token'],
                    access_token["user_id"])
except Exception as e:
    print(e)
    sys.exit(1)


def on_tick(tick, ws):
    # Callback for tick reception.
    # print('timestamp: {} tick: {}'.format(time.time(), tick))
    print('Sending {}'.format(json.dumps(tick)))
    socket.send_string(json.dumps(tick))


def on_connect(ws):
    # Callback for successful connection.
    # Subscribe to a list of instrument_tokens (RELIANCE and ACC
Esempio n. 4
0
import sys
import json
import logging
logging.basicConfig(
    stream=sys.stdout,
    level=logging.DEBUG,
    format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")

import time
from db import insert_ticks
from kiteconnect import WebSocket

# Initialise.
kws = WebSocket("api_key", "public_token", "zerodha_user_id")

# RELIANCE BSE, RELIANCE NSE, NIFTY 50, SENSEX
tokens = [128083204, 73856, 256265, 265]


# Callback for tick reception.
def on_tick(ticks, ws):
    logging.info("on tick - {}".format(json.dumps(ticks)))
    insert_ticks.delay(ticks)


# Callback for successful connection.
def on_connect(ws):
    logging.info("Successfully connected to WebSocket")


def on_close():
Esempio n. 5
0
from kiteconnect import WebSocket

from bot import db, util
from bot.util import logger
from web import nse, edelweiss

kws = WebSocket(api_key="9oykkw4mc01lm5jf",
                public_token="V3mTjh6XbVQk3171IoWsn863qZsmBsDL",
                user_id="RT1384")

SUNTVJAN = 12055042
CGPOWERFEB = 14649602
CGPOWERJAN = 11968258

FUTURES = ('25JAN2018', '22FEB2018', '28MAR2018')

symbolmap = {
    "CGPOWER JAN": CGPOWERJAN,
    "CGPOWER FEB": CGPOWERFEB,
    "SUNTV JAN": SUNTVJAN
}

equityurl = 'https://www.nseindia.com/live_market/dynaContent/live_watch/get_quote/GetQuote.jsp?symbol='
futureurl = 'https://www.nseindia.com/live_market/dynaContent/live_watch/get_quote/GetQuoteFO.jsp?instrument=FUTSTK&expiry=%s&underlying=%s'


def geturl(symbol):
    symbolandexpiry = symbol.partition(' ')
    url = equityurl + symbol
    # if symbolandexpiry[2]:
    #     url = futureurl % (getexpiry(symbolandexpiry[2]), symbolandexpiry[0])
Esempio n. 6
0
import sys

from kiteconnect import WebSocket
from pydblite.pydblite import Base

from constants import *
from readinstrument import MyTrade
import persist_last_value

api_key = os.getenv("API_KEY")
token = os.getenv("PUB_TOKEN")
user = os.getenv("USER_ID")
# Initialise.
# kws = WebSocket("your_api_key", "your_public_token", "logged_in_user_id")
# kws = WebSocket(api_key, token, user)
kws = WebSocket("lzxojcmp16le5ep8", "9dd813876abe0c06dfca066221f5d1da", "DD1846")

# Initialize DB.

db = Base(db_name, sqlite_compat=True)
if db.exists():
    db.open()
else:
    db.create('time', 'instrument_token', 'last_price', 'mode', 'tradeable')



# Save Initial Time
now = datetime.datetime.now()
tmp_filename = PREVIOUS_TIME+str(int(time.time()))
persist_last_value.save_object(tmp_filename, now)
Esempio n. 7
0
kite_api_key = "yw8yelu5bpfel8ib"
kite_api_secret = "vaddqe1qb3lzorst3uolc1ptdo0l2cku"

logging.basicConfig(level=logging.DEBUG)

kite = KiteConnect(api_key="yw8yelu5bpfel8ib", proxies=r_proxy)

rq = kite.request_access_token("sulTUnrQxqYumZGVmOgXzWcCTxAaRbnc",
                               "vaddqe1qb3lzorst3uolc1ptdo0l2cku")

kite.set_access_token(rq['access_token'])

kite.ohlc("NSE:INFY")

#kite.set_access_token('xjsfx1mymtr3j340g2u4hhy1sshrtl6d')
kws = WebSocket(kite_api_key, 'Kf879HRiMNS0DbOREhO1KyDqRl3J2bWu', "YK8879")


def on_ticks(tick, ws):
    # Callback to receive ticks.
    #logging.debug("Ticks: {}".format(ticks))
    print(tick)


def on_connect(ws):
    # Callback on successful connect.
    # Subscribe to a list of instrument_tokens (RELIANCE and ACC here).
    ws.subscribe([738561, 5633])

    # Set RELIANCE to tick in `full` mode.
    ws.set_mode(ws.MODE_FULL, [738561])