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

    • Total Topics
      21,176
    • Total Posts
      90,698
    • Total Members
      41,282
    • Most Online
      7,522
      10/06/21 10:53

    Newest Member
    CFDBandit
    Joined 29/01/23 03:20
  • Posts

    • Capital, win loss ratio. If you have a trading edge and you can consistently win 50% of your trades, so your winning 5 trades out of 10. So if your risking 1% of your capital per trade, out of your 10 trades 5 would be losers, so that’s 5% loss and realistically out of the 5 winning trades, some would make small profits, some break even and 1, 2 or 3 could run nicely IF you can let your profits run, basically your making money out of 2 trades out of the 10 trades (80/20 Rule Pareto principle) So a $20,000 acct risking 1% is $200 per trade, this will keep the trader with his trade risk based on being able to win 50% of his trades. A long term trend trader can win with 30% wining trade. Basically you need to know your numbers. Rgds Pete
    • Investing in stocks can be a great way to grow your wealth over time. However, there are different approaches that investors can take when choosing which stocks to buy. Two of the most popular approaches are growth investing and value investing. Growth Investing Growth investing is an investment strategy that focuses on buying stocks of companies that are expected to grow at a faster rate than the overall market. These companies are often in industries that are growing quickly, such as technology or healthcare. Investors who use this approach believe that these companies will be able to generate higher profits in the future, which will lead to higher stock prices. One of the main advantages of growth investing is that it can potentially provide higher returns than the overall market. However, it is also riskier than other investment strategies, as these companies often have higher valuations and more volatile stock prices. Value Investing Value investing is an investment strategy that focuses on buying stocks of companies that are undervalued by the market. These companies may be in industries that are out of favour or have recently experienced challenges, but they have strong fundamentals and a history of profitability. Investors who use this approach believe that these companies are undervalued and that their true value will be recognized in the future, leading to higher stock prices. One of the main advantages of value investing is that it can potentially provide lower risk than growth investing. However, it may also provide lower returns in the long run, as these companies may not have the same growth potential as companies in the growth investing category. Comparing Growth and Value Investing Growth and value investing are two different approaches to stock investing, each with its own advantages and disadvantages. Growth investing can potentially provide higher returns but is riskier, while value investing can provide lower risk but potentially lower returns. An investor may choose one approach or a combination of both. A portfolio that contains a mix of growth and value stocks can provide a balance of potential returns and risk. Conclusion Both growth investing and value investing can be effective ways to invest in stocks. The key is to understand the potential risks and rewards of each approach and to choose the one that aligns with your investment goals and risk tolerance. Analyst Peter Mathers TradingLounge™ 
    • I am a beginner, and I must say, there are a lot of rules to the trading game that one must abide by if they want to be successful.   Here, the writer mentions several basic rules for day vs swing trading.  However, I find that often times, the reasoning for these rules is not as  obvious for a beginner as it may be for an expert.   The 'why' factor if I may. For example, why must you have a large capital to trade with as a day trader? Because your positions must be large so that a small change in price will be augmented and turned into a large profit. Also, with such high risk, the margin will be specially high, given the trader is taking up large positions at a time.  Without a large amount of capital, positions may be forced to close due to funds being below margin requirements.  When this happens, you can expect to lose tons of cash, fast.  I learned the hard way. All the best, David Franco      
×
×
  • Create New...