Jump to content

ManpreetWV

Community Member
  • Posts

    4
  • Joined

  • Last visited

Posts posted by ManpreetWV

  1. Quote

    $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);


    $id="DIAAAAKF225EXAL";
    $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);
    print"$result";

    above is my code, I get:

    {"errorCode":"invalid.request.trailingStopDistance"}

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

    why the errror?

×
×
  • Create New...
us