nicehash/rest-clients-demo

Please provide PHP example

undert03 opened this issue · 17 comments

Always get "errors":[{"code":2000,"message":"Invalid Session"}]

I am guessing I did not set up my sign data properly.
My OrgID matches what's in my account and the API info is set up under my Org.

Please help

PHP CODE

define('NH_API_KEY', 'XXXX' );
define('NH_API_SEC', 'XXXX' );
define('NH_ORGID',    'da41b3bc-3d0b-4226-b7ea-aee73f94a518' );
$UTCtime 		= UTC_Get_Millis();
$OrgID 			= NH_ORGID;
$Nonce			= GEN_UUIDv4();
$Method   	= 'GET';
$Path				= "/main/api/v2/mining/info";
$Query			= "";
$SigData 		= NH_API_KEY."\x00{$UTCtime}\x00{$Nonce}\x00\x00{$OrgID}\x00\x00{$Method}\x00{$Path}\x00{$Query}";
$Signature 	= hash_hmac('sha256', $SigData, NH_API_SEC );

$RequestID = GEN_UUIDv4();

$Headers = array(
	"X-Time: {$UTCtime}",
	"X-Nonce: {$Nonce}",
	"X-Organization-Id: {$OrgID}",
	"X-Request-Id: {$RequestID}",
	"X-Auth: ".NH_API_KEY.":{$Signature}",
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://api2.nicehash.com{$Path}/" );
curl_setopt($curl, CURLOPT_HTTPHEADER, $Headers );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

$result = curl_exec($curl);
if(!$result){
	die("Connection Failure");
}
curl_close($curl);
echo $result;
bl4z commented

this should work

<?php

$url_root   = "https://api-test.nicehash.com";
$org_id     = "00095760-4f2f-4b19-83d1-72ced0272976";
$api_key    = "0000f476-c39b-43fc-a62c-337e98bdcb76";
$api_secret = "000d4037-59f1-4afa-940f-d0f4dc5014f21956eeb2-3295-4bed-8e93-835ccc878d28";

//get current time
$curl = curl_init();
//curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_URL, $url_root."/api/v2/time");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);

$time = json_decode($result, true)['serverTime'];
echo "server time: ".$time."\n";

//do auth request
$nonce     = uniqid();
$path      = "/main/api/v2/mining/info";
$signature = $api_key."\x00".$time."\x00".$nonce."\x00"."\x00".$org_id."\x00"."\x00"."GET"."\x00".$path."\x00";
$signhash  = hash_hmac('sha256', $signature, $api_secret);

$headers = array(
	"X-Time: {$time}",
	"X-Nonce: {$nonce}",
	"X-Organization-Id: {$org_id}",
	"X-Request-Id: {$nonce}",
	"X-Auth: {$api_key}:{$signhash}",
);

$curl = curl_init();
//curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_URL, $url_root.$path);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);

$info = json_decode($result, true);
print_r($info);

the output should be something like:

...\php.exe api2.php
server time: 1567146960771
Array
(
    [btcAddress] => 000ANcEEy1QawpN3yuVCCDJqU4T3NPHZb2p
    [downloadData] => Array
        (
            [nhm] => Array
                (
                    [version] => 1.9.2.13
                    [size] =>
                    [link] => https://github.com/nicehash/NiceHashMiner/releases/tag/1.9.2.13
                )

            [nhos] => Array
                (
                    [version] => 1.0.5
                    [size] =>
                    [link] => https://nhos.nicehash.com/component?variant=production&name=image
                )

        )

)

complete php example comming soon

Can't really figure out where i went wrong, but your code got me over the hump.
Here is a nice function for GET requests. Haven't needed post yet or a body request so I will leave this here.

Thanks @bl4z & @cod3gen!


define('NH_API_KEY', 'XXXX' );
define('NH_API_SEC', 'XXXX' );
define('NH_API_ORG', 'XXXX' );


function NHAPIv2_Call($EndPoint, $Params = array(), $Method = 'GET'){
	$Method 		= strtoupper( $Method );
	
	$url_root   = "https://api2.nicehash.com";
	
	$QueryStr  = ( count($Params) > 0) ? http_build_query($Params) : null;
	
	$time 		 = (gmmktime() * 1000);	
	$nonce     = uniqid();
	$path      = $EndPoint;
	$query		 = $QueryStr;
	$signature = NH_API_KEY."\x00".$time."\x00".$nonce."\x00"."\x00".NH_API_ORG."\x00"."\x00". $Method ."\x00".$path."\x00".$query;
	$signhash  = hash_hmac('sha256', $signature, NH_API_SEC );
	
	$headers = array(
		"X-Time: {$time}",
		"X-Nonce: {$nonce}",
		"X-Organization-Id: " . NH_API_ORG,
		"X-Request-Id: {$nonce}",
		"X-Auth: ".NH_API_KEY.":{$signhash}",
	);
	
	$curl = curl_init();
	curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
	curl_setopt($curl, CURLOPT_URL, $url_root . $path . "?" . $query);
	curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
	$result = curl_exec($curl);
	curl_close($curl);
	
	$info = json_decode($result, true);	
	return $info;
}

this should work

<?php

$url_root   = "https://api-test.nicehash.com";
$org_id     = "00095760-4f2f-4b19-83d1-72ced0272976";
$api_key    = "0000f476-c39b-43fc-a62c-337e98bdcb76";
$api_secret = "000d4037-59f1-4afa-940f-d0f4dc5014f21956eeb2-3295-4bed-8e93-835ccc878d28";

//get current time
$curl = curl_init();
//curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_URL, $url_root."/api/v2/time");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);

$time = json_decode($result, true)['serverTime'];
echo "server time: ".$time."\n";

//do auth request
$nonce     = uniqid();
$path      = "/main/api/v2/mining/info";
$signature = $api_key."\x00".$time."\x00".$nonce."\x00"."\x00".$org_id."\x00"."\x00"."GET"."\x00".$path."\x00";
$signhash  = hash_hmac('sha256', $signature, $api_secret);

$headers = array(
	"X-Time: {$time}",
	"X-Nonce: {$nonce}",
	"X-Organization-Id: {$org_id}",
	"X-Request-Id: {$nonce}",
	"X-Auth: {$api_key}:{$signhash}",
);

$curl = curl_init();
//curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_URL, $url_root.$path);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);

$info = json_decode($result, true);
print_r($info);

the output should be something like:

...\php.exe api2.php
server time: 1567146960771
Array
(
    [btcAddress] => 000ANcEEy1QawpN3yuVCCDJqU4T3NPHZb2p
    [downloadData] => Array
        (
            [nhm] => Array
                (
                    [version] => 1.9.2.13
                    [size] =>
                    [link] => https://github.com/nicehash/NiceHashMiner/releases/tag/1.9.2.13
                )

            [nhos] => Array
                (
                    [version] => 1.0.5
                    [size] =>
                    [link] => https://nhos.nicehash.com/component?variant=production&name=image
                )

        )

)

complete php example comming soon

This worked for me, but when i try to add query, it fails with invalid session..

Any ideas?

I am trying to get "/main/api/v2/hashpower/myOrders/" with params "algorithm=SHA256"

bl4z commented

try like this

please pay attention to $qs param is added to $signature without (?) but then with (?) like this: $url_root.$path."?".$qs

//anoter auth request
$nonce     = uniqid();
$path      = "/main/api/v2/hashpower/myOrders";
$qs        = "op=LE&limit=100&ts=".$time."&algorithm=NEOSCRYPT";
$signature = $api_key."\x00".$time."\x00".$nonce."\x00"."\x00".$org_id."\x00"."\x00"."GET"."\x00".$path."\x00".$qs;
$signhash  = hash_hmac('sha256', $signature, $api_secret);

$headers = array(
	"X-Time: {$time}",
	"X-Nonce: {$nonce}",
	"X-Organization-Id: {$org_id}",
	"X-Request-Id: {$nonce}",
	"X-Auth: {$api_key}:{$signhash}",
);

$curl = curl_init();
//curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_URL, $url_root.$path."?".$qs);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);

$info = json_decode($result, true);
print_r($info);

response

Array
(
    [list] => Array
        (
            [0] => Array
                (
                    [id] => 403ff3b2-15ee-405e-b8e8-aa807c897338
                    [availableAmount] => 0.00475
                    [payedAmount] => 0
                    [endTs] => 2019-03-16T08:16:52.555Z
                    [updatedTs] => 2019-03-16T08:17:15.015Z
                    [estimateDurationInSeconds] => 0
                    [type] => Array
                        (
                            [code] => STANDARD
                            [description] => Standard
                        )

                    [market] => USA
                    [algorithm] => Array
                        (
                            [algorithm] => NEOSCRYPT
                            [title] => NeoScrypt
                            [enabled] => 1
                            [order] => 8
                        )

                    [status] => Array
                        (
                            [code] => EXPIRED
                            [description] => Expired
                        )

                    [price] => 0.01
                    [limit] => 0.01
                    [amount] => 0.005
                    [displayMarketFactor] => GH
                    [marketFactor] => 1000000000
                    [alive] =>
                    [startTs] => 2019-03-06T08:16:52.555Z
                    [pool] => Array
                        (
                            [id] => f960ec6f-2a05-4766-ab77-bac8c2dfd5dd
                            [name] => bsod
                            [algorithm] => NEOSCRYPT
                            [stratumHostname] => eu.xxx.pw
                            [stratumPort] => 1932
                            [username] => XXXYnHiKdXWZpQ6PxZk9uVjeufEysj5zVP
                            [password] => x
                        )

                    [acceptedCurrentSpeed] => 0
                    [rigsCount] => 0
                    [organizationId] => 48795760-4f2f-4b19-83d1-72ced0272976
                    [creatorUserId] => b9655604-3ed8-4c46-90bd-c79ec641e88d
                ) ...

Please give an example "POST" request UPDATE PRICE AND LIMIT.

bl4z commented

pay attention to add post body to the end of signature string - $signature and set post curl request with:

curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postbody);

i also added content type and content length to request headers

marketFactor, displayMarketFactor and orderId u get from .. order details request or algoinfo

//update price and limit
$nonce     = uniqid();
$path      = "/main/api/v2/hashpower/order/63b126f1-fdcd-44db-b3f0-c89fdeb7a506/updatePriceAndLimit";
$qs        = "";
$postbody  = json_encode(array("marketFactor"=>"1000000000000000","displayMarketFactor"=>"PH","limit"=>"0","price"=>"0.0004"));
$postlen   = strlen($postbody);
$signature = $api_key."\x00".$time."\x00".$nonce."\x00"."\x00".$org_id."\x00"."\x00"."POST"."\x00".$path."\x00".$qs."\x00".$postbody;
$signhash  = hash_hmac('sha256', $signature, $api_secret);

$headers = array(
	"X-Time: {$time}",
	"X-Nonce: {$nonce}",
	"X-Organization-Id: {$org_id}",
	"X-Request-Id: {$nonce}",
	"X-Auth: {$api_key}:{$signhash}",
	"Content-Type: application/json",                                                                                
	"Content-Length: {$postlen}" 
);

$curl = curl_init();
//curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postbody); 
curl_setopt($curl, CURLOPT_URL, $url_root.$path."?".$qs);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);

$info = json_decode($result, true);
print_r($info);

Hello! Maybe you can help me!

I need a request to get order data.

C #

string priceResponse = api.get("/main/api/v2/hashpower/order/" + myOrderId + "/updatePriceAndLimit", true, time);
ServerPrice serverPriceObject = Newtonsoft.Json.JsonConvert.DeserializeObject(priceResponse);
string Price = serverPriceObject.serverPrice;

string priceResponse = api.get("/main/api/v2/hashpower/order/" + myOrderId + "/updatePriceAndLimit", true, time);


response

"Http Request method not allowed for this resource"

bl4z commented

You are using wrong method - for updatePriceAndLimit u should use POST insted of GET request type.
see here https://docs.nicehash.com/main/index.html

Thx bro!

Hello! please, help me
I want to set a FIXED order, but I get errors like this

object(stdClass)#1 (2) { ["error_id"]=> string(36) "6dfa6471-3ac7-4850-ae72-dc46f72c9537" ["errors"]=> array(1) { [0]=> object(stdClass)#2 (2) { ["code"]=> int(5012) ["message"]=> string(44) "Hashpower order fixed speed limit is too big" } } } bool(true)

object(stdClass)#1 (2) { ["error_id"]=> string(36) "6c2add5b-3fd9-4fea-998d-19ebf95c7b73" ["errors"]=> array(1) { [0]=> object(stdClass)#2 (2) { ["code"]=> int(5056) ["message"]=> string(41) "Error creating fixed order, price changed" } } } bool(true)

what am I doing wrong?
How to find out the acceptable intervals for Price & Limits?

bl4z commented

this depends on market situation .. just call
POST /main/api/v2/hashpower/orders/fixedPrice ({"limit":"0.1","market":"EU","algorithm":"X16RV2"})

u will get price and max speed (min speed is in algo settings)
{"fixedMax":"31.2737","fixedPrice":"0.0001"}

Hello, help me please. ( "Invalid Session 2000" )

server time: 1.58269476041E+12
headers:
Array
(
[0] => X-Time: 1.58269476041E+12
[1] => X-Nonce: 5e560168c88b8
[2] => X-Organization-Id: 518a4e9e-877f-40a8-bcd9-d60caa38873e
[3] => X-Request-Id: 5e560168c88b8
[4] => X-Auth: cec48bae-8c54-4bba-9bd4-ddf1df4c90e0:bbc62ce56325697429ea30b45c286c7ed0d4afc443397e968ccfe3b9db361c8f
)
info:
Array
(
[error_id] => 6920b965-81c3-4699-99ca-a6a35d974661
[errors] => Array
(
[0] => Array
(
[code] => 2000
[message] => Invalid Session
)

    )

)

<?php
echo '<pre>';
$url_root   = "https://api-test.nicehash.com";
$org_id     = "518a4e9e-877f-40a8-bcd9-d60caa38873e";
$api_key    = "cec48bae-8c54-4bba-9bd4-ddf1df4c90e0";
$api_secret = "b110a27d-c9ec-4ec8-83ef-8623b44f9036ce740a31-42dd-4d14-8a87-06948213e9f1";

//get current time
$curl = curl_init();
//curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_URL, $url_root."/api/v2/time");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);

$time = json_decode($result, true)['serverTime'];
echo "server time: ".$time."\n";

//do auth request
$nonce     = uniqid();
$path      = "/main/api/v2/accounting/accounts";
$signature = $api_key."\x00".$time."\x00".$nonce."\x00"."\x00".$org_id."\x00"."\x00"."GET"."\x00".$path."\x00";
$signhash  = hash_hmac('sha256', $signature, $api_secret);

$headers = array(
	"X-Time: {$time}",
	"X-Nonce: {$nonce}",
	"X-Organization-Id: {$org_id}",
	"X-Request-Id: {$nonce}",
	"X-Auth: {$api_key}:{$signhash}",
);

echo 'headers: <br>';
print_r ($headers);
$curl = curl_init();
//curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_URL, $url_root.$path);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);

$info = json_decode($result, true);
echo 'info: <br>';
print_r($info);
?>

pay attention to add post body to the end of signature string - $signature and set post curl request with:

curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postbody);

