I'm trying to connect to IG's lightstreamer server via python to obtain candle chart data. However, I always seem to get item updates every second even though I specify that I want it every minute or every hour. This is my code:
from lightstreamer.client import *
loggerProvider = ConsoleLoggerProvider(ConsoleLogLevel.WARN)
LightstreamerClient.setLoggerProvider(loggerProvider)
ls_client = LightstreamerClient("https://demo-apd.marketdatasystems.com", None)
ls_client.connectionDetails.setUser("...")
ls_client.connectionDetails.setPassword("...")
ls_client.connect()
subscription = Subscription(
mode="MERGE",
items=["CHART:CS.D.BITCOIN.CFD.IP:1MINUTE"],
fields=["BID_CLOSE"])
subscription.addListener(SubListener())
ls_client.subscribe(subscription)
input()
ls_client.unsubscribe(subscription)
ls_client.disconnect()
class SubListener:
def onItemUpdate(self, update):
print(update.getValue("BID_CLOSE"))
The 1MINUTE
part of CHART:CS.D.BITCOIN.CFD.IP:1MINUTE
doesn't seem to affect anything.
I've tried the same item string in IG's streaming companion and I'm able to obtain updates every minute that way, but it won't work in code for some reason. Any ideas?
I believe that the label 1MINUTE in the item name indicates the duration of the time interval for the chart's candlestick aggregation; however, the updates are sent continuously. If you want to receive updates at a specific frequency, you could leverage the setRequestedMaxFrequency option of the Lightstreamer client library. To receive one update per minute, you should use something like the following:
subscription.setRequestedMaxFrequency(Decimal(1)/Decimal(60));