Jump to content
  • 0

Level not working in API limit order

Question

Posted (edited)

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

Share this post


Link to post

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

Share this post


Link to post
  • 0

Hi, I always enter at market level, it is easier to get filled but when I exit using Limit orders I use the following parameters: It is c# but I guess you won't have much problem to understand it. 

image.png.e66b92ccf605ff9463104047913f8a0a.png

 

  • Sad 1

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
  • 0

Thank you so much! I would have been completely lost without your help. I was clearly on the wrong track, all sorted and working now.

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.


  • Member Statistics

    • Total Topics
      13,063
    • Total Posts
      66,537
    • Total Members
      88,811
    Newest Member
    bigslickmmt
    Joined 24/11/20 03:00
  • Posts

    • Everyone, it seems accepts the result of the recent  US elections, except the President and half of the GOP.  Convinced of his own meritless delusions of fraud and other voting chicanery, he now pursues a policy of obfuscation, denial of service and general spite while mad dog Giuliani and even madder Sidney Powell pursue laughable cases in various courts in the vainglorious expectation that 6 million perfectly legal votes will somehow be annulled/ cancelled and cease to  exist. This is not to be, though the only realists in the GOP are keeping their own counsel on the subject, thereby enabling the Presidents' persistent delusions. That's the problem when you believe your own propaganda, it is easy to become confused with reality. Apart from hiding rotten fish behind the radiators of the White house and carving his name on the Resolute desk, soon to be ex president Trump is doing his best to make the transition for "sleepy" Joe as difficult as he can. This includes a tacit refusal to provide more stimulus.  He has instructed Steve Munchkin to end funding for various emergency programs to the tune of $438 billion., thereby hampering the incoming Treasury secretary before he/she even walks through the door. This has rightly upset Jerome Powell who has the interest of the US economy as his overarching priority. Unfortunately, the President is unmoved by the needs of the American public as he feels they have betrayed him.  Why reward treachery? Trump is known for his heartless ardour when crushing those he deems as unworthy, which in this case is the American people as a whole, overcome as he is with nihilistic zeal.  Playing golf while ignoring a health crisis , at the same time as full denial in the face of outright defeat, does not an effective president make. Indeed, might I venture his very legacy as president and future GOP kingmaker hang very much in the balance, indeed may have been irretrievably  lost. Like Trump, lost with nowhere to go. Though he will surely be welcomed in Turkey, Russia, not to mention North Korea.  The markets really want to break higher and gap up to new ATH's but Trumps intransigence, denial (of Covid and the election results) and general spite ( no new stimulus)are causing a state of intermarket bearish divergence, with the SP and Nasdaq refusing to break into new ATHs(all time highs).  I guess we will have to wait until he is forced out come 20th Jan. 
    • Good article (new) on strategy planning and testing from Steve Burns. https://www.newtraderu.com/2020/10/25/how-to-create-backtest-and-optimize-a-trading-strategy/ "A trading strategy is the process used to enter and exit positions in a market based on quantified signals on when to buy and sell. A trading strategy will have trading plan to express a methodology that defines a trader’s return goals, risk tolerance, and time frame. A successful strategy should have an edge expressed in how trades are entered and managed to maximize gains and minimize losses."
    • (not the cost of Covid-19 but the cost of the govt's disastrous response to a virus that's no more deadly than the common flu) The REAL cost of Covid-19: RUTH SUNDERLAND's terrifying dossier exploring the full economic damage will make you ask... can we afford to keep the brakes on Britain? National debt more than £2 trillion, equivalent of year’s output by entire country  Borrowing from April to October was £170 billion higher than period in 2019  Bank of England believes unemployment rate will to peak at around 7.75 per cent https://www.dailymail.co.uk/news/article-8975765/The-true-cost-Covid-19-Read-RUTH-SUNDERLANDs-terrifying-dossier-economic-damage.html?ito=amp_twitter_share-top
×
×