i also added content type and content length to request headers

marketFactor, displayMarketFactor and orderId u get from .. order details request or algoinfo

//update price and limit
$nonce     = uniqid();
$path      = "/main/api/v2/hashpower/order/63b126f1-fdcd-44db-b3f0-c89fdeb7a506/updatePriceAndLimit";
$qs        = "";
$postbody  = json_encode(array("marketFactor"=>"1000000000000000","displayMarketFactor"=>"PH","limit"=>"0","price"=>"0.0004"));
$postlen   = strlen($postbody);
$signature = $api_key."\x00".$time."\x00".$nonce."\x00"."\x00".$org_id."\x00"."\x00"."POST"."\x00".$path."\x00".$qs."\x00".$postbody;
$signhash  = hash_hmac('sha256', $signature, $api_secret);

$headers = array(
	"X-Time: {$time}",
	"X-Nonce: {$nonce}",
	"X-Organization-Id: {$org_id}",
	"X-Request-Id: {$nonce}",
	"X-Auth: {$api_key}:{$signhash}",
	"Content-Type: application/json",                                                                                
	"Content-Length: {$postlen}" 
);

$curl = curl_init();
//curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postbody); 
curl_setopt($curl, CURLOPT_URL, $url_root.$path."?".$qs);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);

$info = json_decode($result, true);
print_r($info);

