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

    • Staking to receive hourly rewards on Bitget PoolX is a less risky way of earning with the volatility attached to crypto trading
    • While the volatility of the crypto space is always a factor, the eternal quest to earn is ever present. This in part, means that, even after earning, we will want to make the earnings earn more. To do this however, requires an insight into the earning mechanisms at our disposal and correctly picking the best ones will transform idle assets into a productive investment. In a recent analysis of the staking rates across the crypto market, Bitget's PoolX platform offers the highest returns among similar flexible savings accounts from Huobi, OKEX, and Bybit. Especially lucrative for ETH, PoolX boasts an impressive APR of up to 28.61%. Users can stake BGB, USDT, BTC, or ETH to receive free airdrops of popular tokens daily, with rewards distributed hourly and available for immediate withdrawal. If staking ever comes to mind, you could leverage analysis like these to enjoy some of the highest returns available in the crypto market today. PS: Let me know in the comment section if there are better options elsewhere!
    • Bit Starz, a leading online casino known for its extensive selection of slots and table games, is offering an exciting promotion in 2024. By using the promo code “hella”, players can receive a generous 240 free spins, providing ample opportunities to win big on popular slot games. Overview of Bit Starz: Bit Starz is renowned for its wide variety of high-quality casino games, including slots, table games, and live dealer options. The platform is praised for its user-friendly interface, fast withdrawal times, and excellent customer support. Bit Starz accepts multiple currencies, including cryptocurrencies, making it a versatile choice for players worldwide. Promo Code and Bonus: Promo Code: hella Bonus: 240 free spins How to Use the Promo Code: Visit Bit Starz: Open your web browser and go to the Bit Starz website. Sign Up or Log In: If you are a new user, click on the “Sign Up” button to create a new account. You will need to provide your email, create a username, and set a password. If you already have an account, click on the “Log In” button and enter your credentials to access your account. Navigate to the Promotions Section: Once logged in, go to the promotions or bonuses section of your account. Enter the Promo Code: In the promo code field, type “hella” and click on the “Submit” or “Redeem” button. Claim Your Free Spins: After entering the code, you will instantly receive 240 free spins. These spins can be used on selected slot games available on Bit Starz. Benefits of the Promotion: The 240 free spins offer a significant advantage to both new and existing players. Free spins allow players to try out various slot games without risking their own money. This bonus can lead to substantial winnings, enhancing the overall gaming experience. Tips for Maximizing Your Bonus: Explore Different Games: Use your free spins to try different slot games on the platform. This helps in discovering which games you enjoy the most and where you have the best chances of winning. Check Game Contributions: Some games contribute more to wagering requirements than others. Make sure to play games that count significantly towards fulfilling these requirements. Stay Informed: Regularly check the promotions page for additional offers that can further boost your balance or provide extra rewards. By following these steps and using the promo code “hella”, you can maximize your gaming experience on Bit Starz. Enjoy the excitement and potential winnings with this generous 240 free spins bonus in 2024.
×
×
  • Create New...
us