bot きのっこラボ

YoBit Trade Bot

更新日:

今回はYoBitのTrade APIを使った、 Trade Botの作り方とサンプルコード(PHP)を紹介します。

目次
YoBitでアカウント作成
②API KEYを取得
③コード作成

①YoBitでアカウント作成

Trade APIを使うためにはアカウントが必要です。
無い方は、こちらからお願いします。

②API KEYを取得

https://yobit.net/en/api/keys/  より引用

プルタブで「info & trade & deposits」を選択し、「Create new key」を押しAPI KEYを作成して下さい。

③コード作成

https://yobit.net/en/api/  より引用

公式の情報はこれだけしかありません。不親切ですねぇ。
よかったらこちらを参考にして下さいね🍄

<?php

ini_set("display_errors", 1);
error_reporting(E_ALL);


function yobit($method, $req = array()){
  $api_key    = "xxxxx";  //②で作成したKEY
  $api_secret = "xxxxx";  //②で作成したSECRET


$rate   = "xxxxx";  //0.00000380
$amount = "xxxxx";  //100


$req["method"] = $method;
$req["nonce"]  = time();
$req["pair"]   = "alis_btc";  //取引する通貨のペア
$req["type"]   = "sell";      //buy or sell
$req["rate"]   = $rate;
$req["amount"] = $amount;
$post_data = http_build_query($req, '', '&amp;');
echo $post_data."<br>";

$sign = hash_hmac("sha512", $post_data, $api_secret);
$headers = array("Sign: ".$sign,"Key: ".$api_key,);

$ch = null;
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, "https://yobit.net/tapi/");
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

$res = curl_exec($ch);
curl_close($ch);

echo $res."<br>";

}

$res = yobit("Trade"); 

  • 8行目の $api_key に②で取得した KEY を書く
  • 9行目の $api_secret に②で取得した SECRET を書く
  • 12行目の $rate に価格を書く(例 0.00000380)
  • 13行目の $amount に買い(売り)たい量(枚数)を書く
  • 18行目の $req["pair"] に取引したい通貨ペアを書く
  • 19行目の $req["type"] に買いなら buy 、売りなら sell を書く

-bot, きのっこラボ
-, , , , ,

Copyright© きのっこラボ🍄 , 2024 All Rights Reserved Powered by AFFINGER5.