Jump to content
socalwill

Python client for lightstreamer

Recommended Posts

Hi there,

 

for my very limited development purposes (running scripts for download of recent prices for one single currency pair of choice and then placing a trade) I see different approaches for a simple solution of the streaming part of the API.

 

After exploring different resources in an attempt to avoid reinventing the wheel, it seems to me that a simple python client such as

 


 

which is discussed at 

 


 

would be a perfect starting point but I thought I post here before getting started:

 

Does anyone know of an implementation along the lines of the code referenced above for Cityindex?

 

Thanks so much!

 

William

Share this post


Link to post

Hi there PM!

 

I will definitely post the code once I have it working. In the meantime, I received a response on the lightstreamer forum that is a good basis to get started.

 

Here is one thing for which your input would be incredibly helpful:

 

If you have a chance, please take a look at post #24 in  http://forums.lightstreamer.com/showthread.php?4737-Python-client-for-lightstreamer .

 

Here is a copy of the two pieces of code there:

lightstreamer_client = LSClient(base_url="https://push.cityindex.com/", user="<your user name>", password="<your security token>", adapter_set="CITYINDEXSTREAMINGDEFAULTPRICES")  

and

# Making a new Subscription to "PRICES" Data Adapter  
subscription = Subscription(  
    adapter="PRICES"  
    mode="MERGE",  
    items=["AC2347"],  
    fields=["MarketId", "TickDate", "Bid", "Offer", "Price"]  
)  
  
# A simple function acting as a Subscription listener  
def on_item_update(item_update):  
    print("{MarketId}, {TickDate}, {Bid}, {Offer}, {Price}".format(**item_update["values"]))  
  
# Adding the "on_item_update" function to Subscription  
subscription.addlistener(on_item_update)  

What I had before was pretty close, but I was getting an error message because I didn't have the fields in the subscription right. Now I can connect and disconnect, but I don't see any prices printed to my screen.

 

I use the session_id of a valid session as password.

 

Should the  adapter be set to  CITYINDEXSTREAMINGDEFAULTPRICES or to STREAMINGALL?

 

Also, I changed the items value to  the market_id of EURUSD, which is 154290.

 

Thanks much for your help - I may be missing some parts of the documentation where the above questions are answered, if so, it would be great if you could provide pointers.

 

Best,

 

William

Share this post


Link to post

Hello PM,

 

I believe I am getting close. For the subscription, I am getting an error message if I choose meaningless values for adapter or mode. If I set those to PRICES and MERGE, respectively, it seems like I can subscribe and unsubscribe, but there is something that seems suspicious...I can choose some random value for item, say "mycurrencyid" and still "subscribe" and unsubscribe and get no error message. I will see if the lightstreamer forum might help with this.

 

Thanks!

Share this post


Link to post

Hi there - making progress and having fun. With the help of support from the lightstreamer side, i got both, a bare-bones command line version as well as a modified python script working for streaming data from Cityindex. Please see  http://forums.lightstreamer.com/showthread.php?4737-Python-client-for-lightstreamer/page4 .

 

Of course I have a question related to trades now as I am moving on, but I will post that on a different thread or start a new one. Thanks!

Share this post


Link to post

Hello Physcisman, Socalwill,

 

Just wondering if there was a python library available now for streaming City Index prices? Or if its best to use the Lightstreamer stock-list demo and edit it?

Share this post


Link to post

Hello Garstonman,

 

There isn't a Python library that I'm aware of unfortunately - we've not been working on one. It's probably easiest to modify / edit the Lighstreamer one and go from there.

 

Cordially,

PM!

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×