332 文字
2 分

PoloniexのAPIを使って、指定した金額になったら取引する(IFD)プログラム

背景#

  • Poloniexで仮想通貨を取引していますが、法定通貨がUSDTしか無い。
  • ETH/BTC とか USDT/BTC がメイン。JPY は存在しない。

問題と解決#

仕様#

  • Stop Limit Order を行っています。
    • 1 分に 1 回レートを取得
    • 指定の金額になったら macOS の notification center に通知を表示
    • 一応、1 分待つ。
    • 1%高い所で指値(Limit order)を入れる。
    • プログラムが終了
  • 24 時間稼働させたいならサーバで動かしておけば良い。

スクリーンショット#

Screen Shot 2017-06-12 at 15.50.41.png

ソースコード#

require 'rubygems'
require 'bundler/setup'
Bundler.require(:default)
Dotenv.load
Poloniex.setup do |config|
config.key = ENV['POLONIEX_KEY']
config.secret = ENV['POLONIEX_SECRET']
end
check_currency_pair = 'USDT_ETH'
sell_currency_pair = 'ETH_BTC'
usd_jpy = 110.24
sell_amount = 0.1
loop do
ticker = Poloniex.ticker
usdt_btc = JSON.parse(ticker)[check_currency_pair]['last']
jpy_btc = usdt_btc.to_f * usd_jpy
puts Time.now.to_s + "\t" + jpy_btc.to_s
if jpy_btc > 38_000
contents = jpy_btc
title = 'Rate alert'
system('osascript -e \'display notification "%s" with title "%s" \'' % %w[contents title])
# execute order
sleep 60
rate = JSON.parse(ticker)['BTC_ETH']['lowestAsk'].to_f * 1.01
Poloniex.sell(sell_currency_pair, rate, sell_amount)
contents = rate
title = 'Placed and selling order'
system('osascript -e \'display notification "%s" with title "%s" \'' % %w[contents title])
break
end
sleep 60
end

Happy FX life!

この記事が役に立ったら
GitHub Sponsorsで応援できます

コメント