pool/web/yaamp/core/exchange/cryptsy.php
Tanguy Pruvot e3bd3de87d exchanges: allow to ignore some with empty keys/secret
- cryptsy is now used in low priority as default market

- remove keys.php from default defines, only loaded when used

- safecex prepare balances and deposit addresses (not ready yet)
2016-01-13 14:17:35 +01:00

65 lines
1.7 KiB
PHP

<?php
function cryptsy_api_query($method, array $req = array())
{
// debuglog("calling cryptsy_api_query $method");
require_once('/etc/yiimp/keys.php');
if (!defined('EXCH_CRYPTSY_SECRET')) define('EXCH_CRYPTSY_SECRET', '');
if (empty(EXCH_CRYPTSY_KEY)) return FALSE;
// API settings
$key = EXCH_CRYPTSY_KEY; // your API-key
$secret = EXCH_CRYPTSY_SECRET; // your Secret-key
// $cookie_jar = tempnam(YAAMP_HTDOCS.'/yaamp/runtime/cookies','cryptsy_cook');
$cookie_jar = YAAMP_HTDOCS.'/yaamp/runtime/cookies/cryptsy_cookies.dat';
//touch($cookie_jar);
$req['method'] = $method;
$mt = explode(' ', microtime());
$req['nonce'] = $mt[1];
// generate the POST data string
$post_data = http_build_query($req, '', '&');
$sign = hash_hmac("sha512", $post_data, $secret);
// generate the extra headers
$headers = array(
'Sign: '.$sign,
'Key: '.$key,
);
// our curl handle (initialize if required)
static $ch = null;
if (is_null($ch)) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; Cryptsy API PHP client; '.php_uname('s').'; PHP/'.phpversion().')');
}
curl_setopt($ch, CURLOPT_URL, 'https://api.cryptsy.com/api');
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
// run the query
$res = curl_exec($ch);
if ($res === false) {
debuglog("ERROR cryptsy_api_query $method");
return null;
}
// debuglog("cryptsy: $method");
$dec = json_decode($res, true);
if (!is_array($dec)) {
debuglog("ERROR cryptsy_api_query $method");
debuglog(strip_tags($res));
return null;
}
//usleep(200*1000);
return $dec;
}