Skip to content

Instantly share code, notes, and snippets.

@moyashi
Last active December 5, 2020 07:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save moyashi/d5ba29a69d928a178c5080a5f9258c1d to your computer and use it in GitHub Desktop.
Save moyashi/d5ba29a69d928a178c5080a5f9258c1d to your computer and use it in GitHub Desktop.
Coincheck Market Price
#!/usr/bin/ruby
# coding: utf-8
# <bitbar.title>Coincheck Market Price</bitbar.title>
# <bitbar.version>v1.0</bitbar.version>
# <bitbar.author>moyashi</bitbar.author>
# <bitbar.author.github>moyashi</bitbar.author.github>
# <bitbar.desc>Test</bitbar.desc>
# <bitbar.image></bitbar.image>
require 'mechanize'
require 'json'
yaml = File.join(ENV["HOME"], "coincheck.yaml")
agent = Mechanize.new
#res = agent.get("https://coincheck.com/api/ticker")
res = agent.get("https://coincheck.com/api/rate/btc_jpy")
json = JSON.parse(res.body)
color = "black"
difference = 0
#if json && json["last"] then
if json && json["rate"] then
#current_status = json["last"]
current_status = sprintf("%.02f", json["rate"]).to_f
if File.exists?(yaml) then
previous_status = YAML.load(File.read(yaml))
if (previous_status == false) then
previous_status = current_status
end
difference = sprintf("%.02f", current_status - previous_status).to_f
if (difference > 0) then
difference = "+" + difference.to_s
else
difference = difference.to_s
end
if (previous_status > 0) then
if (current_status > previous_status) then
color = "green"
elsif (current_status == previous_status) then
color = "black"
else
color = "red"
end
end
end
File.open(yaml, 'w') {|f| f.write(YAML.dump(current_status)) }
puts "#{current_status}(#{difference}) | color=#{color}"
end
#puts "切り替え表示1"
#puts "切り替え表示2"
puts "---"
puts "ビットコイン(Bitcoin)価格チャート 5分足 | href=https://coincheck.com/ja/exchange/charts/coincheck/btc_jpy/300"
puts "ビットコイン(Bitcoin)価格チャート 15分足 | href=https://coincheck.com/ja/exchange/charts/coincheck/btc_jpy/900"
puts "ビットコイン(Bitcoin)価格チャート 1時間足 | href=https://coincheck.com/ja/exchange/charts/coincheck/btc_jpy/3600"
puts "ビットコイン(Bitcoin)価格チャート 4時間足 | href=https://coincheck.com/ja/exchange/charts/coincheck/btc_jpy/14400"
puts "ビットコイン(Bitcoin)価格チャート 24時間足 | href=https://coincheck.com/ja/exchange/charts/coincheck/btc_jpy/86400"
@moyashi
Copy link
Author

moyashi commented Mar 23, 2017

関連Blog記事: http://hitoriblog.com/?p=50182

@takuo
Copy link

takuo commented Jan 19, 2018

概ね同じものを golang で書きました
https://gist.github.com/takuo/05ad167b03326dc86c974079bf76ed11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment