Unable to receive CHART data

1 post / 0 new
steinic
Unable to receive CHART data

Hi, I am tring to subscribe to chart data more specifically:

mode="MERGE",
items=['CHART:CS.D.GBPUSD.TODAY.IP:SECOND'],
fields=["UPDATE_TIME","BID_OPEN"],

When I run the subscription I always get a warning message .

INFO:trading_ig.stream:Starting connection with https://demo-apd.marketdatasystems.com
WARNING:trading_ig.lightstreamer:systemd.daemon not available, no watchdog notifications will be sent.

Here is my code

#!/usr/bin/env python
#-*- coding:utf-8 -*-

"""
IG Markets Stream API sample with Python
2015 FemtoTrader
"""

import logging
from trading_ig import config

from trading_ig import (IGService, IGStreamService)

from trading_ig.lightstreamer import Subscription
import psycopg2
from datetime import datetime

conn = psycopg2.connect(conn_string)

cursor=conn.cursor()

# A simple function acting as a Subscription listener
def on_prices_update(item_update):
today=datetime.today().strftime('%Y-%m-%d')
print("price: %s " % item_update)
t=str(today)+' '+str(item_update['values']['UPDATE_TIME'])
print(t)
epic=item_update['name']
bid = item_update['values']['BID']
bid_open = item_update['values']['BID_OPEN']
ask = item_update['values']['OFFER']
days_change = item_update['values']['CHANGE']

'''
print("{stock_name:<19}: Time {UPDATE_TIME:<8} - "
"Bid {BID:>5} - Ask {OFFER:>5}".format(
stock_name=item_update["name"], **item_update["values"],
))
'''
cursor.execute("""INSERT INTO market_data values('%s','%s','%s','%s','%s')""" % (epic, t, bid, ask, days_change))
conn.commit()
#print(cursor.fetchall())

def on_account_update(balance_update):
print("balance: %s " % balance_update)

def main():
logging.basicConfig(level=logging.INFO)
# logging.basicConfig(level=logging.DEBUG)

ig_service = IGService(****)

ig_stream_service = IGStreamService(ig_service)
ig_session = ig_stream_service.create_session()
# Ensure configured account is selected
accounts = ig_session[u'accounts']
for account in accounts:
if account[u'accountId'] == '**':
accountId = account[u'accountId']
break
else:
print('Account not found: {0}'.format(acc_number='***'))
accountId = None
ig_stream_service.connect(accountId)

# Making a new Subscription in MERGE mode
subscription_prices = Subscription(
mode="MERGE",
items=['CHART:CS.D.GBPUSD.TODAY.IP:SECOND'],
fields=["UPDATE_TIME","BID_OPEN"],

#mode="MERGE",
#items=["CHART:CC.D.LCO.USS.IP:SECOND",

#],

#fields=["UPDATE_TIME", 'UTM', 'LTP_OPEN', 'LTP_CLOSE'],
)
# adapter="QUOTE_ADAPTER")

# Adding the "on_price_update" function to Subscription
subscription_prices.addlistener(on_prices_update)

# Registering the Subscription
sub_key_prices = ig_stream_service.ls_client.subscribe(subscription_prices)

# Making an other Subscription in MERGE mode
subscription_account = Subscription(
mode="MERGE",
items=['ACCOUNT:'+accountId],
fields=["AVAILABLE_CASH"],
)
# #adapter="QUOTE_ADAPTER")

# Adding the "on_balance_update" function to Subscription
subscription_account.addlistener(on_account_update)

# Registering the Subscription
sub_key_account = ig_stream_service.ls_client.subscribe(
subscription_account
)

input("{0:-^80}\n".format("HIT CR TO UNSUBSCRIBE AND DISCONNECT FROM \
LIGHTSTREAMER"))

# Disconnecting
ig_stream_service.disconnect()

if __name__ == '__main__':
main()