-
Notifications
You must be signed in to change notification settings - Fork 0
/
bitfinex_api
28 lines (24 loc) · 1.19 KB
/
bitfinex_api
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function bitfinex($key,$secret){
$ch_bitfinex = curl_init();
$mt = explode(' ', microtime());
$req_bitfinex['nonce'] = $mt[1].substr($mt[0], 2, 6);
$req_bitfinex['request']="/v1/orders"; //获取订单
$req_bitfinex['options']=array();
// generate the POST data string
$post_data = http_build_query($req_bitfinex, '', '&');
$headers = array(
'X-BFX-APIKEY: '.$key,
'X-BFX-SIGNATURE: '.hash_hmac('sha384',base64_encode(json_encode($req_bitfinex)),$secret),
'X-BFX-PAYLOAD:'.base64_encode(json_encode($req_bitfinex))
);
curl_setopt($ch_bitfinex, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch_bitfinex, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; bitfinex PHP client; '.php_uname('s').'; PHP/'.phpversion().')');
curl_setopt($ch_bitfinex, CURLOPT_URL, 'https://api.bitfinex.com/v1/orders');
curl_setopt($ch_bitfinex, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch_bitfinex, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch_bitfinex, CURLOPT_SSL_VERIFYPEER, FALSE);
$res = curl_exec($ch_bitfinex);
curl_close($ch_bitfinex);
$dec = json_decode($res, true);
return $dec;
}