Jump to content

peterhuynh

Members
  • Posts

    29
  • Joined

  • Last visited

Everything posted by peterhuynh

  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"
  15. Yup, I tried that before I posted. I tried to sort $ask, and I get an error. When I use print_r to show the contents of $ask, I get nothing. So I'm still not sure what the problem is.
  16. I don't think that is my intention. I'm VERY new to php, so I'm just doing things as I go along to see whatever works. Can you tell me a bit more about overloading variables? Thanks,
  17. Hi, The problem I'm having is getting to the 'bids' section of the array. Whereas in the link, the 'bids' section is immediately available. Here, the 'bids' section is nested in a set called 'ltc_btc'. This is where the confusion is derived from. Thanks for the help.
  18. Ahh! A little bit of help or a hint? This is the result: {"ltc_btc":{"asks":[[0.00757,109.7613],[0.00758,83.72171025]],"bids":[[0.00754,0.782],[0.00753,283.68702632],[0.00752,608.06368173],[0.00751,1058.66307725],[0.0075,692.06028608]]}} I want to sort "asks" and "bids". This is where I'm having a problem. This is the code I'm using: $array = $array->ltc_btc; rsort($array['bids']); sort($array['asks']); $btce_bids = $array->bids; $btce_bids = $array['bids'][0][0]; $btce_bids_quantity = $array->bids; $btce_bids_quantity = $array['bids'][0][1]; $btce_asks = $array->asks; $btce_asks = $array['asks'][0][0]; $btce_asks_quantity = $array->asks; $btce_asks_quantity = $array['asks'][0][1]; After it sorts it, it select some stuff out of the array. (I think this part is no problem but just putting it up here).
  19. I'm looking at this: $message = “{$nonce}{$token}{$path}0.1buy965.45”; Can someone tell me what the syntax means. Thanks.
  20. Thank you. The script is supposed to execute a buy order at a bitcoin exchange. This is the example given to me by the exchange.
  21. Hi, This is my third post and the first two were incredibly helpful. I'm learning a lot, so thank you contributers! This is what I'm working with: $nonce = time(); $token = ‘asdfghjklmnbvcxz’; $secret = ‘qwertyuioplkjhgfdsa’; $path = '/api2/user/order.json'; $params = array( 'amount' => '0.1', 'mode' => 'buy', 'currencypair' => 'BTCCAD', '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); I ran the script but it doesn't work. I'm wondering about $path. How would the script know to go anywhere to get anything since it doesn't link to any website? Any ideas how to make it work? Thanks
  22. Hi, supernoob here. This is my 2nd thread. The 1st one was very helpful. I want to sort a multidimensional array. I have something like this: {"bids": [[ 100, 24 ], [ 300, 10 ], [ 200, 34 ]], "asks": [[ 300, 23 ], [ 100, 34 ], [ 200, 21]]} I want to order "bids" such that the largest first number in the square brackets goes first. (I realize I'm not explaining this well.) For example, I want "[[ 300, 10 ], [ 200, 34 ], [ 100, 24 ]]". And I want to order "asks" such that the smallest first number in the square bracket goes first. For example, I want "[[ 100, 34 ], [ 200, 21 ], [ 300, 23]]" Thank you so much!
  23. Thanks, guys! I actually made something work in programming. Is there a tipping service on this forums? If you guys have a bitcoin wallet, I'd like to send you something. Another question: How do get specific things when the array is a set of sets? For instance, my original problem was that I needed to get something out and turn it into a variable. The set looked like this: {"a":"1", "b":"2", "c":"3"}. Now I need to get things that are members of a subset of the original set. E.g., {"bids": [[0.010010000, 150.000000000], [0.121000000, 82.000000000]], "asks": [[1700.000000000, 1.000000000],[282.365000000, 1.000000000]]}. Specifically, how do I get the lowest "asks"?
×
×
  • 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.