bitflyer

package module
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: May 3, 2020 License: MIT Imports: 16 Imported by: 0

README

bitflyer

GoDoc GitHub license

bitflyer api for trading bot.

this liibrary contains

  • realtime api
  • private api
  • public api

Install

$ go get -u github.com/sodefrin/bitflyer

requirements: go1.13

Usage

realtime api
using ticker
package main

import (
	"context"
	"log"
	"time"

	"github.com/sodefrin/bitflyer"
)

func main() {
	bf := bitflyer.NewBitflyer()
	realtime, err := bf.GetRealtimeAPIClient()
	if err != nil {
		log.Fatal(err)
	}

	ctx := context.Background()
	go realtime.Subscribe(ctx)

	ticker := time.NewTicker(time.Second)
	defer ticker.Stop()
	for {
		<-ticker.C
		mid, bids, ask := realtime.GetBoard()
		// you can recieve board data.
		// ...

		exs := realtime.GetExecutions(time.Second)
		// you can recieve execution data within 1 second.
		// ...
	}
}
using callback
package main

import (
	"context"
	"log"

	"github.com/sodefrin/bitflyer"
)

func main() {
	bf := bitflyer.NewBitflyer()
	realtime, err := bf.GetRealtimeAPIClient()
	if err != nil {
		log.Fatal(err)
	}

	ctx := context.Background()
	realtime.AddOnBoardCallback(ctx, func(mid float64, bids, asks []*bitflyer.Price) {
		// you can recieve board diff data by callback.
		// ...
	})
	realtime.AddOnExecutionCallback(ctx, func(exs []*bitflyer.Execution) {
		// you can recieve execution diff data by callback.
		// ...
	})

	// blocking.
	if err := realtime.Subscribe(ctx); err != nil {
		log.Fatal(err)
	}
}

parivate api

create order
package main

import (
	"log"

	"github.com/sodefrin/bitflyer"
)

