api

package module
v0.0.0-...-81d47fe Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 1, 2020 License: MIT Imports: 1 Imported by: 0

README

image

インストール

$ go get github.com/zsp2088dev/go-bitflyer

動作環境

  • Go 1.12

使用方法

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

製作者

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API interface {
	ToURL() (*url.URL, error)
}

type Request

type Request interface {
	Endpoint() string
	Method() string
	Query() string
	Payload() []byte
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL