bitflyer.comでAPI使ってみたよ、遅っいぞ。レスポンスが遅い恐ろしく遅いのだ。ccxtとかも使ってみたが・・アレ大丈夫?、なのでPHPでHTTP APIの奴を自作してみた、body部分は間違っているかも。いや間違っているよ。ご自身で直して使ってみても駄目だこりゃと思うはずです。
自分の回線が悪いのかわからないけれど、データの結果が返却されるまで2~4分ぐらい時間がかかるのですccxtでもPHPでも同じくレスポンスが遅いのだ、PHP関してはかなりトロイですね(´・ω・`)。まるでオイラのようだ。
追記:
PHPのレスポンスが遅いのは、LinuxのOSをゴニョゴニョしたからでした。普通にレスポンスが返ってきました、、、。
PHPのソースコードを記載します。
<?php
date_default_timezone_set('Asia/Tokyo');
class api_bitflyer
{
public const url_bitflyer = "https://api.bitflyer.com";
public static $APIKey = "";
public static $APISecret = "";
public static $timestamp = "";
public static $method = "";
public static $body = "";
public static $path = "";
public static $access_singn = "";
public static function set_apikey($a = "", $s = "")
{
self::$APIKey = $a;
self::$APISecret = $s;
}
public static function gorun($path = "", $req_method = "", $req_body = array())
{
//hash_hmac ( string $algo , string $data , string $key [, bool $raw_output = FALSE ] ) : string
//ACCESS-TIMESTAMP, HTTP メソッド, リクエストのパス, リクエストボディ
self::$timestamp = time();
self::$method = $req_method;
self::$path = $path;
$body = json_encode($req_body);
$data = $req_body?self::$timestamp . self::$method . self::$path . $body:self::$timestamp . self::$method . self::$path;
self::$access_singn = hash_hmac("sha256", $data, self::$APISecret);
$headers = [
'ACCESS-KEY: ' . self::$APIKey ,
'ACCESS-TIMESTAMP: ' . self::$timestamp ,
'ACCESS-SIGN: ' . self::$access_singn ,
'Content-Type: application/json',
];
print date("Y/m/d H:i:s");
$curl = curl_init();
if(strtolower(self::$method)=="post"){
curl_setopt($curl, CURLOPT_URL,self::url_bitflyer . self::$path);
}else{
curl_setopt($curl, CURLOPT_URL,self::url_bitflyer . self::$path."?".http_build_query($req_body));
}
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, self::$method);
curl_setopt($curl, CURLOPT_HTTPHEADER,$headers);
if(strtolower(self::$method)=="post"){
curl_setopt($curl, CURLOPT_POSTFIELDS,$body);
}
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
// $response_info = curl_getinfo($curl);
// $response_code = $response_info['http_code'];
// $response_header_size = $response_info['header_size'];
curl_close($curl);
var_dump(json_decode($response));
// var_dump($response_code);
// var_dump($response_header_size);
print date("Y/m/d H:i:s");
}
}
api_bitflyer::set_apikey("APIKEY","シークレットキー");
api_bitflyer::gorun("/v1/getboardstate","GET","");
超絶にレスポンスが遅かったのでnode.jsでリアルタイムAPIを使用してみたら、上手く動作した(*´﹃`*)あれ?
HTTP APIの方もnode.jsなら動作しました。qiitaにHTTP APIの方は置いときます。知っている人は見てみてください。Qiita: http://bit.ly/2Sv1lkt
ちなみにリアルタイムの方はこんな感じです、下記参照!
なお、よく読んだほうが良いAPI Documentation
bitFlyer Lightning では、HTTP API と Realtime API の 2 種類の API を提供しています。
尚、ビットコイン高くて買えないので、ビットコインの売買したい知人は格安で自動売買のシステム作りますよ。