Jump to content
  • 0

Unable to stream Epic - Python


BCC

Question

Hi everyone,

I'm new in the "dev world" :) , and I'm working on building my own app n python. 

For the Rest API, it's OK, I can log and make what I want.

BUT, for the streaming part, I'm completely in the fog! lol

 

I downloaded the excellent "trading-ig" python module (thanks to the devs that made it 👌) but I can't stream epic price.

Here the code I use:

Quote
import logging
import time
from trading_ig import IGService, IGStreamService
from trading_ig.config import config
from trading_ig.streamer.manager import StreamingManager
#from sample.sample_utils import crypto_epics  # fx_epics, index_epics, weekend_epics


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

    ig_service = IGService(
        config.username,
        config.password,
        config.api_key,
        config.acc_type,
        config.acc_number,
    )

    ig = IGStreamService(ig_service)
    ig.create_session(version="3")
    sm = StreamingManager(ig)

    crypto_epics = ['IX.D.NASDAQ.IFD.IP']
    tickers = []
    for epic in crypto_epics:  # fx_epics, index_epics, crypto_epics
        sm.start_tick_subscription(epic)
        tickers.append(sm.ticker(epic))

    for idx in range(0, 10):
        for ticker in tickers:
            print(ticker)
        time.sleep(1)

    sm.stop_subscriptions()


if __name__ == "__main__":
    main()

 

and here the error message:

Quote

/Users/XXX/PycharmProjects/pythonProject/venv2/bin/python /Users/XXX/Library/Application Support/JetBrains/PyCharmCE2023.3/scratches/scratch_43.py 
INFO:trading_ig.rest:Creating new v3 session for user 'XXX' at 'https://demo-api.ig.com/gateway/deal'
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): demo-api.ig.com:443
DEBUG:urllib3.connectionpool:https://demo-api.ig.com:443 "POST /gateway/deal/session HTTP/1.1" 200 250
INFO:trading_ig.rest:POST '/session', resp 200
DEBUG:trading_ig.rest:Checking session status...
DEBUG:urllib3.connectionpool:https://demo-api.ig.com:443 "GET /gateway/deal/session?fetchSessionTokens=true HTTP/1.1" 200 156
INFO:trading_ig.rest:GET '/session', resp 200
INFO:trading_ig.stream:Starting connection with https://demo-apd.marketdatasystems.com
INFO:trading_ig.streamer.manager:Consumer: Running
INFO:trading_ig.streamer.manager:Waiting for ticker for 'IX.D.NASDAQ.IFD.IP'...
INFO:trading_ig.streamer.manager:Waiting for ticker for 'IX.D.NASDAQ.IFD.IP'...
INFO:trading_ig.streamer.manager:Waiting for ticker for 'IX.D.NASDAQ.IFD.IP'...
INFO:trading_ig.streamer.manager:Waiting for ticker for 'IX.D.NASDAQ.IFD.IP'...
INFO:trading_ig.streamer.manager:Waiting for ticker for 'IX.D.NASDAQ.IFD.IP'...
INFO:trading_ig.streamer.manager:Waiting for ticker for 'IX.D.NASDAQ.IFD.IP'...
INFO:trading_ig.streamer.manager:Waiting for ticker for 'IX.D.NASDAQ.IFD.IP'...
INFO:trading_ig.streamer.manager:Waiting for ticker for 'IX.D.NASDAQ.IFD.IP'...
INFO:trading_ig.streamer.manager:Waiting for ticker for 'IX.D.NASDAQ.IFD.IP'...
INFO:trading_ig.streamer.manager:Waiting for ticker for 'IX.D.NASDAQ.IFD.IP'...
INFO:trading_ig.streamer.manager:Waiting for ticker for 'IX.D.NASDAQ.IFD.IP'...
INFO:trading_ig.streamer.manager:Waiting for ticker for 'IX.D.NASDAQ.IFD.IP'...
INFO:trading_ig.streamer.manager:Waiting for ticker for 'IX.D.NASDAQ.IFD.IP'...
Traceback (most recent call last):
  File "/Users/XXX/PycharmProjects/pythonProject/venv2/lib/python3.12/site-packages/trading_ig/streamer/manager.py", line 57, in ticker
    ticker = self._tickers[epic]
             ~~~~~~~~~~~~~^^^^^^
KeyError: 'IX.D.NASDAQ.IFD.IP'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/XXX/Library/Application Support/JetBrains/PyCharmCE2023.3/scratches/scratch_43.py", line 39, in <module>
    main()
  File "/Users/XXX/Library/Application Support/JetBrains/PyCharmCE2023.3/scratches/scratch_43.py", line 28, in main
    tickers.append(sm.ticker(epic))
                   ^^^^^^^^^^^^^^^
  File "/Users/XXX/PycharmProjects/pythonProject/venv2/lib/python3.12/site-packages/trading_ig/streamer/manager.py", line 59, in ticker
    raise Exception(
Exception: No ticker found for IX.D.NASDAQ.IFD.IP after waiting 3 seconds - giving up

Process finished with exit code 1
 

 

Maybe it's a little error in the code, but I can't find it !

FYI, I tried with spreadbet and cfd epic (but my demo account is a CFD account).

Thank you for your kind answer 

 

ps: if you have some advice in coding, I take it ;)

 

 

Link to comment

9 answers to this question

Recommended Posts

  • 0
40 minutes ago, BCC said:

Hi everyone,

