python 3.6.5を使用しております。
過去にPHPでzaifのAPI取引用botを作成したのですが…
pythonでも作成してみたくなり勉強を始めたばかりで、pythonはまったくの初心者です。
PHPですと以下のプログラムで注文と戻り値の表示ができます。
<?php //必要ファイルの読み込み require 'Zaif.php'; require 'api.php'; require 'dbconnect.php'; //インスタンスの生成 $zaif = new Zaif($key, $secret); //注文処理 $price = 18; $amount = 0.1; $trade_ask = $zaif->trade("trade", array( 'currency_pair' => 'xem_jpy', 'action' => 'bid', 'price' => $price, 'amount' => $amount ) ); var_dump($trade_ask); ?>戻り値は以下です。
object(stdClass)#3 (2) { ["success"]=> int(1) ["return"]=> object(stdClass)#4 (4) { ["received"]=> float(0) ["remains"]=> float(0.1) ["order_id"]=> int(357470635) ["funds"]=> object(stdClass)#5 (8) { ["jpy"]=> float(33434.71898225) ["btc"]=> float(0) ["xem"]=> float(0.69142518) ["mona"]=> float(0) ["BCH"]=> float(8.13E-5) ["JPYZ"]=> float(0.0001) ["PEPECASH"]=> float(3.00003841) ["ZAIF"]=> float(374.0699) } } }
pythonでは以下のように記述してみました。
注文は成功するのですが戻り値を表示できません。(そもそも取得できているのかどうかもわからないです)
どうかご教示頂きますようお願い致します。
from zaifapi import *
import math
zaif = ZaifPublicApi()
ticker = zaif.ticker('btc_jpy')
last = ticker['last']
bid = ticker['bid']
ask = ticker['ask']
key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
zaif = ZaifTradeApi(key, secret)
zaif.trade(currency_pair='btc_jpy',
action='bid',
amount= 0.0001,
price = math.floor(bid - 20000),
limit = math.floor(ask + 20000))
print(zaif)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。