Hi Fennix86,

Can you help me with this one, I don't what did I do wrong, I can't proceed the New Order of Exchange.

Thanks

`<?
echo '

';
$url_root = "https://api2.nicehash.com";
$org_id = "";
$api_key = "";
$api_secret = "";

//get current time
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_URL, $url_root."/api/v2/time");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);

$time = json_decode($result, true)['serverTime'];
echo "server time: ".$time."\n";


$nonce     = uniqid();
$path      = "/exchange/api/v2/order";
//$qs        = "market=BTCUSDC&side=SELL&type=LIMIT&quantity=.00012&price=35000&secQuantity=.00012";
$qs ="";

$postbody  = json_encode(array(
	"market"=>"BTCUSDC",
	"side"=>"SELL",
	"type"=>"LIMIT",
	"quantity"=>"0.00012",
	"price"=>"35000",
	"minSecQuantity"=>"",
	"secQuantity"=>"0.00012",
	"minQuantity"=>""
	)
);

print_r($postbody);
$postlen   = strlen($postbody);

//$signature = $api_key."\x00".$time."\x00".$nonce."\x00"."\x00".$org_id."\x00"."\x00"."POST"."\x00".$path."\x00".$qs;
//$signature = $api_key."\x00".$time."\x00".$nonce."\x00"."\x00".$org_id."\x00"."\x00"."POST"."\x00".$path."\x00".$qs."\x00".$postbody;
$signature = $api_key."\x00".$time."\x00".$nonce."\x00"."\x00".$org_id."\x00"."\x00"."POST"."\x00".$path."\x00".$postbody;
$signhash  = hash_hmac('sha256', $signature, $api_secret);


//$postlen   = strlen($qs);

//echo $postlen .' <br>';

$headers = array(
	"X-Time: {$time}",
	"X-Nonce: {$nonce}",
	"X-Organization-Id: {$org_id}",
	"X-Request-Id: {$nonce}",
	"X-Auth: {$api_key}:{$signhash}",
	"Content-Type: application/json",          
	"Content-Length: {$postlen}",
);
echo ' <br>headers: <br>';
print_r ($headers);

$curl = curl_init($url_root.$path);
//curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
//curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postbody); 


//curl_setopt($curl, CURLOPT_URL, $url_root.$path.'?'.$qs);
//curl_setopt($curl, CURLOPT_URL, $url_root.$path);

curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curl);

if(curl_errno($curl)){
    echo 'Err : ' . curl_error($curl) .'<br>';
}
print_r($result);

curl_close($curl);
//if(!$result){echo "Connection Failure";}


//print_r($result);

$info = json_decode($result, true);
echo '<br>info: <br>';
print_r($info);


echo '-- END -- <br>';

?>`

