Jump to content
  • 0

Trying to update a stop loss using API, works in API but not when i code it in PHP




$headers = array(
'Content-Type: application/json; charset=UTF-8',
'Accept: application/json; charset=UTF-8',
'Version: 2',
'X-IG-API-KEY: '.$xapikey,
'CST: ' .$_SESSION['api_cst'],
'X-SECURITY-TOKEN: '.$_SESSION['api_xtoken']

$data = array("stopLevel" => "9300", "limitLevel" =>  null, "trailingStop" => " false", "trailingStopDistance" =>  null, "trailingStopIncrement" =>  null);
$data_string = json_encode($data);

$ch = curl_init('https://demo-api.ig.com/gateway/deal/positions/otc/?' . $id . '');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);

above is my code, I get:


However using the exact same header output and json output it works in the REST API.

why the errror?

Link to comment

1 answer to this question

Recommended Posts

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
    • Total Posts
    • Total Members
    • Most Online
      10/06/21 06:53

    Newest Member
    Joined 30/01/23 14:03
  • Posts

    • Trying to buy First Trust Nasdaq Cybersecurity ETF (CIBR) but the order keeps getting rejected, even with Order type = limit and expiry = Day (all  sessions).  Please advise.
    • @MongiIG How long does it take to reply to a simple question?
    • Look Ahead to 31/1/23: Big data from the US, China, Japan; PFE, XOM, AMD earnings Ahead of the Fed meeting and the key US jobs report, investors get set to digest retail sales numbers from Germany and Japan. Plus, look out for consumer-related data from China, France, and the US. Earnings see Pfizer (PFE), Exxon Mobil (XOM) and Advanced Micro Devices (AMD) hand in their Q4 report cards.   Angeline Ong | Presenter, Analyst and Content Editor, London | Publication date: Monday 30 January 2023        
  • Create New...