Last active
February 1, 2017 01:32
-
-
Save saboyutaka/ab8d9baf306dc2ebcc79ab4d1f645fc7 to your computer and use it in GitHub Desktop.
Display Bitcoin prices of 4 major exchange in BTC/JPY on Bitbar
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
// Display Bitcoin prices of 4 major exchange in BTC/JPY on Bitbar | |
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"io/ioutil" | |
"log" | |
"net/http" | |
) | |
func getJSON(url string) []byte { | |
resp, _ := http.Get(url) | |
defer resp.Body.Close() | |
byteArray, err := ioutil.ReadAll(resp.Body) | |
if err != nil { | |
log.Print(err) | |
return nil | |
} | |
return byteArray | |
} | |
func zaif(ch chan string) { | |
byteArray := getJSON("https://api.zaif.jp/api/1/ticker/btc_jpy") | |
var j struct { | |
Bid float32 `json:"bid"` | |
Ask float32 `json:"ask"` | |
} | |
if err := json.Unmarshal(byteArray, &j); err != nil { | |
log.Print(err) | |
return | |
} | |
ch <- fmt.Sprintf("Zaif bid: %d, ask: %d", int(j.Bid), int(j.Ask)) | |
} | |
func bitflyer(ch chan string) { | |
byteArray := getJSON("https://api.bitflyer.jp/v1/ticker?product_code=BTC_JPY") | |
var j struct { | |
Bid float32 `json:"best_bid"` | |
Ask float32 `json:"best_ask"` | |
} | |
if err := json.Unmarshal(byteArray, &j); err != nil { | |
log.Print(err) | |
return | |
} | |
ch <- fmt.Sprintf("Bitflyer bid: %d, ask: %d", int(j.Bid), int(j.Ask)) | |
} | |
func btcbox(ch chan string) { | |
byteArray := getJSON("https://www.btcbox.co.jp/api/v1/ticker/") | |
var j struct { | |
Bid float32 `json:"buy"` | |
Ask float32 `json:"sell"` | |
} | |
if err := json.Unmarshal(byteArray, &j); err != nil { | |
log.Print(err) | |
return | |
} | |
ch <- fmt.Sprintf("BTCBOX bid: %d, ask: %d", int(j.Bid), int(j.Ask)) | |
} | |
func quoine(ch chan string) { | |
byteArray := getJSON("https://api.quoine.com/products/5") | |
var j struct { | |
Bid float32 `json:"market_bid"` | |
Ask float32 `json:"market_ask"` | |
} | |
if err := json.Unmarshal(byteArray, &j); err != nil { | |
log.Print(err) | |
return | |
} | |
ch <- fmt.Sprintf("Quoine bid: %d, ask: %d", int(j.Bid), int(j.Ask)) | |
} | |
func main() { | |
fmt.Println("💲") | |
fmt.Println("---") | |
ch := make(chan string) | |
go bitflyer(ch) | |
go zaif(ch) | |
go btcbox(ch) | |
go quoine(ch) | |
for i := 0; i < 4; i++ { | |
fmt.Println(<-ch) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment