Jump to content

peterhuynh

Members
  • Posts

    29
  • Joined

  • Last visited

peterhuynh's Achievements

Member

Member (2/5)

0

Reputation

  1. Here is an example of what the "code" should look like: tonce=1377743828095093 &accesskey=1d87effa-e84d-48c1-a172-0232b86305dd &requestmethod=post &id=1 &method=buyOrder &params=500,1 This is what I get: tonce=1434662836898942 &accesskey=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx &requestmethod=post &id=1 &method=buyOrder ¶ms= Notice that the '&' sign has changed into a '¶', and 'params' is changed into 'ms', and it deson't recognize the parameters I put into the code. Any idea why this is?
  2. OP here: I could be more specific. The variables $a, $b, $c corresonding to three separate scripts: a.php, b.php, c.php. If, among the three variables, $a ends up having the greatest value, then I want to execture a.php. And if $b ends up having the greatest value, then I want to execute b.php. How can I do this? Thanks.
  3. I have a set of variables with randomly assigned integers. $a = 1; $b = 3; $c = -1; I put them in an array and sort them from highest to lowest. $all = array( 'a' => $a, 'b' => $b, 'c' => $c ); arsort($all); I want to do something with the highest variable only if it is greater than 0. How can I accomplish that? Thank you.
  4. Hello world, I'm trying to submit an order at a bitcoin exchange. This is their example: $nonce = time(); $token = 'xoxoxoxoxoxoxoxox'; $secret = ‘qwertyuioplkjhgfdsa’; $path = '/api2/user/order.json'; $params = array( 'amount' => '0.1', 'mode' => 'buy', 'price' => '965.45' ); //param values must be appended in alphabetical order by key to the message $message = “{$nonce}{$token}{$path}0.1buy965.45”; $signature = hash_hmac(‘sha256’, $message, $secret); And I use cURL to post that stuff: $ch = curl_init('https://www.cavirtex.com/api2/user/order.json'); curl_setopt($ch, CURLOPT_HTTPHEADER, $signature); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($message)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($ch); curl_close($ch); It doesn't work. I get this: {"status": "error", "message": "No token key in requests"} Help? Please? Thanks!
  5. AuthenticationAuthentication is accomplished with a private/public key combination that utilizes HMAC-SHA256. Parameter names AND values (total quantity, price, etc.) are passed as strings in JSON format in POST body of the request. To use the API users must first generate a key pair in the User Profile API section of the site. Multiple keypair combinations can be generated per account. NOTE: All POST parameters in JSON (payload) must be sent in string format (quoted). All connections must be be transmitted over HTTPS/SSL.
  6. I'm two months into learning php - my first programming language. I'm thankful for all the support I've received from this board. This script is supposed to retrieve a balance from a bitcoin exchange. (Note: it is a dummy account, so no money actually in it.) Here is the script: <?php date_default_timezone_set("EST"); $nonce = date("Y-m-d H:i:s e"); $secret = 'banana'; $public = 'aGjnonYmA3gEQv6JzgEwcyR7cpa3ARxMlTUweXBer3xM'; $private = '2D0ndrWpzWasfDNIWfvKNizeE2cxmqJhQf31ubf0boyd'; $data = array( "t" => $nonce, "secret" => $secret ); $hash = hash_hmac('sha256', json_encode($data), $private); $headers = array( 'Accept: application/json', 'X-Auth: '. $public, 'X-Auth-Hash: '. $hash ); $header_data = json_encode($headers); $ch = curl_init('https://sandbox.cointrader.net/api4/account/balance'); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: ' . strlen($header_data)) ); $result = curl_exec($ch); curl_close($ch); var_dump($result); ?> The POST parameters are "time" and "secret". Time is supposed to be formatted a certain way, which I've done, and the secret is the word 'banana'. The exchange provides me with this message: string(205) "{"success":false,"message":"Unauthorized","data":{"errorCode":"401","message":"Headers or JSON POST missing tonce, corrupt or incomplete. Data: {\"t\":\"2015-03-04 22:33:57 EST\",\"secret\":\"banana\"}"}} "
  7. Honestly, I've read the example at least a dozen times, and I've tried running it in my script but to no avail. I'm not sure how I authenticate using curl. I'll keep trying.
  8. Hi Requinix, thanks for the clarification. How do I take the request body and run it through hmac256? i.e., what exactly would be supplemented for the following line? curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "X-Auth: {public key}", "X-Auth-Hash: {post body JSON + private key / HMAC-256 algorithm}")); Thanks again!
  9. I want to reiterate that I'm a noob and am very thankful for this forum and all its help and support. The problem I am having is understand some script, and how I need to modify it to work. (This is a script to POST a buy order on a bitcoin exchange.) Here it is: <?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://cointrader.net/api4/order/BTCCAD/buy"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_POSTFIELDS, " { t : {timestamp}, secret : {secret}, total_quantity : {amount}, price : {price} }"); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "X-Auth: {public key}", "X-Auth-Hash: {post body JSON + private key / HMAC-256 algorithm}")); $response = curl_exec($ch); curl_close($ch); var_dump($response); I'm confused about these two lines: curl_setopt($ch, CURLOPT_POSTFIELDS, " { t : {timestamp}, secret : {secret}, total_quantity : {amount}, price : {price} }"); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "X-Auth: {public key}", "X-Auth-Hash: {post body JSON + private key / HMAC-256 algorithm}")); I believe CURLOPT_POSTFIELDS is information about the order. My question is: Do I replace, e.g., "{timestamp}" with the timestamp and exclude the curly brackets? I believe CURLOPT_HTTPHEADER is authentication. I am particularly confused about this part: "{post body JSON + private key / HMAC-256 algorithm}". I don't know know what to do with this. Again, Thank you so much phpfreaks!
  10. I used this and it works now. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); Thanks for the help, Ch0cu3r
  11. I get this message: "Curl error: SSL: certificate subject name 'incapsula.com' does not match target host name 'www.cointrader.net'bool(false)"
  12. I set it to FALSE: $ch = curl_init('https://www.cointrader.net/api4/stats/high/BTCCAD'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_HEADER, FALSE); $response = curl_exec($ch); curl_close($ch); var_dump($response); It isn't sensitive data, so the improper way is fine. However, it still outputs bool(false).
  13. This is the script I'm running: <?php $ch = curl_init('https://www.cointrader.net/api4/stats/high/BTCUSD'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_HEADER, FALSE); $response = curl_exec($ch); curl_close($ch); var_dump($response); ?> This is the response I get: bool(false) I emailed the API guy at that website for help. He ran the script and gets the proper results. Any tips? Thanks!
  14. Here is my script: $ch = curl_init('https://btc-e.com/api/3/depth/ltc_btc'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, false); $result = curl_exec($ch); $array = json_decode($result, 1); $asks = $array['ltc_btc']['asks']; sort($asks); echo '<pre>', print_r($asks, true), '</pre>'; ?> And this is the result I get: "Warning: sort() expects parameter 1 to be array, null given in /home/a2926161/public_html/btce_ltcbtc_orderbook.php on line 10"
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.