bitflyerで自動売買
bitflyerでとりあえず前の1時間よりも安かったら買うプログラム
おもったより簡単にできた。
SBI銀行から毎日定額送金+下記をcronで回せばビットコン積立みたいなことができそうですね
工夫は後ほどやってみる
#!/usr/bin/ruby
require "net/http"
require "uri"
require "openssl"
require 'json'
require 'time'
require 'securerandom'
require 'base64'
API_KEY = 'XXX'
API_SECRET = 'XXX'
def order(product_code, buy_sell, size)
timestamp = Time.now.to_i.to_s
uri = URI.parse("https://api.bitflyer.jp")
uri.path = "/v1/me/sendchildorder"
body = '{
"product_code" : "'+ product_code +'",
"child_order_type" : "MARKET",
"side" : "' + buy_sell + '",
"size" : ' + size.to_s + ',
"minute_to_expire" : 10000,
"time_in_force" : "GTC"
}'
text = timestamp + 'POST' + uri.request_uri + body
sign = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("sha256"), API_SECRET, text)
options = Net::HTTP::Post.new(uri.request_uri, initheader = {
"ACCESS-KEY" => API_KEY,
"ACCESS-TIMESTAMP" => timestamp,
"ACCESS-SIGN" => sign,
"Content-Type" => "application/json"
});
options.body = body
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = true
response = https.request(options)
result = JSON.parse(response.body)
puts result
if (result['status'] == -201) then
puts ' ' + product_code + ' ' + buy_sell + " You have reached the maximum amount of trades for your account class."
return false
end
if (result['child_order_acceptance_id'] == nil) then
puts ' ' + product_code + ' ' + buy_sell + " Insufficient funds"
return false
end
end
# 今の価格と1時間平均を比べる
url = URI.parse("https://www.bitstamp.net/api/ticker_hour/")
json = Net::HTTP.get(url)
result = JSON.parse(json)
now_price = result['last'].to_f
last_hour = result['open'].to_f
if now_price < last_hour then
order("BTC_JPY", "BUY", 0.001)
end
TenXの紹介
試行錯誤で私もpayトークンを購入すすめていますので参考になる情報をまとめていきます。
TenXの説明はコチラがわかりやすいです
今後どうなっていくのか
1PAYあたり476円/年の配当を受け取れると見る方もいらっしゃるようで今後に期待感が高まります。
現在価格(pay/jpy)
おすすめ取引所
英語でちょっとわかりにくいですが、「bittrex 開設」とかでググればわかりますので割愛します
Bittrex.com - Bittrex, The Next Generation Digital Currency Exchange