bitflyer

package
v0.0.0-...-eba6480 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2020 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EXCHANGE        = "bitflyer"
	RECONNECTMINUTE = 12
	DELAYTHRESHHOLD = 2000 * time.Millisecond

	// ORDER
	WAITEXECUTE = 1800 // second

	// LOGIC workers
	WORKERS        = 10
	WORKERMMPROFIT = 1
	WORKERMMBASIC  = 1

	// CHECKRESOUCEPERIOD websocket executionsの集計(期間内最大変動などを取得)
	CHECKRESOUCEPERIOD = 3
	// MMBASICCANCELORDER is basic market make orderの板乗り時間(±Delay, ±PingTime)でCHECKRESOUCEPERIOD*MMBASICCANCELORDER秒を基本とする
	MMBASICCANCELORDER = 3
)
View Source
const (
	// AGGPERIOD Aggregation period
	AGGPERIOD = 15
	// DBTABLEORDERS 注文(約定: IsDone)
	DBTABLEORDERS = "orders"
	// DBTABLEORDERSFORTEST 注文(約定: IsDone)
	DBTABLEORDERSFORTEST = "orders_test"
	// DBTABLEORDERSINFO 約定集計(約定率やbid/askの傾き、最大保持枚数)
	DBTABLEORDERSINFO = "orders_info"
)
View Source
const (
	DISCORDPREFIX = "."
)

Variables

View Source
var (
	BUYPRICE, SELLPRICE float64
)
View Source
var (
	TANHTENSION = 0.01
)

Functions

This section is empty.

Types

type Client

type Client struct {
	DB      *db.Client
	Discord *discordgo.Session

	// Event駆動用
	Event chan interface{}

	C           *v1.Client
	Controllers *Controllers
	Setting     *config.Setting

	// API Limit
	Public  *v1.Limit
	Private *v1.Limit

	// Executions
	E *Executes
	O *Orders

	// Logic 可否
	Logics *Logics
	// Logic 発注開始
	Logic chan Logicer

	Logger *logrus.Entry
}

func New

func New(ldb *db.Client, l *logrus.Logger, d *discordgo.Session, s map[string]interface{}) *Client

func (*Client) CancelByID

func (p *Client) CancelByID(id string) (int, error)

CancelByID is cancel by orderID

func (*Client) Check

func (p *Client) Check()

Check gets resorse and culc

func (*Client) ClosePositions

func (p *Client) ClosePositions() (*Order, error)

func (*Client) Connect

func (p *Client) Connect()

func (*Client) ConnectForPrivate

func (p *Client) ConnectForPrivate()

ConnectForPrivate check order status

func (*Client) CulcForward

func (p *Client) CulcForward()

CulcForward culc orders in this running

func (*Client) GetOrders

func (p *Client) GetOrders(prefix string, start, end time.Time) ([]Order, error)

GetOrders get orders before start to end time

func (*Client) GetOrdersInfo

func (p *Client) GetOrdersInfo(prefix string, start, end time.Time) ([]OrdersInfo, error)

GetOrdersInfo aggrigate orders

func (*Client) IgniteBasic

func (p *Client) IgniteBasic()

IgniteBasic ignition to Logic

func (*Client) Interactive

func (p *Client) Interactive()

func (*Client) LogicChecker

func (p *Client) LogicChecker()

LogicChecker is check for ignition, par sec.

func (*Client) OrderBySimple

func (p *Client) OrderBySimple(isMarket bool, side int, price, size float64, timeInForce *string) (*Order, error)

OrderBySimple is order for bitflyer api

func (*Client) OrderGroup

func (p *Client) OrderGroup()

OrderGroup LogicIgnition受信用

func (*Client) SetError

func (p *Client) SetError(isWait bool, err error)

SetError is log & time.Sleep

type Controller

type Controller struct {
	IsDo  bool
	Count int
	Limit int
	// contains filtered or unexported fields
}

Controller ロジックの稼働数量管理

func (*Controller) Close

func (p *Controller) Close()

Close pull buck count

func (*Controller) IsOK

func (p *Controller) IsOK() bool