pouvais vous maider pour le coter php pour GET /main/api/v2/mining/rig2/{rigId}

pay attention to add post body to the end of signature string - $signature and set post curl request with:
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postbody);
i also added content type and content length to request headers
marketFactor, displayMarketFactor and orderId u get from .. order details request or algoinfo

//update price and limit
$nonce     = uniqid();
$path      = "/main/api/v2/hashpower/order/63b126f1-fdcd-44db-b3f0-c89fdeb7a506/updatePriceAndLimit";
$qs        = "";
$postbody  = json_encode(array("marketFactor"=>"1000000000000000","displayMarketFactor"=>"PH","limit"=>"0","price"=>"0.0004"));
$postlen   = strlen($postbody);
$signature = $api_key."\x00".$time."\x00".$nonce."\x00"."\x00".$org_id."\x00"."\x00"."POST"."\x00".$path."\x00".$qs."\x00".$postbody;
$signhash  = hash_hmac('sha256', $signature, $api_secret);

$headers = array(
	"X-Time: {$time}",
	"X-Nonce: {$nonce}",
	"X-Organization-Id: {$org_id}",
	"X-Request-Id: {$nonce}",
	"X-Auth: {$api_key}:{$signhash}",
	"Content-Type: application/json",                                                                                
	"Content-Length: {$postlen}" 
);

