Forked from moyashi/coincheck_market_price.10s.rb
Last active
December 6, 2020 09:14
-
-
Save koichiro/b9bc38c166ec8a091d8c5a6c3751e0aa to your computer and use it in GitHub Desktop.
Coincheck Market Price
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# <bitbar.title>Coincheck Market Price</bitbar.title> | |
# <bitbar.version>v1.0</bitbar.version> | |
# <bitbar.author>koichiro</bitbar.author> | |
# <bitbar.author.github>koichiro</bitbar.author.github> | |
# <bitbar.desc>Test</bitbar.desc> | |
# <bitbar.image></bitbar.image> | |
require 'open-uri' | |
require 'json' | |
require 'yaml' | |
yaml = File.join(ENV["HOME"], "coincheck.yaml") | |
#coincheck = "https://coincheck.com/api/ticker" | |
coincheck = "https://coincheck.com/api/rate/btc_jpy" | |
res = '' | |
URI.open(coincheck) do |f| | |
res = f.read | |
end | |
json = JSON.parse(res) | |
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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment