Results 1 to 7 of 7
  1. #1

    Trying to raise a subscription with IG but keep getting errors

    I am probably missing something very basic here, but using the following code, I can connect to the IG Streaming service but when I try and raise a subscription, I just get "Subscription error". No more information as to what is going on than that. I've tried to attach some logging but it doesn't really provide any insight.

    Would anyone be able to tell me what I have failed to do here?

    from lightstreamer_client import *


    # I've borrowed this listerner code and stuck some random print statements in. Nothing ever seems to get called from this listerner which is interesting.
    class SubListener:
    def onItemUpdate(self, update):
    print("{stock_name:<19}: Last{last_price:>6} - Time {time:<8} - "
    "Bid {bid:>5} - Ask {ask:>5}".format(
    stock_name=update.getValue("stock_name"),
    last_price=update.getValue("last_price"),
    time=update.getValue("time"),
    bid=update.getValue("bid"),
    ask=update.getValue("ask")))
    pass
    def onClearSnapshot(self, itemName, itemPos):
    pass
    def onCommandSecondLevelItemLostUpdates(self, lostUpdates, key):
    pass
    def onCommandSecondLevelSubscriptionError(self, code, message, key):
    pass
    def onEndOfSnapshot(self, itemName, itemPos):
    pass
    def onItemLostUpdates(self, itemName, itemPos, lostUpdates):
    pass
    def onListenEnd(self):
    pass
    def onListenStart(self):
    pass
    def onSubscription(self):
    print("hello")
    pass
    def onSubscriptionError(self, code, message):
    print("There has been some kind of error")
    print(code)
    print(message)
    pass
    def onUnsubscription(self):
    pass
    def onRealMaxFrequency(self, frequency):
    pass




    #Import the various settings - This all seems to work
    client = LightstreamerClient(spread_bet_account, password, streamurl)


    #If I use these settings on IG streaming companion, they all work
    subscription_data = LightstreamerSubscription("MERGE", "MARKET:IX.D.FTSE.CFD.IP", "BID", "QUOTE_ADAPTER")

    #create the listerner
    hearme = SubListener

    #attach the listerner to the subscription ask
    subscription_data.addlistener(hearme)

    #Connect to the server which the logging says is sucessful
    client.connect()

    #and then errors when I call this
    client.subscribe(subscription_data)

  2. #2
    It seems there might be a misunderstanding in the way the Lightstreamer Client API is being used.
    To ensure the API is used correctly, I recommend reviewing the parameters passed to the class constructors against the official documentation.
    This will help clarify the expected number of parameters and their intended use, leading to more effective integration of the Lightstreamer Client.

  3. #3
    Thanks for the pointer. I realised the main error in what I was doing shortly after I posted, which was I wasn’t passing tuples into the subscription command.

    That has moved me on to the next error which seems to be that the import command does not bring in custom variable types that the API documentation assumes are there.

    Not sure if it is me being silly or whether the documentation is for an older version of the code.

    For example the documention says you should create a subscription via the following

    sub = Subscription("MERGE",["item1","item2","item3"],["stock_name","last_price"])

    but that doesn’t work, as Subscription variable isn’t recognised and I find I have to do this;

    subscription_data = LightstreamerSubscription("MERGE", ['MARKET:IX.D.FTSE.CFD.IP'], ['BID'])

    Now I have a similar issue with listeners;

    class SubListener(SubscriptionListener):
    def onItemUpdate(self, update):
    print("UPDATE " + update.getValue("stock_name") + " " + update.getValue("last_price"))

    SubscriptionListener isn’t defined anywhere so you can’t pass it as a variable into the class.

    If you remove subscription listener from the class, you can run it and assign it, but then every time some data is passed back, the code falls over.

    What am I missing?

  4. #4
    Could you try running the example provided in the quickstart guide?

  5. #5
    I’ve tried, but it doesn’t work, everything in the example is nearly right but not quiet right.

    In the example is says

    from lightstreamer.client import *

    That doesn’t work, it needs

    from lightstreamer_client import *

    In the example,

    sub = Subscription("MERGE",["item1","item2","item3"],["stock_name","last_price"])

    It errors because Subscription is not defined.

    I get round it using

    subscription_data = LightstreamerSubscription("MERGE", ['MARKET:IX.D.FTSE.CFD.IP'], ['BID'])

    etc etc.

    Hence I wonder if the example is written on a very old version of the code.

  6. #6
    I assure that the example is right.
    If you run the command pip list, can you see the library lightstreamer-client-lib 2.1.0?

  7. #7
    HA! Thank you very much. Seems to be an Anaconda issue. Despite it telling me I had the latest version, it was in fact 0.1!! Hence to documentation making no sense. I have just used pip to pull in 2.1 and now the example code works. So it was the wrong documentation, but because the implementation was very old! You help is much appreciated! - Now to go and correct all my code (ARRRRR)

 

 

Similar Threads

  1. Getting exceptions on initial subscription request
    By shirli_om2 in forum Adapter SDKs
    Replies: 1
    Last Post: March 16th, 2023, 02:15 PM
  2. Replies: 5
    Last Post: December 23rd, 2010, 08:34 AM
  3. Getting time out on initial subscription request
    By PeterHiross in forum Adapter SDKs
    Replies: 4
    Last Post: December 20th, 2010, 08:36 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT +1. The time now is 02:39 PM.