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

    • In the wake of a brewing conflict between the Nigerian government and Binance, cryptocurrency enthusiasts find themselves on edge, uncertain about the future of their digital investments. Rumors abound that Binance, along with other platforms, might be exacerbating the Naira's devaluation against the dollar, prompting the government to take a hard stance against the exchange. Despite longstanding allegations of wrongdoing, recent events have propelled the government to escalate its actions. The situation has escalated dramatically, with Binance's P2P platform disabled and a staggering $10 billion fine imposed for alleged illegal activities. This punitive measure, coupled with last year's $4.3 billion fine by the SEC, underscores the gravity of the situation. However, skepticism lingers regarding the astronomical sum demanded by the Nigerian government. While Binance has faced regulatory challenges in other jurisdictions, its resilience and market dominance have largely endured. Yet, the potential ramifications of losing access to a key crypto market like Nigeria cannot be ignored. Complicating matters further, the Nigerian House of Representatives has summoned Binance CEO Richard Teng, issuing a seven-day ultimatum for him to address allegations of terrorist financing and money laundering, among other charges. This development casts a shadow over the future prospects of Binance in the country. Amidst the uncertainty surrounding Binance's operations in Nigeria, users are scrambling to identify alternative platforms. While other centralized exchanges (CEX) remain operational within the country, the pressing question remains: which platform will emerge as the most dependable alternative should the situation worsen? https://punchng.com/reps-summon-binance-boss-over-alleged-terrorism-financing/
    • 2024 has been a good year for crypto traders with signs of a bullish market prevailing. For the first time in 3 years, we are witnessing BTC set a new ATH repeatedly. If you endured the prolonged bear market of the previous years, you deserve these gigantic green candles! In addition to BTC's incredible run, several alts have broken out nicely; Ai, memecoin, GameFi projects and so on have spiked. Most notably in the month of February is the run of CEX tokens. According to Foresight News, centralized exchange tokens boast of a widespread price spike in February, based on data from ICO Analytics. Standing tall amongst many is BGB with 62% increase, while ASD, BNB, and KCS witnessed gains of 45%, 33%, and 22% respectively. As a BGB holder myself who’s been holding since June 2023 at an average price of $0.45, it’s been an incredible journey. I’ve witnessed it smash its ATH over again, the latest coming in February when BGB set a new ATH of $1.15. Aside the juicy ROI, BGB usecases have been a flex for me, granting me access to exclusive events, like Launchpads where I’ve also managed mouth-watering gains from my participations. BNB had a remarkable run in the last bull cycle, sadly I missed out having sold mine for peanuts. If you said I’m stoked to right my wrong with BGB this time, you wouldn’t be far from the truth!  Which CEX token(s) are you keenly observing?
    • Look at the transaction log to see why, Most of the time it's because your stop loss is set too close. 
×
×
  • Create New...
us