bitflyer

package module
v0.0.0-...-df7f5f2 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2024 License: MIT Imports: 17 Imported by: 3

README

go-bitflyer

GoDoc

Bitflyer exchange API version1, renew at 2023/02. Updated for change FX to CFD at 2024/04/01.

Description

go-bitflyer is a go client library for Bitflyer lightning API.

Supported

  • All Public API
  • All Private API
  • GUI's Hidden API
  • Websocket

Usage

Client Functions
Public Status(&Request{}) (res, apiLimit, err)
Public Helth(&Request{}) (res, apiLimit, err)
Public Ticker(&Request{}) (res, apiLimit, err)
Public Market(&Request{}) (res, apiLimit, err)
Public Board(&Request{}) (res, apiLimit, err)
Public Executions(&Request{}) (res, apiLimit, err)
Public Fr(&Request{}) (res, apiLimit, err)
Public Chat(&Request{}) (res, apiLimit, err)
Public LeverageC(&Request{}) (res, apiLimit, err)
Private Permissions(&Request{}) (res, apiLimit, err)
Private Balance(&Request{}) (res, apiLimit, err)
Private Collateral(&Request{}) (res, apiLimit, err)
Private CollateralAccounts(&Request{}) (res, apiLimit, err)
Private Addresses(&Request{}) (res, apiLimit, err)
Private Coinins(&Request{}) (res, apiLimit, err)
Private Coinouts(&Request{}) (res, apiLimit, err)
Private Banks(&Request{}) (res, apiLimit, err)
Private Deposits(&Request{}) (res, apiLimit, err)
Private Withdrawals(&Request{}) (res, apiLimit, err)
Private ChildOrder(&Request{}) (res, apiLimit, err)
Private CancelChildOrder(&Request{}) (res, apiLimit, err)
Private ParentOrder(&Request{}) (res, apiLimit, err)
Private CancelParentOrder(&Request{}) (res, apiLimit, err)
Private Cancel(&Request{}) (res, apiLimit, err)
Private ChildOrders(&Request{}) (res, apiLimit, err)
Private DetailParentOrder(&Request{}) (res, apiLimit, err)
Private MyExecutions(&Request{}) (res, apiLimit, err)
Private BalanceHistory(&Request{}) (res, apiLimit, err)
Private Positions(&Request{}) (res, apiLimit, err)
Private CollateralHistory(&Request{}) (res, apiLimit, err)
Private Commission(&Request{}) (res, apiLimit, err)
Hidden OHLCv(&Request{}) (res, err)
Hidden Ranking(&Request{}) (res, err)
Realtime Connect(&auth, []string{"channels"...}, []string{"product_codes..."...}, chan Response) error

package main

func main() {
    client := bitflyer.New(
		os.Getenv("BF_KEY"),
		os.Getenv("BF_SECRET"))

    results, managedApiLimit, err := client.Executions(&public.Executions{
        ProductCode: "BTC_JPY",
    })
    if err != nil {
        log.Fatal(err)
    }

    for _, v := range *results {
        fmt.Println(v)
        // -> {2430391013 BUY 2.989057e+06 0.02 2025-01-01T08:47:20.577 JRF20250101-084720-050159 JRF20250101-084720-042209}...
    }
    fmt.Println(managedApiLimit.Remain)
    // API Limit remain and more
    // -> 489

	// For Ohlcv and Ranking
	hclient := hidden.New()
	ohlcv, err := hclient.OHLCv(&hidden.RequestOHLCv{
        Symbo;: "BTC_JPY",
		Period: "m",
    })
    if err != nil {
        log.Fatal(err)
    }

    for _, v := range ohlcv {
        fmt.Println(v)
        // -> O, H, L, C, V, Volume(1day), Y(null), Timestamp
		// 0: 3003659 3004234 3003143 3003503 3.131921 311.1 0 2023-02-01T21:01:00+09:00
    }
}



package main

import (
	"context"
	"fmt"
	"log"
	"time"

	"github.com/go-numb/go-bitflyer"
	"github.com/go-numb/go-bitflyer/public"
	"github.com/go-numb/go-bitflyer/realtime"
	"github.com/go-numb/go-bitflyer/types"
)

func main() {
	client := bitflyer.New(
		"xxxxxxxxxxxxxxxxxxx",
		"xxxxxxxxxxxxxxxxxxxxxxxx=")

    // cancel goroutine from this function
	ctx, cancel := context.WithCancel(context.Background())
	ws := realtime.New(ctx)
	defer ws.Close()

    // recive data and notification form websocket
	recived := make(chan realtime.Response, 3)
	// This Connect is sharping binary data, to each struct.
	// There's also a class that handles raw data. use realtime\raw.go
	go ws.Connect(
        // Connect to Private, if struct *Auth. 
		client.Auth, // or nil, when not subscribe to private channel

        // input channel and product code, create request paramater in function
		[]string{
			"executions",
			"ticker",
			"board",
		},
		[]string{
			types.BTCJPY,
		},
		recived)

	go Reciver(ctx, recived)

    sig := make(chan os.Signal)
    <-sig
	cancel()
	time.Sleep(time.Second)
	close(recived)

}

