Jump to content

SirNewton

Members
  • Content count

    31
  • Joined

  • Last visited

  • Days Won

    1

Reputation Activity

  1. Thanks
    SirNewton got a reaction from Physicsman in Realtime streaming data for pairs or symbols   
    Thanks Superee. Even though, I wrote my code in Python, your code was a good reference on what to do in the subscription.
    I successfully wrote everything in Python, but looking at the demo code given by Lightstreamer, I noticed that the error handling was pretty lacking.
    Those that are doing their code in Python, I suggest you do something like below:
        subscription.addlistener(on_item_update) # Adding the "on_item_update" function to Subscription    
        sub_key = lightstreamer_client.subscribe(subscription) # Registering the Subscription
        try:
            wait_for_input()        
            lightstreamer_client.unsubscribe(sub_key) # Unsubscribing from Lightstreamer by using the subscription key        
            lightstreamer_client.disconnect() # Disconnecting Lightstreamer      
            kafka_producer_obj.close()  # Close Apache Kafka
        except KeyboardInterrupt:
            lightstreamer_client.unsubscribe(sub_key)
            lightstreamer_client.disconnect()
            kafka_producer_obj.close()
            print('Manual break by user')
        except Exception as e:
            lightstreamer_client.unsubscribe(sub_key)
            lightstreamer_client.disconnect()
            kafka_producer_obj.close()
            print(e)
    You can ignore the "kafka_producer_obj.close()". I have that because, I also use Kafka and need to close the connection on that too.
     
  2. Thanks
    SirNewton got a reaction from Physicsman in Realtime streaming data for pairs or symbols   
    In the demo: https://github.com/Lightstreamer/Lightstreamer-example-StockList-client-python/blob/master/src/stock_list_demo.py
    I would also suggest changing:
    def wait_for_input():
    input("{0:-^80}\n".format("HIT CR TO UNSUBSCRIBE AND DISCONNECT FROM \
    LIGHTSTREAMER"))
    To something like this:
        def wait_for_input():
            while True: 
                try:
                    q = input("{0:-^80}\n".format("Press q than Enter to Unsubscribe and Disconnect from Lightstreamer"))
                    if q == 'q': break
                except: break
    With the way it was written originally anytime you hit Enter it would exit. This way you can press 'q' than Enter to exit. Better control.
  3. Thanks
    SirNewton got a reaction from Physicsman in List of pairs corresponding to the numbers   
    Thank you Physicsman. In python, I was doing below for conversion:
    from datetime import datetime
    dateconv = datetime.fromtimestamp(1611273600000 / 1e3)
    print(dateconv)
    I should have been doing:
    from datetime import datetime
    dateconv = datetime.utcfromtimestamp(1611273600000 / 1e3)
    print(dateconv)
×