Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provided signature is invalid for PATCH request #110

Open
walidbahgat opened this issue Nov 13, 2021 · 3 comments
Open

Provided signature is invalid for PATCH request #110

walidbahgat opened this issue Nov 13, 2021 · 3 comments

Comments

@walidbahgat
Copy link

i'm facing an issue sending API Patch request, it always send a "{"error":"signature_invalid","error_description":"Provided signature is invalid"}" error, when i try to send i GET request, it return s successfully.

but the issue happens when trying to send PATCH request with several parametes in the body using cURL "-d xxxxxx", it always send me 401 unauthorized, so i need to know do i need to put the baseURL only "/public/api/ver1/bots/<bot_id>/update" in "Plain Text to Compute Hash" or shall i add the parameters in the body also to the "Plain Text to Compute Hash"

@agustind
Copy link

agustind commented Nov 22, 2021

After dealing with this for hours I realized the URL you use to generate the signature should include all the parameters you are posting

@agustind
Copy link

Here's an example in PHP:

$data = [
"name" => $bot_data->name,
"base_order_volume" => $bot_data->base_order_volume,
"take_profit" => $bot_data->take_profit,
"safety_order_volume" => $bot_data->safety_order_volume,
"martingale_volume_coefficient" => $bot_data->martingale_volume_coefficient,
"martingale_step_coefficient" => $bot_data->martingale_step_coefficient,
"max_safety_orders" => $bot_data->max_safety_orders,
"active_safety_orders_count" => $bot_data->active_safety_orders_count,
"safety_order_step_percentage" => $bot_data->safety_order_step_percentage,
"take_profit_type" => $bot_data->take_profit_type,
"strategy_list" => '',
'pairs' => 'USDT_BTC',
'api_key' => $api_key,
'secret' => $secret,
];

$data_encoded = http_build_query($data);

$endpoint_base = '/public/api/ver1/bots/12345678/update';
$endpoint = $endpoint_base . '?' . $data_encoded;

$signature = hash_hmac('sha256', $endpoint, $secret);
$url = 'https://api.3commas.io' . $endpoint_base;

$headers = array(
"Content-Type: application/x-www-form-urlencoded",
"Accept: application/json",
"APIKEY: " . $api_key,
"Signature: " . $signature,
);

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PATCH');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_encoded);
$resp = curl_exec($curl);

@amahouachi
Copy link

I am stuck with the same problem.

@agustind how did you manage to send the strategy_list parameter? Because if you don't want to update it, you need to provide it as it is in the bot before updating no ? Does it get encoded properly? because it's a json array not a simple type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants