I am using the following 'suggested' code to post a test order to Bybit.
(https://github.com/bybit-exchange/api-usage-examples/blob/master/api_demo/futures/Encryption.php)
<?php
function get_signed_params($public_key, $secret_key, $params) {
$params = array_merge(['api_key' => $public_key], $params);
ksort($params);
//decode return value of http_build_query to make sure signing by plain parameter string
$signature = hash_hmac('sha256', urldecode(http_build_query($params)), $secret_key);
return http_build_query($params) . "&sign=$signature";
}
$params = [
'symbol' => 'BTCUSDT',
'side' => 'Buy',
'order_type' => 'Limit',
'qty' => '1',
'price' => '30000',
'time_in_force' => 'GoodTillCancel',
'reduce_only' => false,
'close_on_trigger' => false,
'timestamp' => time() * 1000,
'position_idx' => 0
];
//$url = 'https://api-testnet.bybit.com/private/linear/order/create';
$url = 'https://api.bybit.com/v2/private/order/create';
$public_key = 'my_key_is_here_in_my_code';
$secret_key = 'my_secret_key_is_here_in_my_code';
$qs=get_signed_params($public_key, $secret_key, $params);
$curl_url=$url."?".$qs;
$curl=curl_init($curl_url);
echo $curl_url;
curl_setopt($curl, CURLOPT_URL, $curl_url);
#curl_setopt($curl, CURLOPT_POSTFIELDS, $qs);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
#curl_setopt($curl, CURLOPT_PROXY,"127.0.0.1:1087");
$response=curl_exec($curl);
echo $response;
However, I receive the following within the response: validation for 'symbol' failed on the 'symbol' tag"
https://api.bybit.com/v2/private/order/create?api_key=XXXXXX_my_key_XXXXX&close_on_trigger=0&order_type=Limit&position_idx=0&price=30000&qty=1&reduce_only=0&side=Buy&symbol=BTCUSDT&time_in_force=GoodTillCancel×tamp=1647644020000&sign=0e08e9f9be4cf5e4d7b1294d769ab4bf3b5b79ae9f92bab717670b3d95be0672{"ret_code":10001,"ret_msg":"Param validation for 'symbol' failed on the 'symbol' tag","ext_code":"","ext_info":"","result":null,"time_now":"1647644020.389465","rate_limit_status":99,"rate_limit_reset_ms":1647644020387,"rate_limit":100}
Could somebody pls suggest why Bybit is not recognising the 'BTCUSDT' symbol as expected. As everything seems setup on the exchange. Many thanks for your help.
BTCUSDT is not a valid symbol as per the documenation. These are the list of valid symbols that you can use.
Related
const measurement_id = `G-XXXXXXXXXX`;
const api_secret = `<secret_value>`;
fetch(`https://www.google-analytics.com/mp/collect?measurement_id=${measurement_id}&`api_secret`=${api_secret}`, {
method: "POST",
body: JSON.stringify({
client_id: 'XXXXXXXXXX.YYYYYYYYYY',
events: [{
name: 'tutorial_begin',
params: {},
}]
})
});
can someone tell me how i can do the above code in php?
i have tried the following but it is not working,
$data = array(
'client_id' => self::ga_extract_cid_from_cookies(),
'user_id' => 123,
'timestamp_micros' => time(),
'non_perosnalised_ads' => false,
'events' => array(
'name' => 'login'
)
);
$dataString = json_encode($data);
$post_url = 'https://www.google-analytics.com/mp/collect?api_secret=xxxxxxx&measurement_id=xxxxxxxxx';
$ch = curl_init($post_url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $datastring);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
curl_setopt($ch, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
When i run the above its not sending any event to google analytics account. I don't know what is the error and how to find it. Need help on this pls.
I believe the main problem in your example, apart from the typo in the $datastring variable, was that the user id was sent as an int, not as a string. My example here works:
$ip = str_replace('.', '', $_SERVER['REMOTE_ADDR']);
$data = array(
'client_id' => $ip,
'user_id' => '123',
'events' => array(
'name' => 'event_serverside'
)
);
$datastring = json_encode($data);
$post_url = 'https://www.google-analytics.com/mp/collect?api_secret=xxxxxxxxxx&measurement_id=xxxxxxxxx';
$ch = curl_init($post_url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $datastring);
curl_setopt($ch, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $post_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
curl_setopt($ch, CURLOPT_POST, TRUE);
$result = curl_exec($ch);
I wrote this code. I send data to $url = "https://upload.box.com/api/2.0/files/content", but i don't get a response. Maybe someone has also had this problem?
$absolutePath = 'home/my/path/uploads/media/ClientPDF/0001/01/c607bea86bdb42220bb49aac722b4a5eb44be3db.pdf';
$json = json_encode([
'name' => 'c607bea86bdb42220bb49aac722b4a5eb44be3db.pdf,
'parent' => ['id' => 7479666489] //parent folder
]);
$fields = [
'attributes' => $json,
'file' => #$absolutePath
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer MY_TOKEN_KEY'
'Content-Type:multipart/form-data'
]);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
$response = curl_exec($ch);
var_dump(json_decode($response, true)); die;
var_dump - print nothing, i can't debug this request. Please, help me to solve this problem
I am trying to use this code to insert item in youtubeplaylist and its not working as i want ... i think its showing me if playlist contain this id .
please check and let me know what i need to change in code to insert this ID in my playlist .
Here is code :
$option = array(
'part' => 'snippet',
'mine' => 'true',
'key' => 'AIzaSyCJlbT_sqTG2nOUMYU24WzzxXpOelaiYTA',
'access_token' => $_SESSION['info']['access_token'],
'playlistId' => $ID,
'kind' => 'youtube#video',
'videoId' => 'KMGuyGY5gvY',
);
$url = "https://www.googleapis.com/youtube/v3/playlistItems?".http_build_query($option, 'a', '&');
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$curlheader[0] = "Authorization: Bearer " . $_SESSION['info']['access_token'];
curl_setopt($curl, CURLOPT_HTTPHEADER, $curlheader);
$json_response = curl_exec($curl);
curl_close($curl);
$responseObj = json_decode($json_response);
thanks in advance.
$URL:https://demo.firstach.com/https/TransRequest.asp?Login_ID=someit&Transaction_Key=somekey&Customer_ID=23&Customer_Name=Muhammad Naeem&Customer_Address=Address&Customer_City=city&Customer_State=HI&Customer_Zip=54000&Customer_Phone=--&Customer_Bank_ID=111111118&Customer_Bank_Account=12345678901234567890&Account_Type=Business Checking&Transaction_Type=Debit&Frequency=Once&Number_of_Payments=1&Effective_Date=12%2F05%2F2010&Amount_per_Transaction=10.00&Check_No=&Memo=&SECCType=WEB
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url); // set url to post to
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 0); // times out after Ns
curl_setopt($ch, CURLOPT_FAILONERROR, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec($ch); // run the whole process
print_r($result);
curl_close($ch);
i also used file_get_conent and fopen but all are returning me BAD REQUEST error,
please help me out
for more detail please see the link below
http://www.uqwibble.com/Phase-2/ach.php
Well assumign the code you posted is accurate then this line is the issue:
$URL:https://demo.firstach.com/https/TransRequest.asp?Login_ID=someit&Transaction_Key=somekey&Customer_ID=23&Customer_Name=Muhammad Naeem&Customer_Address=Address&Customer_City=city&Customer_State=HI&Customer_Zip=54000&Customer_Phone=--&Customer_Bank_ID=111111118&Customer_Bank_Account=12345678901234567890&Account_Type=Business Checking&Transaction_Type=Debit&Frequency=Once&Number_of_Payments=1&Effective_Date=12%2F05%2F2010&Amount_per_Transaction=10.00&Check_No=&Memo=&SECCType=WEB
here it looks liek you attemtp to define $URL but when you use it with cURL you are referencing $url. The varibales are case sensitive. Secondly you have $URL: which is not valid you want to use $url =.
Addiitonally i would encode the params like this:
$baseurl = 'https://demo.firstach.com/https/TransRequest.asp';
$params = array(
'Login_ID' => 'someit',
'Transaction_Key' => 'somekey',
'Customer_ID'= => 23,
'Customer_Name' => 'Muhammad Naeem',
'Customer_Address' => 'Address',
'Customer_City' => 'city',
'Customer_State' => 'HI',
'Customer_Zip' => '54000',
'Customer_Phone' => '--',
'Customer_Bank_ID' => '111111118'
'Customer_Bank_Account' => '12345678901234567890'
'Account_Type' => 'Business Checking'
'Transaction_Type' => 'Debit'
'Frequency' => 'Once'
'Number_of_Payments' => 1,
'Effective_Date'=> '12/05/2010',
'Amount_per_Transaction' => '10.00',
'Check_No'=> '',
'Memo'=> '',
'SECCType' => 'WEB'
);
$url = sprintf('%s?%s', $baseurl, http_build_query($params));
That way http_build_query will take care of all your url encoding and you can work with an array before hand so its easy to see whats going on and add/remove/change paramters. Alternatively if its a post request you could jsut use:
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
which will take care of all the parameter encoding and what not directly from the array this way they dont need to be appended manually to the $url.
My Facebook app publishes a story to the user wall with an http post:
$args = array('access_token' => $ACCESS_TOKEN,
'message' => 'testing message',
'picture' => $appin_logo,
'link' => $appin_canvas_url,
'name' => $appin_name,
'caption' => $post_score,
'description' => $post_rfs,
);
$ch = curl_init(); $url = 'https://graph.facebook.com/me/feed'; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $args); $data = curl_exec($ch); curl_close($ch);
That works all fine, except for one thing: $post_rfs is an array. I'd like to output its values in a neat way, with a comma after every value i.e.. What should I do?
Thanks in advance.
Try this:
implode(', ', array_values($post_rfs));