Jump to content
  • 0

Level not working in API limit order


wki

Question

Hi, I am trying to do a trade through the API (either Python or the API Companion).  I can do a MARKET trade successfully but now I want to do a LIMIT trade, where the trade is executed when a specific price point is reached but I cannot get this to work. I can place the limit order with the level through the IG Trading Dashboard though. Through the API, the LEVEL seems to be completely ignored and so it bypasses the limit and goes straight to market. Here is my Python script for GBPUSD:

epic = "CS.D.GBPUSD.TODAY.IP"
direction = "BUY"
stopDistance = 15
limitDistance = 15
size = 0.5
level = 13130 #(current price is 13125)
expiry="DBF"
orderType="LIMIT"
guaranteedStop=False
stopLevel=None
trailingStopIncrement=None
trailingStop=False
forceOpen=True
limitLevel=None
quoteId=None
currencyCode="GBP"

response = ig_service.create_open_position(currencyCode, direction, epic,
                            expiry, forceOpen, guaranteedStop, level, limitDistance,
                            limitLevel, orderType, quoteId, size, stopDistance, stopLevel,
                            trailingStop, trailingStopIncrement, None)

 
Edited by wki
Link to comment

6 answers to this question

Recommended Posts

  • 1
7 hours ago, wki said:

Can you get the API Companion working for a limit resting order with a level, the same as what is possible through the main UI dashboard (see attached)?  Thanks again for your help!

Hi, the picture helped. Now I understand what you are trying to do. You are pointing your code to the wrong endpoint, you don't need the Open Position Request, you need the Create Working Order Request.

Quote

Endpoint: /gateway/deal/workingorders/otc

The type of order that you are looking for is a Resting Working Order, the API companion has a menu option for it. It is at "Trading Working Orders"

https://labs.ig.com/rest-trading-api-reference/service-detail?id=533

I sent a test to get the json parameters, here is the request:

Quote

{
    "epic": "CS.D.GBPUSD.TODAY.IP",
    "expiry": "DFB",
    "direction": "BUY",
    "size": "0.5",
    "level": "13300",
    "forceOpen": "true",
    "type": "LIMIT",
    "currencyCode": "GBP",
    "timeInForce": "GOOD_TILL_CANCELLED",
    "goodTillDate": null,
    "guaranteedStop": "false",
    "stopLevel": null,
    "stopDistance": null,
    "limitLevel": null,
    "limitDistance": null
}

You can amend stop and limit levels to match your picture.

That gets a response with a deal reference. Querying the "Trade Confirm" endpoint that we discussed earlier you will get a response like:

Quote

{
    "date": "2020-08-29T04:54:56.582",
    "status": "OPEN",
    "reason": "SUCCESS",
    "dealStatus": "ACCEPTED",
    "epic": "CS.D.GBPUSD.TODAY.IP",
    "expiry": "DFB",
    "dealReference": "L2LEBWUUNQN44S3",
    "dealId": "DIAAAAEASUXMMA3",
    "affectedDeals": [{
        "dealId": "DIAAAAEASUXMMA3",
        "status": "OPENED"
    }],
    "level": 13300.0,
    "size": 0.5,
    "direction": "BUY",
    "stopLevel": null,
    "limitLevel": null,
    "stopDistance": null,
    "limitDistance": null,
    "guaranteedStop": false,
    "trailingStop": false,
    "profit": null,
    "profitCurrency": null
}

 

  • Sad 1
Link to comment
  • 0

Hi, thanks @jlzfor your reply but I can't see anything in your C# code that indicates where I have gone wrong.  As mentioned, I can't even get this working via the API Companion, let alone through Python.  I'll contact IG directly. 👍

Link to comment
  • 0
38 minutes ago, wki said:

Hi, thanks @jlzfor your reply but I can't see anything in your C# code that indicates where I have gone wrong.  As mentioned, I can't even get this working via the API Companion, let alone through Python.  I'll contact IG directly. 👍

When you send a Create Position Request you always get a deal reference as a result.

If the request didn't go through you can query the "Trade Confirm" endpoint with that reference.

This is a result from a wrong request that I sent as a test:

    "date": "2020-08-28T16:56:11.906",
    "status": null,
    "reason": "LIMIT_ORDER_WRONG_SIDE_OF_MARKET",
    "dealStatus": "REJECTED",
    "epic": "IX.D.FTSE.DAILY.IP",
    "expiry": null,
    "dealReference": "RBHDM9LUQYU44S3",
    "dealId": "DIAAAAEASE5RTA3",
    "affectedDeals": [],
    "level": null,
    "size": null,
    "direction": "BUY",
    "stopLevel": null,
    "limitLevel": null,
    "stopDistance": null,
    "limitDistance": null,
    "guaranteedStop": false,
    "trailingStop": false,
    "profit": null,
    "profitCurrency": null
}
  • Sad 1
Link to comment
  • 0

Hi, thanks again for your response and top tip. I am indeed getting the "LIMIT_ORDER_WRONG_SIDE_OF_MARKET" error. I have realised that I am looking to do a resting order as opposed to an immediate order as explained here: https://labs.ig.com/apiorders

Can you get the API Companion working for a limit resting order with a level, the same as what is possible through the main UI dashboard (see attached)?  Thanks again for your help!

IG.jpg

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

    • Elliott Wave Analysis TradingLounge Daily Chart, Polkadot/ U.S. dollar(DOTUSD) DOTUSD Elliott Wave Technical Analysis Function: Counter Trend Mode: Corrective Structure: Flat Position: Wave C Direction Next higher Degrees: wave (II) of Impulse Wave Cancel invalid level: Details: Wave II Is equal to 61.8% of Wave I at 5.225 Polkadot/ U.S. dollar(DOTUSD)Trading Strategy: Polkadot overall is still in the period of correction. In the position of wave (II) with a double corrective pattern, the view is therefore for a short-term pullback before rising again in wave (III), waiting for the correction to complete to rejoin the uptrend. Polkadot/ U.S. dollar(DOTUSD)Technical Indicators: The price is below the MA200 indicating a downtrend, The Wave Oscillator is a Bearish Momentum. Elliott Wave Analysis TradingLounge H4 Chart, Polkadot/ U.S. dollar(DOTUSD) DOTUSD Elliott Wave Technical Analysis Function: Counter Trend Mode: Corrective Structure: Flat Position: Wave C Direction Next higher Degrees: wave (II) of Impulse Wave Cancel invalid level: Details: Wave II Is equal to 61.8% of Wave I at 5.225 Polkadot/ U.S. dollar(DOTUSD)Trading Strategy: Polkadot overall is still in the period of correction. In the position of wave (II) with a double corrective pattern, the view is therefore for a short-term pullback before rising again in wave (III), waiting for the correction to complete to rejoin the uptrend. Polkadot/ U.S. dollar(DOTUSD)Technical Indicators: The price is below the MA200 indicating a downtrend, The Wave Oscillator is a Bearish Momentum.       Technical Analyst : Kittiampon Somboonsod Source : Tradinglounge.com get trial here!  
    • Commodities Market Update: Discover the latest trends and strategies for trading in the futures market with a focus on Elliott Wave analysis. Learn about bond yields, USD DXY, and key commodity prices such as gold, silver, copper, iron ore, lithium, uranium, nickel, crude oil, and natural gas. Stay informed and make informed trades with our in-depth market summary and expert trading recommendations. Commodity Market Elliott Wave Update: - Bitcoin: Wave 2 low in place, awaiting confirmation. Support at 65k. - US Dollar: Awaiting more price action. Bonds expected to move higher, yields to lower. - Gold, GDX, and Silver: Possible lows in place, requires confirmation. Silver is looking more positive. - Base Metals: Copper approaching Wave 4 low. - Natural Gas: Wave b) of 4 correction lower. Video Chapters: 00:00 - Bitcoin (BTC) and Ether (ETH/USD)   07:28 - US Dollar Index (DXY) / TLT Bonds / US Gov Bonds 10 Yr Yields   16:51 - Precious Metals: Spot Gold (XAU) / GDX ETF / US Spot Silver (XAG)   27:10 - Base Metals: Uranium (URA ETF) / Copper   29:55 - Energy: Crude Oil (WTI OIL) / Natural Gas (NG)   32:27 - End   Analyst: Peter Mathers, TradingLounge  
    • The cryptocurrency world is being transformed by AI, making investing and asset management easier and more secure. Projects like Fetch.ai, Ocean Protocol, and SingularityNET use AI to analyze market data and predict trends, empowering investors with smart decisions. ROGin AI exemplifies this by providing market analysis and portfolio management tools, automating tasks to save time and reduce errors. AI also boosts security by detecting fraud on crypto platforms. ROGin AI's unique features include social learning and NFT integration, allowing investors to collaborate, get trading advice, and protect their strategies as NFTs. What excites you about AI in crypto? Have you tried any AI-powered crypto projects? What features would you like to see on platforms like ROGin AI?
×
×
  • Create New...
us