Jump to content
  • 0

InvalidHeader error for creating working order through trading_ig api

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 😉 ). 

 

Share this post


Link to post

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

 

 

  • Sad 1

Share this post


Link to post
  • 0

I just realised that the "orderType"is a variable and is not a parameter, ignore that line about "type" :D , the rest still applies 

  • Sad 1

Share this post


Link to post
  • 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)

Share this post


Link to post
  • 0

I always develop my own libraries so I don't have to deal with others' bugs.

Where did you get that library? Let me clone it and see how the headers are being set up there.

Is there any github I can clone to test it?

  • Sad 1

Share this post


Link to post
  • 0

I got it! It was a pesky little VERSION= 2 instead of VERSION = "2" under the """Updates an OTC working order""". I'll log a bug. Seems to be working now, thanks!

Share this post


Link to post
  • 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.

  • Sad 1

Share this post


Link to post
  • 0

That's great feedback, cheers. Will struggle to find the time to move over from Python to C# but will keep that in mind, especially if the wheels keep coming off with the Python libraries.

Share this post


Link to post

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
You are posting as a guest. If you have an account, please sign in.
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×