Skip to content

Commit

Permalink
feat(coincheck): add ticker
Browse files Browse the repository at this point in the history
  • Loading branch information
Akagi201 committed Sep 19, 2017
1 parent b631651 commit 7ba2cff
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ A cryptocurrency trader for all famous exchanges.
- [x] jubi
- [x] allcoin
- [x] bitfinex
- [x] coincheck

## Data API
- [x] etherscan
Expand Down
1 change: 1 addition & 0 deletions bitfinex/bitfinex.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package bitfinex bitfinex rest api
package bitfinex

import (
Expand Down
15 changes: 14 additions & 1 deletion cmd/trader/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/Akagi201/cryptotrader/bittrex"
"github.com/Akagi201/cryptotrader/btc9"
"github.com/Akagi201/cryptotrader/chbtc"
"github.com/Akagi201/cryptotrader/coincheck"
"github.com/Akagi201/cryptotrader/etherscan"
"github.com/Akagi201/cryptotrader/fixer"
"github.com/Akagi201/cryptotrader/huobi"
Expand Down Expand Up @@ -251,7 +252,7 @@ func main() {
log.Infof("Get ticker: %+v", ticker)
}

{
if false {
// bitfinex
api := bitfinex.New("", "")

Expand All @@ -262,4 +263,16 @@ func main() {

log.Infof("Get ticker: %+v", ticker)
}

{
// coincheck
api := coincheck.New("", "")

ticker, err := api.GetTicker("jpy", "btc")
if err != nil {
log.Errorf("Get ticker failed, err: %v", err)
}

log.Infof("Get ticker: %+v", ticker)
}
}
44 changes: 44 additions & 0 deletions coincheck/coincheck.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Package coincheck coincheck rest api
package coincheck

import (
coincheck "github.com/Akagi201/coincheckgo"
"github.com/Akagi201/cryptotrader/model"
"github.com/tidwall/gjson"
)

// Coincheck API data
type Coincheck struct {
coincheck.CoinCheck
}

// New create new Allcoin API data
func New(accessKey string, secretKey string) *Coincheck {
client := new(coincheck.CoinCheck).NewClient(accessKey, secretKey)

return &Coincheck{
client,
}
}

// GetTicker 行情
func (cc *Coincheck) GetTicker(base string, quote string) (*model.Ticker, error) {

resp := cc.Ticker.All()

buy := gjson.Get(resp, "bid").Float()
sell := gjson.Get(resp, "ask").Float()
last := gjson.Get(resp, "last").Float()
low := gjson.Get(resp, "low").Float()
high := gjson.Get(resp, "high").Float()
vol := gjson.Get(resp, "volume").Float()

return &model.Ticker{
Buy: buy,
Sell: sell,
Last: last,
Low: low,
High: high,
Vol: vol,
}, nil
}

0 comments on commit 7ba2cff

Please sign in to comment.