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

    • Recently, U.S. Senator Bill Hagerty from Tennessee spoke at the Bitcoin conference, stating his efforts to push for Bitcoin-supportive legislation to promote freedom and opportunity. This year, cryptocurrency has become a key battleground in the election campaigns. It remains to be seen whether future policies on cryptocurrency will improve.
    • The digital landscape is undergoing a profound transformation as attention, once a freely given commodity, is increasingly recognized as a valuable asset. Layer3 is at the forefront of this revolution, pioneering a new economy where attention can be owned, traded, and monetized   This innovative approach empowers individuals to monetize their engagement, providing unprecedented control over personal data. Simultaneously, advertisers benefit from transparent metrics that optimize campaign performance. Content creators are presented with diverse revenue avenues beyond traditional advertising, while the overall ecosystem experiences a more equitable distribution of value.   The implications of Layer3 extend across various sectors. Social media platforms, for instance, can leverage this technology to revolutionize user engagement and monetization strategies. Tokenomics play a crucial role in driving Layer3's economy, incentivizing participation and rewarding value creation. While challenges such as data privacy and market volatility exist, the potential benefits of Layer3 are immense   Anticipation is building as its native token $L3 is on Bitget Pre-market as users await its listing on the exchange. This milestone is expected to significantly increase the token's visibility and accessibility, potentially driving substantial growth and attracting new investors. As the countdown begins, the crypto community watches with keen interest, eager to see how Layer3 will perform in this new chapter.
    • I've been exploring the world of play-to-earn gaming recently, looking for something that's not just about endless grinding but actually offers a fun and rewarding experience. OGC really stood out to me because it combines gaming with a sense of community in a unique way. OGC isn't just a game; it's a platform where you can play, earn, and even help shape its future. You're not just a player; you're part of a community with a voice. The idea of earning crypto while playing games is exciting, but what makes OGC special is its focus on community involvement. Your feedback can directly influence the development of the game, which is a big deal. I've also heard that the OGC token is available for pre-market trading on Bitget. While I'm still getting to know the platform and its features, it's definitely something to keep an eye on. Has anyone else tried OGC? What has your experience been like? I'd love to hear your thoughts and any tips you might have.
×
×
  • Create New...
us