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
  • General Statistics

    • Total Topics
      23,664
    • Total Posts
      97,148
    • Total Members
      44,216
    • Most Online
      7,522
      10/06/21 10:53

    Newest Member
    Phil_RP
    Joined 08/12/23 12:13
  • Posts

    • Insightful write up. Personally, I use top down analysis to mark my pivot points and i prefer to call them zones. As seen from my ETH chart below, i have been swinging the bullish ride with my top down analysis. 
    • One exchange that checks the box interms of my own requirement is bitgetglobal. The exchange is reputable for been compliant with regulations globally, its copy trading is the largest with over 100k elite traders and 540k followers, its trading fees is amongst the lowest in the industry. The one area i feel they need to improve on is their P2P. This area is lagging compared to that of Binance and Bybit.
    • Here's the next set of TIME CYCLES - I've had these dates on my charts since 2015 ish Please note this is just to show you that the markets are not random and we can TIME them - the AIM of this thread is to SHOW you that dates calculated years in advance can be significant These Time Cycles are not all of them, just the ones I wanted to show you, which are the INTERNAL cycles of a bigger Time Cycle - some will hit and some won't - REMEMBER, lots of active cycles are ALL operating at the same time Notice that there's not a TC for the 2022 high - the reason is that there was one, it's just not part of this series of TC's I'm showing you - Then when we look backwards in 2034, you'll be able to see market price action around the dates and you will KNOW these are not random dates thrown on a chart in the hope of hitting - because If you are ignore the latter dates (not yet shown) in the cycle, then you will come a cropper and when Investments are concerned that will mean LOSING lots of your money I'm still using the screenshot taken in Oct 2020 - Once we complete 2025, I'll update the chart with price data and take a screen shot from then on for the next cycles The THICK BLACK line is the mid-point of the cycle, which in the grand scheme of things "should / is expected to be" a significant LOW point when viewed back in time from 2034! - It WILL NOT be a major low, so don't expect a humungous price crash to it, it will NOT be how you are imagining it in your head right now Notice that most of those cycles are "LINKED" that's because they are the same cycle which repeats THT
×
×
  • Create New...
us