$curl = curl_init();
//curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postbody); 
curl_setopt($curl, CURLOPT_URL, $url_root.$path."?".$qs);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);

$info = json_decode($result, true);
print_r($info);

Hi Fennix86,

Can you help me with this one, I don't what did I do wrong, I can't proceed the New Order of Exchange.

Thanks

`<? echo '

';

$url_root = "https://api2.nicehash.com";

$org_id = "";

$api_key = "";

$api_secret = "";

//get current time
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_URL, $url_root."/api/v2/time");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);

$time = json_decode($result, true)['serverTime'];
echo "server time: ".$time."\n";


$nonce     = uniqid();
$path      = "/exchange/api/v2/order";
//$qs        = "market=BTCUSDC&side=SELL&type=LIMIT&quantity=.00012&price=35000&secQuantity=.00012";
$qs ="";

$postbody  = json_encode(array(
	"market"=>"BTCUSDC",
	"side"=>"SELL",
	"type"=>"LIMIT",
	"quantity"=>"0.00012",
	"price"=>"35000",
	"minSecQuantity"=>"",
	"secQuantity"=>"0.00012",
	"minQuantity"=>""
	)
);

print_r($postbody);
$postlen   = strlen($postbody);

//$signature = $api_key."\x00".$time."\x00".$nonce."\x00"."\x00".$org_id."\x00"."\x00"."POST"."\x00".$path."\x00".$qs;
//$signature = $api_key."\x00".$time."\x00".$nonce."\x00"."\x00".$org_id."\x00"."\x00"."POST"."\x00".$path."\x00".$qs."\x00".$postbody;
$signature = $api_key."\x00".$time."\x00".$nonce."\x00"."\x00".$org_id."\x00"."\x00"."POST"."\x00".$path."\x00".$postbody;
$signhash  = hash_hmac('sha256', $signature, $api_secret);


//$postlen   = strlen($qs);

//echo $postlen .' <br>';

$headers = array(
	"X-Time: {$time}",
	"X-Nonce: {$nonce}",
	"X-Organization-Id: {$org_id}",
	"X-Request-Id: {$nonce}",
	"X-Auth: {$api_key}:{$signhash}",
	"Content-Type: application/json",          
	"Content-Length: {$postlen}",
);
echo ' <br>headers: <br>';
print_r ($headers);

$curl = curl_init($url_root.$path);
//curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
//curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postbody); 


//curl_setopt($curl, CURLOPT_URL, $url_root.$path.'?'.$qs);
//curl_setopt($curl, CURLOPT_URL, $url_root.$path);

curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curl);

if(curl_errno($curl)){
    echo 'Err : ' . curl_error($curl) .'<br>';
}
print_r($result);

curl_close($curl);
//if(!$result){echo "Connection Failure";}


//print_r($result);

$info = json_decode($result, true);
echo '<br>info: <br>';
print_r($info);


echo '-- END -- <br>';

?>`

Hello, Have you solved this issue ?
I'm trying to use API with POST (with your script) for rig power management but I have still code 2000 invalid session.
Thank you

Hello! please, help me
when I try to place a FIXED order, I get a server error
{
["code"]=>
int(2999)
["message"]=>
string(20) "Generic Server Error"
},
STANDARD order, with the same values is created without problems,
I get the values ​​for the price and limit in advance
{
["fixedMax"]=>
string(10) "0.01380000"
["fixed price"]=>
string(10) "0.71050000"
}
ALGO : EQUIHASH