websocket data issue



  • I ran my code last time a week ago it was working fine , but now its not working I am not able to find the mistake inmy websocket code , its not giving any error also. So I'm confuse , that I'm doing something wrong or its from your side please check the websocket code and reply asap.
    I'm attaching my code below.```
    code_text

    import sys
    import pandas as pd
    import numpy as np
    import os
    import time
    import pickle
    import pymongo
    from datetime import datetime
    from IPython.display import display, clear_output
    from upstox_api.api import *
    
    list1 = sys.argv[1:]
    
    symbolList = list1[:-3]
    database_name = list1[-3]
    websocket_name = list1[-2]
    tag1 = list1[-1]
    
    
    myclient = pymongo.MongoClient("mongodb://localhost:27017/")
    #myclient = pymongo.MongoClient("mongodb+srv://aaswin:aaswin123456@cluster0-bdors.gcp.mongodb.net/test?retryWrites=true&w=majority")
    
    mydb = myclient[database_name]
    
    mycol1 = mydb[websocket_name]
    mycol1.delete_many({})
    
    for i in symbolList:
        mycol3 = mydb[i+tag1]
        mycol3.delete_many({})
    
    exchange = "nse_eq"
    
    pickle_in = open("upstox.pickle", "rb")
    u = pickle.load(pickle_in)
    u.get_master_contract(exchange)
    
    
    def set_on_order_update_handler(event):
        print(event)
        mycol1.insert_one(event)
    
    
    def set_on_error_update_handler(event):
        print("set_on_error_update_handler: %s" % str(event))
    
    
    def event_handler_socket_disconnect(event):
        u.start_websocket(True)
    
    
    def event_handler_quote_update(message):
    
        # symbol , ltp , vtt , total_buy_qty , total_sell_qty , ltt
        print(message)
        mycol3 = mydb[message["symbol"]+tag1]
        mycol3.insert_one(message)
    
    def socket_example(exchange):
        print('Websocket running\n')
    
    # set_on_order_update_handler
    
        for i in symbolList:
            u.subscribe(u.get_instrument_by_symbol('NSE_EQ', i), LiveFeedType.Full)
            print(i)
            time.sleep(1)
    
        u.set_on_order_update(set_on_order_update_handler)
        u.set_on_disconnect(event_handler_socket_disconnect)
        u.set_on_error(set_on_error_update_handler)
        u.set_on_quote_update(event_handler_quote_update)
        u.start_websocket(True)
    
    
    socket_example(exchange)
    condition = threading.Condition()
    condition.acquire()
    condition.wait()


  • Whats your websocket version? Try with websocket version 0.48.0 as suggested by someone in another topic.



  • i was using 0.46.0 for past 1 year and it was working fine then



  • @excellingtrade Thanks. 0.48.0 worked for me. I do not what has happened all of a sudden what was working for more than year stopped very suddenly without any changes at my side.


Log in to reply