ALISホルダーにとって、10/1はとても辛い発表がありました。
保有している暗号資産の引き出しは 2019/12/1 までです!早めに出金しましょう。
Cryptopia 閉鎖後、99.5%の取引が行われていたCoinExchage 閉鎖のお知らせ。最近作ったbotもあと2週間の命になってしまいました。そんな可哀想なbotちゃんを救うべく、新しい取引所に対応してあげることにしました。その取引所は、YoBit という 2014年にロシア設立され 1200種類以上 の 取扱い通貨 がある取引所です。
使用してるのはPublic APIの
https://yobit.net/api/2/alis_btc/ticker
https://yobit.net/api/3/depth/alis_btc
この2つ。このAPIを叩くと
{"ticker":{"high":2.06e-6,"low":1.94e-6,"avg":2.0e-6,"vol":0.00503789,"vol_cur":2468.4531,"last":1.94e-6,"buy":1.92e-6,"sell":2.27e-6,"updated":1570084357,"server_time":1570084415}}
{"alis_btc":{"asks":[[0.00000226,731.01582278],[0.00000227,100],[0.0000023,75.9878418],[0.00021999,16.20027631]],"bids":[[0.00000192,197.61620135],[0.00000191,546.95154752],[0.00000002,5000]]}}
こんな文字・数字が出てくるのでそれをPHPでまとめてTweetするコードを書きます。
<?php ini_set("display_errors", 1); error_reporting(E_ALL); require_once("TwistOAuth.phar"); $consumerKey = "xxxxx"; $consumerSecret = "xxxxx"; $accessToken = "xxxxx"; $accessTokenSecret = "xxxxx"; //YoBit Market Info $url2 = "https://yobit.net/api/2/alis_btc/ticker"; $yo = file_get_contents($url2, false, $context); $start = mb_strpos($yo,"high")+6; $end = mb_strpos($yo,"low")-2; $high = number_format(mb_substr($yo, $start, $end-$start),8); $start = mb_strpos($yo,"low")+5; $end = mb_strpos($yo,"avg")-2; $low = number_format(mb_substr($yo, $start, $end-$start),8); $start = mb_strpos($yo,"vol")+5; $end = mb_strpos($yo,"vol_cur")-2; $vol = mb_substr($yo, $start, $end-$start); $start = mb_strpos($yo,"last")+6; $end = mb_strpos($yo,"buy")-2; $last = number_format(mb_substr($yo, $start, $end-$start),8); $start = mb_strpos($yo,"buy")+5; $end = mb_strpos($yo,"sell")-2; $buy = number_format(mb_substr($yo, $start, $end-$start),8); $start = mb_strpos($yo,"sell")+6; $end = mb_strpos($yo,"updated")-2; $sell = number_format(mb_substr($yo, $start, $end-$start),8); //orderbookから総ALIS量を取得 $url3 = "https://yobit.net/api/3/depth/alis_btc"; $orderbook3 = file_get_contents($url3, false, $context); $end2 = 22; $sell_count = 0; $sell_amount = 0; $buy_count = 0; $buy_amount = 0; $kanma = ","; $futa = "]"; for($y = 0; $y < 500; $y++){ if(strpos($orderbook3,"[",$end2) == 0){ break; } $start1 = strpos($orderbook3,"[",$end2); $end1 = strpos($orderbook3,"$kanma",$start1)+1; //$price = substr($orderbook3, $start1, $end1 - $start1); $end2 = strpos($orderbook3,"$futa",$end1); $amount = substr($orderbook3, $end1, $end2 - $end1); if(strpos($orderbook3,"bids",$end2) == 0 ){ $buy_count ++; $buy_amount += $amount; }else{ $sell_count ++; $sell_amount += $amount; } } //Tweet文作成 $tweet= "["."YoBit Market Info"."]"."\n". "LastPrice:".$last."\n". "HighPrice:".$high."\n". "Low_Price:".$low."\n". "Bid_Price:".$buy."\n". "Ask_Price:".$sell."\n". "Volume:".$vol." BTC"."\n"."\n". "Buy_OrderCount:".$buy_count."\n". "(".number_format((int)$buy_amount)." ALIS)"."\n"."\n". "SellOrderCount:".$sell_count."\n". "(".number_format((int)$sell_amount)." ALIS)"."\n"; // Tweet実行 $twitter = new TwistOAuth($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret); $result = $twitter->post("statuses/update", ["status" => "$tweet"]);
上のコードを走らせるとこうなります↓↓
あとはサーバーにアップロードしてCRONの設定をするだけ。
これでYoBit Market Info の完成です( ͡° ͜ʖ ͡°)🍄
プログラミングを始めてかれこれ1ヶ月、だいぶ慣れてきました。
次はYoBit版の板アラートを作っていきます。
取引所開設はコチラから🍄