I'm new in the "dev world" :) , and I'm working on building my own app n python. 

For the Rest API, it's OK, I can log and make what I want.

BUT, for the streaming part, I'm completely in the fog! lol

 

I downloaded the excellent "trading-ig" python module (thanks to the devs that made it 👌) but I can't stream epic price.

Here the code I use:

 

and here the error message:

 

Maybe it's a little error in the code, but I can't find it !

FYI, I tried with spreadbet and cfd epic (but my demo account is a CFD account).

Thank you for your kind answer 

 

ps: if you have some advice in coding, I take it ;)

 

 

Dear @BCC,

Unfortunately, we do not provide coding support. However, you can use our web API companion, which can be found at https://labs.ig.com/. Additionally, some amazing people in our community may be able to assist you.

Thanks,

KoketsoIG

 

  • Like 1

Please rate us on Trustpilot: IG Trustpilot 

Link to comment
  • 0

@BCC are you logging in to a Spread bet or CFD demo account? To stream a CFD epic, you will need to log in with a CFD account. User name, password and API key will be the same as with a spreadbet account - but account ID will be different. Its the 'acc-number' param in trading-ig.

The sample works fine for me with the epic IX.D.NASDAQ.IFD.IP in a CFD demo account, but fails like your snippet when logged into a spread bet account

  • Like 2
Link to comment
  • 0

Thank you for your answer :)

 

I check, it's a CFD account :(

 

Quote
{
        "accountId": "XXXXX",
        "accountName": "CFD_API",
        "accountAlias": null,
        "status": "ENABLED",
        "accountType": "CFD",
        "preferred": true,
        "balance": {
            "balance": 1.0080652E7,
            "deposit": 414978.06,
            "profitLoss": 219826.98,
            "available": 9885501.0
        },
        "currency": "EUR",
        "canTransferFrom": true,
        "canTransferTo": true
    }

 

Link to comment
  • 0
1 hour ago, BCC said:

Thank you for your answer :)

 

I check, it's a CFD account :(

 

 

That shows the account that is logged into the REST API companion. What is important is the credentials you are using in the trading-ig library. Check the file trading_ig_config.py in your project, and make sure it is using the correct account details

Link to comment
  • 0

Hello,

 

I tried to modify the epic (CFD or Spreadbet), and it didn't work :(

I don't know if it could help, but there are some infos on my config: MacBook Air M2, IDE PyCHarm CE.

Tell me if you need more infos 👍

Link to comment
  • 0

I tried to modify the trading_ig_config.py, and I have the same message: usually I wouldn't have been able to connect ! But it was OK ! So, I think I don't modify the good file (but I don't find other file in my laptop).

I think it could be a problem with my venv in pycharm.

Can you help to make a Clean install in order to test it again ?

Thank you for your help :) 

Edited by BCC
Link to comment

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
  • image.png

  • Posts

    • What’s the average spread like, generally? How does it compare to current conditions? I’ve been using IG for over a decade, and I’ve noticed a growing sense of dissatisfaction, not just from myself but across various forums too. I think they really need to prioritize some core areas—like improving the iOS app and refining the API. While your issue may not be directly tied to the API, in theory, if you know how to use it well, it should offer a better experience compared to the web platform or the standard retail charts. Just my two cents. As for the problem, it’s definitely not about liquidity in these markets. I’d say it’s more likely due to the rise of algorithmic trading over the years. These high-speed algorithms can take advantage of price movements, often leading to short periods of slippage for regular traders as prices shift rapidly. Market orders, meant to execute quickly at the best available price, are more prone to slippage compared to limit orders. Since market orders prioritize speed, they don’t guarantee a specific price. If the market price changes in the short moment between when you place the order and when it's actually executed, your trade will go through at the new price, whether it’s better or worse than expected. This makes market orders riskier in fast-moving or volatile markets. By using the API along with a low-latency server, you can reduce the risk of slippage in some cases. What kind of latency are you experiencing with the API? Avoid using a home connection for this—opt for an affordable VPS, even a $5 one will significantly improve your experience.
    • Cardano’s 3.8% price surge might be from all the updates and partnerships they’ve been rolling out lately. I’ve noticed that every time they release some big news, like a new upgrade or collaboration, there’s always a jump in price. The community around Cardano is really strong too, which seems to play a role in driving things. A few weeks back, I swapped some tokens using https://stealthex.io , and I remember seeing a bunch of people talking about Cardano on forums. Maybe that hype is finally showing in the price. Either way, it’s nice to see some action in the market again.
    • Hi everyone, just a short post at this stage as I want to see if there is any interest in this topic first.  I’ll likely contact IG but wanted to see if there are other thoughts and experiences first as there are several issues I am seeing and it’s a bit complicated, so didn’t want to write some long rambling post. i trade the Dax and Nasdaq indices and use an automated strategy using the API.  I am effectively trying to do a trend trading strategy but on short timescales.  So i set fairly tight stops and then run those trades that leave the area to the plus side.  My win rate is low so have a lot of losers so slippage on stops is quite important to me. i have a database of trades and 5m data going back over 3years now - so have a lot of data to work with. i measured the stop slippage several years ago and it was fine for this method but have re measured it recently as I noticed the losing trades were a bit too large and it seems that the slippage has increased quite a lot for Nasdaq (not then Dax). I am trying to see what is behind this. Anyone interested or tackling similar issues? Thanks David 
×
×
  • Create New...
us