Jump to content
  • 0

InvalidHeader error for creating working order through trading_ig api


wki

Question

Hi, trying to create a new working order with a trigger level going through the Python trading_ig API.

currencyCode = 'GBP'
direction = 'BUY'
epic = 'CS.D.BITCOIN.TODAY.IP'
expiry = 'DFB'
forceOpen = True
guaranteedStop = True
level = str(11450)
limitDistance = str(150)
timeInForce='GOOD_TILL_CANCELLED'
limitLevel = None
orderType = 'LIMIT'
quoteId = None
size = str(1)
stopDistance = str(150)
stopLevel = None
goodTillDate = str(datetime(year = 2020, month = 9, day = 3, hour = 18, minute = 0))

response = ig_service.create_working_order(currencyCode, direction, epic,
        expiry, guaranteedStop, level, size, timeInForce, orderType, limitDistance, limitLevel, 
        stopDistance, stopLevel, goodTillDate, quoteId, forceOpen, None)

However, getting a "InvalidHeader: Value for header {VERSION: 2} must be of type str or bytes, not <class 'int'>" error.  Tried various permutations on the string values, have a feeling that the problem lies elsewhere (pebkac most likely 😉 ). 

 

Link to comment

8 answers to this question

Recommended Posts

  • 0

You have two parameters that conflict with each other, "timeInForce" and "goodTillDate".

Change the "orderType" parameter to "type"

I moved what I had in C# to Python in this repo, so it is easier to point things out:

https://github.com/oneangrytrader/brokerapiclients/blob/master/IG.Python.Api.Client/tests/TestIgClientWorkingOrders.py

Within the test you can see the parameters that I am using. The test uses GBPUSD with a limit and a stop of 100 away from the initial level.

image.thumb.png.c5f88d765fc0a0aebc7d50a2529ce9a0.png

 

 

  • Like 1
  • Sad 1
Link to comment
  • 0

Thanks again for your help @jlzbut still struggling. I reverted back to the basic create_open_position to test the connection, and start again from there, etc.  So this works: 

response = ig_service.create_open_position(
    currency_code='GBP', 
    direction='BUY', 
    epic='CS.D.BITCOIN.TODAY.IP',
    expiry='DFB', 
    force_open=True, 
    guaranteed_stop=False, 
    level=None, 
    limit_distance='150', 
    limit_level=None, 
    order_type='MARKET', 
    quote_id=None, 
    size='1', 
    stop_distance='150', 
    stop_level=None,
    trailing_stop=False, 
    trailing_stop_increment=None)

But this does not (same InvalidHeader error as original post):

response = ig_service.create_working_order(
    currency_code='GBP', 
    direction='BUY', 
    epic='CS.D.BITCOIN.TODAY.IP',
    expiry='DFB', 
    force_open=True,
    time_in_force = 'GOOD_TILL_CANCELLED',
    good_till_date=None,
    guaranteed_stop=False, 
    level='10800', 
    limit_distance='150', 
    limit_level=None, 
    order_type='LIMIT', 
    deal_reference=None, 
    size='1', 
    stop_distance='150', 
    stop_level=None)

Link to comment
  • 0

ahh, that is why I don´t like weak-typed languages. C# would have spotted that error in the fist run.

Also looking at the repo you sent, it seems that the streaming API has many errors and there are pending pull requests to be completed. The C# library works without any problem so you might want to have a look at it and give up Python.

  • Like 1
  • Sad 1
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

    • The cat and dog memes have really come a long way, and lots of people relate to this project. $CATE caught my eye when I saw its listing on Bitget, and so far, the price trend is good currently looking for a entry
    • Is very obvious that dogs and cats are the best friend to human considering these are the most prominent meme communities in the crypto space. Well toad, rabbit, ****, bull etc all tried but Cats and Dogs meme remain top community. The love for this two can be traced to the pioneering pet of Atsuko Sato (Cat and Dog), the dogs inspired Shiba inu and doge.   Now, the Cats meme communities are pushing for the exposure of “Cate” known as the Kabosu Mama. They believe that CATE isn’t just any cat but a legendary meme feline that has been the best friend to the famous $DOGE and now extends a paw of friendship to $NEIRO.   Currently, $CATE is trending after many top exchanges listed the meme.  I wonder if this might be the next doge or shiba but considering its tokenomic and total supply I think is worthy to add to watchlist. Also considering this is related to the Sato family will it become the top cat community meme?        
    • Bitcoin (BTC), the world’s oldest and most valued cryptocurrency, remained steady around the $58,000 mark over the weekend. This stability comes as a contrast to other popular altcoins like Ethereum (ETH), Dogecoin (DOGE), Solana (SOL), Ripple (XRP), and Litecoin (LTC), which all experienced declines. The Market Fear & Greed Index reflected this sentiment, standing at 39 out of 100, indicating a state of "Fear" in the market. Among the altcoins, Nervos Network (CKB) emerged as the biggest gainer with a 5% increase over the past 24 hours. On the other hand, Bittensor (TAO) saw the steepest decline, with a 9% drop in the same period. What to Expect from the September Fed Meeting Fed Meeting Overview The US Federal Reserve’s meeting on September 17-18 is expected to announce an interest rate cut on September 18. The market predicts a higher chance of a 50 basis points (bps) cut compared to a 25 bps cut. Data from CME FedWatch and Polymarket shows a strong likelihood for a 50 bps reduction. Historical Context This will be the first rate cut since March 2020. Previous rate cuts have historically benefited Bitcoin, as seen with the 2021 bull run. Potential Impact on Bitcoin Short-Term Outlook Doctor Profit, a crypto analyst, warns of potential short-term declines in Bitcoin if the Fed announces a rate cut. Market uncertainties, like geopolitical issues, could increase volatility. He advises careful risk management during this period. Long-Term Forecast Doctor Profit remains positive about Bitcoin’s long-term outlook. He expects Quantitative Easing (QE) to increase market liquidity, benefiting Bitcoin. Additionally, liquidity from FTX creditors in Q4 could further support Bitcoin’s price. Future Rate Cuts Citi analysts forecast a total Fed rate cut of 1.25% this year. Further rate cuts may follow the September meeting, impacting Bitcoin and the broader crypto market.
×
×
  • Create New...
us