如何将命令行cURL请求转换为php?

I am trying to make a php script that will use this new site called Oanda and trade virtual money on the Forex market.

I am trying to convert this command line code in to php:

$curl -X POST -d "instrument=EUR_USD&units=1000&side=buy&type=market" https://api-fxpractice.oanda.com/v1/accounts/6531071/orders

If anyone can give source code or explain what the -X POST and the -d mean and how to convert them to php that would be awesome.

Thank you for your help!

Try the below code and if there is any authentication please include them..

POST Means the data should be passed as post request

-d Means The data you should pass in the request

//the data you should passed
$data = array(
    "instrument" => 'EUR_USD',
    "units" => "1000",
    "side" => "buy",
    "type" => "market",
);

//encode it as json to become a string
$data_string = json_encode($data);
// print_r($data_string);

$curl = curl_init('https://api-fxpractice.oanda.com/v1/accounts/6531071/orders');

curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");

//the content type(please reffer your api documentation)
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Content-Length: ' . strlen($data_string)
));

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

//set post data
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);

$result = curl_exec($curl);
curl_close($curl);//close the curl request

if ($result) {
    print_r($result); // print the response
}

Plese reffer Curl for more information