Errors while subscribing to instruments

kapilaggr
Hi All,

I want to get the ticks of only four instruments.When I add these 4 instruments to a list and provide this list as an argument to the subscribe function,my code works fine.

In real time, I have these instrument ids in a row in an excel file.I am reading that excel as a data frame and then adding these 4 instrument ids(from the data frame) to a list and then passing this list as an argument to the subscribe function.My code does not work when I do this.I am not getting any ticks.I only get the error message-"Connection closed: 1006 - connection was closed uncleanly (I dropped the WebSocket TCP connection: close reason without close code)".

Please help
  • sujith
    Can you paste your complete code and the stack trace here?
  • kapilaggr
    Hi Sujith,

    Please find-

    all_pairs = pd.read_excel('C:\Kapil\Python\Final-1\Code2_Input.xlsx')
    inst_token = [all_pairs.at[0,'instrument1'],all_pairs.at[0,'instrument2'],all_pairs.at[0,'instrument1_cash'],all_pairs.at[0,'instrument2_cash']]
    print(inst_token)

    def on_connect(ws, response):
    ws.subscribe(inst_token)
    ws.set_mode(ws.MODE_FULL, inst_token)


    def on_ticks(ws, ticks):
    l=len(ticks)
    for k in range(0,l):
    if (ticks[k]['instrument_token'] == all_pairs.at[0,'instrument1']):
    symbol1_price = ticks[k]['last_price']
    elif (ticks[k]['instrument_token'] == all_pairs.at[0,'instrument2']):
    symbol2_price = ticks[k]['last_price']
    elif (ticks[k]['instrument_token'] == all_pairs.at[0, 'instrument1_cash']):
    symbol1_cash_price = ticks[k]['last_price']
    elif (ticks[k]['instrument_token'] == all_pairs.at[0, 'instrument2_cash']):
    symbol2_cash_price = ticks[k]['last_price']


    When I run this,I am getting the following output-

    [12690946, 12709122, 1510401, 1270529]
    Connection error: 1006 - connection was closed uncleanly (I dropped the WebSocket TCP connection: close reason without close code)
    Connection closed: 1006 - connection was closed uncleanly (I dropped the WebSocket TCP connection: close reason without close code)
    Connection error: 1006 - connection was closed uncleanly (I dropped the WebSocket TCP connection: close reason without close code)
    Connection closed: 1006 - connection was closed uncleanly (I dropped the WebSocket TCP connection: close reason without close code)
    Connection error: 1006 - connection was closed uncleanly (I dropped the WebSocket TCP connection: close reason without close code)
    Connection closed: 1006 - connection was closed uncleanly (I dropped the WebSocket TCP connection: close reason without close code)
    Connection error: 1006 - connection was closed uncleanly (I dropped the WebSocket TCP connection: close reason without close code)
    Connection closed: 1006 - connection was closed uncleanly (I dropped the WebSocket TCP connection: close reason without close code)


    When I hard code this instrument ids in the code,it works fine.

  • rakeshr
    @kapilaggr
    You seems to be blocking on_ticks thread. You need to pass on all computations inlcuding condition statements to a different thread, without blocking on_tick method.You can check example here.
Sign In or Register to comment.