IsOK check worker limit, if ok subtracte count

type Controllers

type Controllers struct {
	Profit  *Controller
	Basic   *Controller
	Special *Controller
	VPIN    *Controller
	Swing   *Controller
}

Controllers is 各種ロジックの同時稼働数管理

type Executes

type Executes struct {
	sync.RWMutex

	// BestAsk/Bid
	IsBuy     bool
	Length    int
	Price     float64
	LastPrice float64
	BestAsk   float64
	BestBid   float64

	// 期間内高値安値
	IsRise    int
	High, Low float64

	// 出来高
	Volume float64

	// n秒足乖離(加速度)
	Prices      []float64
	Volumes     []float64
	PricesPast  []float64
	VolumesPast []float64

	Delay     time.Duration
	DelayMean time.Duration
}

Executes is 一般約定情報

func NewExecutes

func NewExecutes() *Executes

NewExecutes is new Executes

func (*Executes) ChangeInTerm

func (p *Executes) ChangeInTerm() float64

ChangeInTerm 期間内変化量

func (*Executes) ChangePrice

func (p *Executes) ChangePrice() float64

ChangePrice is changed price 1tick ws executions

func (*Executes) Reset

func (p *Executes) Reset()

Reset is create mean

func (*Executes) Set

func (p *Executes) Set(e []executions.Execution)

Set is set executions to struct

func (*Executes) Spread

func (p *Executes) Spread() float64

Spread is culc spread

type LogicByBasic

type LogicByBasic struct {
	Name string
}

func (*LogicByBasic) BackTest

func (logic *LogicByBasic) BackTest(p *Client, side int, price, size float64) error

BackTest check execution, and set database

func (*LogicByBasic) Order

func (logic *LogicByBasic) Order(p *Client)

Order do order and execution for MM Basic

type Logicer

type Logicer interface {
	Order(p *Client)
}

Logicer ロジックごとの型判別で処理を分ける

type Logics

type Logics struct {
	MMBasic   bool
	MMSpecial bool
	VPIN      bool
}

type Order

type Order struct {
	OrderID string
	Side    string
	Price   float64
	Size    float64
	IsDone  bool

	// 注文からAPI返り値までの時間
	OnAccept time.Duration
}

Order informations

type Orders

type Orders struct {
	LastBuyOnAccept  float64
	LastSellOnAccept float64

	Orders    *sync.Map
	Cancels   *sync.Map
	Positions *sync.Map

	Result chan string
}

Orders is orders/positions struct

func NewOrders

func NewOrders() *Orders

NewOrders managed Orders&Poistions

func (*Orders) Check

func (p *Orders) Check(e []executions.Execution)

Check is check ws.Exec by orderID

func (*Orders) CheckByPrivateWs

func (p *Orders) CheckByPrivateWs(childorders []jsonrpc.WsResponceForChildEvent)

CheckByPrivateWs get cancel and expire, delete order in orders and set cancels

func (*Orders) GetOrderSize

func (p *Orders) GetOrderSize(side int, sizes []float64) (bool, float64)

GetOrderSize is new Size adjustor include go-bitflyer private positions

func (*Orders) IsCancel

func (p *Orders) IsCancel(o *Order) bool

IsCancel is order cancel done

func (*Orders) Set

func (p *Orders) Set(o Order)

Set is {orderID: order}でmap

func (*Orders) Size

func (p *Orders) Size() (size float64)

Size 建玉枚数を正負枚数で返す

type OrdersInfo

type OrdersInfo struct {
	Length                     int
	Rate                       float64
	RateBid, RateAsk           float64
	Max                        float64
	AvgBid, AvgAsk             float64
	VolumeBid, VolumeAsk       float64
	OrdersizeBid, OrdersizeAsk float64

	ExecTime  time.Duration
	CreatedAt time.Time
}

func (*OrdersInfo) Columns

func (p *OrdersInfo) Columns() string

Columns return string, header columns

func (*OrdersInfo) String

func (p *OrdersInfo) String() string

String is print for human

Jump to

Keyboard shortcuts

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