func Reciver(ctx context.Context, ch chan realtime.Response) {
	defer fmt.Println("func reciver was done")
L:
	for {
		select {
		case <-ctx.Done():
			break L
		case v := <-ch:
			switch v.Types {
			case realtime.TickerN:
				fmt.Print(v.ProductCode)
				fmt.Printf(" ticker comming, %.0f\n", v.Ticker.Ltp)
			case realtime.ExecutionsN:
				fmt.Print(v.ProductCode)
				fmt.Println(" executions comming, id: ", v.Executions[0].ID)
			case realtime.BoardSnapN:
				fmt.Print(v.ProductCode)
				fmt.Println(" board snapshot comming, ", v.Board.MidPrice)
			case realtime.BoardN:
				fmt.Print(v.ProductCode)
				fmt.Println(" board update comming, ", len(v.Board.Asks), len(v.Board.Bids))

			case realtime.ChildOrdersN:
				fmt.Println("child order comming, ", v.ChildOrders[0].ChildOrderID)
			case realtime.ParentOrdersN:
				fmt.Println("parent order comming, ", v.ParentOrders[0].ParentOrderID)

			default:
				// can be detected by the receiver as such this loop, so it tells the receiver to terminate.
				// you can check contains "scheduled maintenance" into error.
				fmt.Printf("error or undefind: %#v", v)
			}

		}
	}
}


Author

@_numbP

License

MIT

Documentation

Index

Constants

View Source
const (
	DECIMALP = 1e8
	DECIMALM = 1e-8
)
View Source
const (
	V1 = "https://api.bitflyer.com/v1/"
)

Variables

This section is empty.

Functions

func CallHidden

func CallHidden() *hidden.Client

func Round

func Round(f float64) float64

Round for order size 最小注文単位以下の枚数

Types

type APILimit

type APILimit struct {
	Reset time.Time
	// リセットまでの秒数
	Period int
	// 残回数
	Remain int
}

func (*APILimit) IsRemain

func (p *APILimit) IsRemain() bool

func (*APILimit) Set

func (p *APILimit) Set(header http.Header)

func (*APILimit) Sleep

func (p *APILimit) Sleep()

type Client

type Client struct {

	// Auth
	Auth *auth.Client
	// contains filtered or unexported fields
}

func New

func New(key, secret string) *Client

func (*Client) Addresses

func (p *Client) Addresses(req *private.Addresses) ([]private.Address, *APILimit, error)

func (*Client) Balance

func (p *Client) Balance(req *private.Balance) ([]private.Currency, *APILimit, error)

func (*Client) BalanceHistory

func (p *Client) BalanceHistory(req *private.BalanceHistory) ([]private.BalanceHis, *APILimit, error)

func (*Client) Banks

func (p *Client) Banks(req *private.Banks) ([]private.Bank, *APILimit, error)

func (*Client) Board

func (p *Client) Board(req *public.Board) (*public.ResponseForBoard, *APILimit, error)

func (*Client) Cancel

func (*Client) CancelChildOrder

func (*Client) CancelParentOrder

func (*Client) Chat

func (p *Client) Chat(req *public.Chat) ([]public.Comment, *APILimit, error)

func (*Client) ChildOrder

func (*Client) ChildOrders

func (p *Client) ChildOrders(req *private.ChildOrders) ([]private.COrder, *APILimit, error)

func (*Client) Coinins

func (p *Client) Coinins(req *private.Coinins) ([]private.Coinin, *APILimit, error)

func (*Client) Coinouts

func (p *Client) Coinouts(req *private.Coinouts) ([]private.Coinout, *APILimit, error)

func (*Client) Collateral

func (*Client) CollateralAccounts

func (p *Client) CollateralAccounts(req *private.CollateralAccounts) ([]private.Currency, *APILimit, error)

func (*Client) CollateralHistory

func (p *Client) CollateralHistory(req *private.CollateralHistory) ([]private.CollateralHis, *APILimit, error)

func (*Client) Commission

func (*Client) Deposits

func (p *Client) Deposits(req *private.Deposits) ([]private.Deposit, *APILimit, error)

func (*Client) DetailParentOrder

func (*Client) Executions

func (p *Client) Executions(req *public.Executions) ([]public.Execution, *APILimit, error)

func (*Client) Fr

func (p *Client) Fr(req *public.Fr) (*public.ResponseForFr, *APILimit, error)

func (*Client) Helth

func (p *Client) Helth(req *public.Helth) (*public.ResponseForHelth, *APILimit, error)

func (*Client) LeverageC

func (p *Client) LeverageC(req *public.LeverageC) (*public.ResponseForLeverageC, *APILimit, error)

func (*Client) Markets

func (p *Client) Markets(req *public.Markets) ([]public.Market, *APILimit, error)

func (*Client) MyExecutions

func (p *Client) MyExecutions(req *private.Executions) ([]private.Execution, *APILimit, error)

func (*Client) ParentOrder

func (*Client) Permissions

func (p *Client) Permissions(req *private.Permissions) ([]string, *APILimit, error)

func (*Client) Positions

func (p *Client) Positions(req *private.Positions) ([]private.Position, *APILimit, error)

func (*Client) SetClient

func (p *Client) SetClient(c *http.Client) *Client

func (*Client) Status

func (p *Client) Status(req *public.Status) (*public.ResponseForStatus, *APILimit, error)

func (*Client) Ticker

func (p *Client) Ticker(req *public.Ticker) (*public.ResponseForTicker, *APILimit, error)

func (*Client) Withdrawals

func (p *Client) Withdrawals(req *private.Withdrawals) ([]private.Withdrawal, *APILimit, error)

type Require

type Require interface {
	IsPrivate() bool
	Path() string
	Method() string
	Query() string
	Payload() []byte
}

type Response

type Response struct {
	Code   int
	Status string
	Result interface{}

	Limit APILimit
	Error error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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