bitfFlyerで買い注文を出す2@python

bifFlyerのAPI経由でPythonで「買い注文」を出してみよう | 文系でもわかる!BitcoinのBOT自動売買トレードの始め方

この記事の勉強メモ

 

import hashlib
import hmac
import requests
import datetime
import json


api_key = "APIキーを入力"
api_secret = "APIシークレットを入力"

base_url = "https://api.bitflyer.jp"
path_url = "/v1/me/sendchildorder"
method = "POST"

timestamp = str(datetime.datetime.today())

param = {
	"product_code" : "FX_BTC_JPY",
	"child_order_type" : "LIMIT",
	"side" : "BUY",
	"price" : 指値価格を入力,
	"size" : 0.01,
}
body = json.dumps(param)

message = timestamp + method + path_url + body
signature = hmac.new(bytearray(api_secret.encode('utf-8')), message.encode('utf-8') , digestmod = hashlib.sha256 ).hexdigest()

headers = {
	'ACCESS-KEY' : api_key,
	'ACCESS-TIMESTAMP' : timestamp,
	'ACCESS-SIGN' : signature,
	'Content-Type' : 'application/json'
}

response = requests.post( base_url + path_url , data = body , headers = headers)
print( response.status_code )
print( response.json() )

 

やりたいこと

現在の買い指値を取得して、その10%下に指値注文入れる。

 

importでbest bidを取得

bestbid09 にbestbid*0.9を代入

 

400
{'status': -103, 'error_message': 'Enter the price in units of 1 JPY.', 'data': None}

エラーが出た。1円単位で?と書いてある?


bestbid09に代入するbestbid*0.9をroundで囲み、小数点以下を切り捨て

できた^^