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
×
×
  • Create New...
us