func main() {
	bf := bitflyer.NewBitflyer()
	private, err := bf.PrivateAPIClient("your api key", "your api secret")
	if err != nil {
		log.Fatal(err)
	}

	if _, err = private.CreateOrder("BUY", 910000, 0.01, "LIMIT"); err != nil {
		log.Fatal(err)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidResponse = errors.New("invalid response")
View Source
var ErrInvalidStatusCode = errors.New("invalid status code")

Functions

This section is empty.

Types

type Bitflyer

type Bitflyer struct{}

func NewBitflyer

func NewBitflyer() *Bitflyer

func (*Bitflyer) GetPublicAPIClient

func (b *Bitflyer) GetPublicAPIClient() (*PublicAPIClient, error)

func (*Bitflyer) GetRealtimeAPIClient

func (b *Bitflyer) GetRealtimeAPIClient() (*RealtimeAPIClient, error)

func (*Bitflyer) PrivateAPIClient

func (b *Bitflyer) PrivateAPIClient(key, secret string) (*PrivateAPIClient, error)

type Board

type Board struct {
	// contains filtered or unexported fields
}

type Collateral

type Collateral struct {
	Collateral      float64 `json:"collateral"`
	OpenPositionPnl float64 `json:"open_position_pnl"`
	KeepRate        float64 `json:"keep_rate"`
}

type Execution

type Execution struct {
	ID                         int64     `json:"id"`
	Side                       string    `json:"side"`
	Price                      float64   `json:"price"`
	Size                       float64   `json:"size"`
	ExecDate                   string    `json:"exec_date"`
	Timestamp                  time.Time `json:"timestamp"`
	BuyChildOrderAcceptanceID  string    `json:"buy_child_order_acceptance_id"`
	SellChildOrderAcceptanceID string    `json:"sell_child_order_acceptance_id"`
}

type Order

type Order struct {
	ID                     int64   `json:"id"`
	ChildOrderID           string  `json:"child_order_id"`
	ProductCode            string  `json:"product_code"`
	Side                   string  `json:"side"`
	ChildOrderType         string  `json:"child_order_type"`
	Price                  float64 `json:"price"`
	AveragePrice           float64 `json:"average_price"`
	Size                   float64 `json:"size"`
	ChildOrderState        string  `json:"child_order_state"`
	ExpireDate             string  `json:"expire_date"`
	ChildOrderDate         string  `json:"child_order_date"`
	ChildOrderAcceptanceID string  `json:"child_order_acceptance_id"`
	OutstandingSize        float64 `json:"outstanding_size"`
	CancelSize             float64 `json:"cancel_size"`
	ExecutedSize           float64 `json:"executed_size"`
	TotalCommission        float64 `json:"total_commission"`
}

type Position

type Position struct {
	Side  string  `json:"side"`
	Price float64 `json:"price"`
	Size  float64 `json:"size"`
}

type Price

type Price struct {
	Price float64 `json:"price"`
	Size  float64 `json:"size"`
}

type PrivateAPIClient

type PrivateAPIClient struct {
	// contains filtered or unexported fields
}

func (*PrivateAPIClient) CancelAllOrder

func (p *PrivateAPIClient) CancelAllOrder(product_code string) error

func (*PrivateAPIClient) CancelOrder

func (p *PrivateAPIClient) CancelOrder(product_code string, id string) error

func (*PrivateAPIClient) CreateOrder

func (p *PrivateAPIClient) CreateOrder(product_code string, side string, price, size float64, typ string) (string, error)

func (*PrivateAPIClient) GetCollateral

func (p *PrivateAPIClient) GetCollateral() (*Collateral, error)

func (*PrivateAPIClient) GetOrder

func (p *PrivateAPIClient) GetOrder(product_code string, id string) (*Order, error)

func (*PrivateAPIClient) GetPositions

func (p *PrivateAPIClient) GetPositions(product_code string) ([]*Position, error)

type PublicAPIClient

type PublicAPIClient struct{}

func (*PublicAPIClient) GetTicker

func (p *PublicAPIClient) GetTicker(productCode string) (*Ticker, error)

type RealtimeAPIClient

type RealtimeAPIClient struct {
	// contains filtered or unexported fields
}

func (*RealtimeAPIClient) AddOnBoardCallback

func (r *RealtimeAPIClient) AddOnBoardCallback(ctx context.Context, callback func(mid float64, bids []*Price, asks []*Price))

func (*RealtimeAPIClient) AddOnExecutionCallback

func (r *RealtimeAPIClient) AddOnExecutionCallback(ctx context.Context, callback func([]*Execution))

func (*RealtimeAPIClient) Close

func (r *RealtimeAPIClient) Close() error

func (*RealtimeAPIClient) GetBoard

func (r *RealtimeAPIClient) GetBoard() (float64, []*Price, []*Price)

func (*RealtimeAPIClient) GetExecutions

func (r *RealtimeAPIClient) GetExecutions(duration time.Duration) []*Execution

func (*RealtimeAPIClient) Subscribe

func (r *RealtimeAPIClient) Subscribe(ctx context.Context) error

type Ticker

type Ticker struct {
	ProductCode     string    `json:"product_code"`
	Timestamp       time.Time `json:"timestamp"`
	TickID          int       `json:"tick_id"`
	BestBid         float64   `json:"best_bid"`
	BestAsk         float64   `json:"best_ask"`
	BestBidSize     float64   `json:"best_bid_size"`
	BestAskSize     float64   `json:"best_ask_size"`
	TotalBidDepth   float64   `json:"total_bid_depth"`
	TotalAskDepth   float64   `json:"total_ask_depth"`
	Ltp             float64   `json:"ltp"`
	Volume          float64   `json:"volume"`
	VolumeByProduct float64   `json:"volume_by_product"`
}

Jump to

Keyboard shortcuts

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