インストール
$ go get github.com/zsp2088dev/go-bitflyer
動作環境
使用方法
package main
import (
"fmt"
"github.com/zsp2088dev/go-bitflyer/auth"
"github.com/zsp2088dev/go-bitflyer/v1"
"github.com/zsp2088dev/go-bitflyer/v1/private/positions"
"github.com/zsp2088dev/go-bitflyer/v1/public/ticker"
"github.com/zsp2088dev/go-bitflyer/v1/realtime"
"github.com/zsp2088dev/go-bitflyer/v1/types"
"log"
)
func main() {
config := &auth.Auth{
APIKey: "<API KEY>",
APISecret: "<API SECRET>",
}
// Private APIを利用しない場合はconfigはnilでよい
client := v1.NewClient(config)
// HTTP Public API
req1 := &ticker.Request{ProductCode: types.BTCJPY}
res1, raw1, err := client.Ticker(req1)
if err != nil {
fmt.Println(err)
} else {
fmt.Printf("%v\n\n", res1) // Ticker
fmt.Printf("%v\n\n", raw1)
}
// HTTP Private API
req2 := &positions.Request{ProductCode: types.FXBTCJPY}
res2, raw2, err := client.Positions(req2)
if err != nil {
fmt.Println(err)
} else {
fmt.Printf("%v\n\n", res2) // 建玉一覧
fmt.Printf("%v\n\n", raw2)
}
// Realtime API
channel1 := realtime.Channel{ProductCode: types.FXBTCJPY, Event: realtime.Executions}
channel2 := realtime.Channel{Event: realtime.ChildOrderEvents}
// Privateチャンネルを購読する場合は ".Auth(config)" を呼び出す
wsClient := realtime.
New().
Auth(config).
AddChannel(channel1).
AddChannel(channel2)
// realtime.Response型で各種メッセージを受信
ch := make(chan realtime.Response)
go wsClient.ReceiveMessage(ch)
for {
msg := <-ch
if msg.Error != nil {
log.Println(msg.Error)
}
// 受信したイベントごとに処理
switch msg.Event {
case realtime.Executions:
fmt.Printf("%v\n\n", msg.Executions)
case realtime.ChildOrderEvents:
fmt.Printf("%v\n\n", msg.ChildOrderEvents)
}
}
}
ライセンス
Released under the MIT license.
Copyright (c) 2020, Kazuki Yamagata
製作者