You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi everyone , i have this error : TypeError Traceback (most recent call last)
Cell In[8], line 91
87 # Disconnecting
88 ig_stream_service.disconnect()
---> 91 main()
Cell In[8], line 44, in main()
42 ig_session = ig_stream_service.create_session()
43 # Ensure configured account is selected
---> 44 accounts = ig_session[u"accounts"]
45 for account in accounts:
46 if account[u"accountId"] == config.acc_number:
TypeError: 'NoneType' object is not subscriptable
with this code:
import time
import sys
import traceback
import logging
import os
from trading_ig import IGService, IGStreamService
from trading_ig.config import config
from trading_ig.lightstreamer import Subscription
def on_prices_update(item_update):
print(
"{stock_name:<19}: Time {UPDATE_TIME:<8} - "
"Bid {BID:>5} - Ask {OFFER:>5}".format(
stock_name=item_update["name"], **item_update["values"]
)
)
def on_account_update(balance_update):
print("balance: %s " % balance_update)
def main():
logging.basicConfig(level=logging.INFO)
ig_service = IGService(config.username, config.password, config.api_key)
ig_stream_service = IGStreamService(ig_service)
ig_session = ig_stream_service.create_session()
accounts = ig_session[u"accounts"]
for account in accounts:
if account[u"accountId"] == config.acc_number:
accountId = account[u"accountId"]
break
else:
print("Account not found: {0}".format(config.acc_number))
accountId = None
ig_stream_service.connect(accountId)
subscription_prices = Subscription(
mode="MERGE",
items=["L1:CS.D.GBPUSD.CFD.IP", "L1:CS.D.USDJPY.CFD.IP"],
fields=["UPDATE_TIME", "BID", "OFFER", "CHANGE", "MARKET_STATE"],
)
subscription_prices.addlistener(on_prices_update)
sub_key_prices = ig_stream_service.ls_client.subscribe(subscription_prices)
subscription_account = Subscription(
mode="MERGE", items=["ACCOUNT:" + accountId], fields=["AVAILABLE_CASH"],
)
subscription_account.addlistener(on_account_update)
sub_key_account = ig_stream_service.ls_client.subscribe(subscription_account)
input(
"{0:-^80}\n".format(
"HIT CR TO UNSUBSCRIBE AND DISCONNECT FROM LIGHTSTREAMER"
)
)
ig_stream_service.disconnect()
main()
I have no problem with the Rest API and i tried and works the stream companion.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi everyone , i have this error :
TypeError Traceback (most recent call last)
Cell In[8], line 91
87 # Disconnecting
88 ig_stream_service.disconnect()
---> 91 main()
Cell In[8], line 44, in main()
42 ig_session = ig_stream_service.create_session()
43 # Ensure configured account is selected
---> 44 accounts = ig_session[u"accounts"]
45 for account in accounts:
46 if account[u"accountId"] == config.acc_number:
TypeError: 'NoneType' object is not subscriptable
with this code:
I have no problem with the Rest API and i tried and works the stream companion.
Beta Was this translation helpful? Give feedback.
All reactions