binance

package module
Version: v0.0.0-...-f051f2e Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2020 License: MIT Imports: 17 Imported by: 0

README

binance-api-client

Documentation

Index

Constants

View Source
const (
	SideTypeBuy  SideType = "BUY"
	SideTypeSell SideType = "SELL"

	OrderTypeLimit           OrderType = "LIMIT"
	OrderTypeMarket          OrderType = "MARKET"
	OrderTypeLimitMaker      OrderType = "LIMIT_MAKER"
	OrderTypeStopLoss        OrderType = "STOP_LOSS"
	OrderTypeStopLossLimit   OrderType = "STOP_LOSS_LIMIT"
	OrderTypeTakeProfit      OrderType = "TAKE_PROFIT"
	OrderTypeTakeProfitLimit OrderType = "TAKE_PROFIT_LIMIT"

	OrderStatusTypeNew             OrderStatusType = "NEW"
	OrderStatusTypePartiallyFilled OrderStatusType = "PARTIALLY_FILLED"
	OrderStatusTypeFilled          OrderStatusType = "FILLED"
	OrderStatusTypeCanceled        OrderStatusType = "CANCELED"
	OrderStatusTypePendingCancel   OrderStatusType = "PENDING_CANCEL"
	OrderStatusTypeRejected        OrderStatusType = "REJECTED"
	OrderStatusTypeExpired         OrderStatusType = "EXPIRED"

	OCOListStatusTypeResponce    OCOListStatusType = "RESPONSE"
	OCOListStatusTypeExecStarted OCOListStatusType = "EXEC_STARTED"
	OCOListStatusTypeAllDone     OCOListStatusType = "ALL_DONE"

	OCOListOrderStatusTypeExecuting OCOListOrderStatusType = "EXECUTING"
	OCOListOrderStatusTypeAllDone   OCOListOrderStatusType = "ALL_DONE"
	OCOListOrderStatusTypeReject    OCOListOrderStatusType = "REJECT"

	TimeInForceTypeGTC TimeInForceType = "GTC"
	TimeInForceTypeIOC TimeInForceType = "IOC"
	TimeInForceTypeFOK TimeInForceType = "FOK"

	NewOrderRespTypeACK    NewOrderRespType = "ACK"
	NewOrderRespTypeRESULT NewOrderRespType = "RESULT"
	NewOrderRespTypeFULL   NewOrderRespType = "FULL"
)

Variables

View Source
var (

	//baseFutureURL   = "wss://fstream.binance.com/ws"
	//combinedBaseURL = "wss://stream.binance.com:9443/stream?streams="
	// WebsocketTimeout is an interval for sending ping/pong messages if WebsocketKeepalive is enabled
	WebsocketTimeout = time.Second * 60
	// WebsocketKeepalive enables sending ping/pong messages to check the connection stability
	WebsocketKeepalive = false
)

Functions

func FormatTimestamp

func FormatTimestamp(t time.Time) int64

FormatTimestamp formats a time into Unix timestamp in milliseconds, as requested by Binance.

func WsBookTickerServe

func WsBookTickerServe(symbol string, handler WsBookTickerHandler, errHandler ErrHandler) (doneC, stopC chan struct{}, err error)

WsBookTickerServe serve websocket partial depth handler with a symbol

Types

type CancelOCOResponse

type CancelOCOResponse struct {
	OrderListID       int64                  `json:"orderListId"`
	ContingencyType   string                 `json:"contingencyType"`
	ListStatusType    OCOListStatusType      `json:"listStatusType"`
	ListOrderStatus   OCOListOrderStatusType `json:"listOrderStatus"`
	ListClientOrderID string                 `json:"listClientOrderId"`
	TransactionTime   int64                  `json:"transactionTime"`
	Symbol            string                 `json:"symbol"`
	Orders            []*OCOOrder            `json:"orders"`
	OrderReports      []*OCOOrderReport      `json:"orderReports"`
}

CancelOCOResponse define response of canceling OCO order

type CancelOCOService

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

CancelOCOService cancel an OCO order

func (*CancelOCOService) Do

func (s *CancelOCOService) Do(ctx context.Context, opts ...RequestOption) (res *CancelOCOResponse, err error)

Do send request

func (*CancelOCOService) ListClientOrderID

func (s *CancelOCOService) ListClientOrderID(listClientOrderID string) *CancelOCOService

ListClientOrderID set listClientOrderID

func (*CancelOCOService) NewClientOrderID

func (s *CancelOCOService) NewClientOrderID(newClientOrderID string) *CancelOCOService

NewClientOrderID set newClientOrderID

func (*CancelOCOService) OrderListID

func (s *CancelOCOService) OrderListID(orderListID int64) *CancelOCOService

OrderListID set orderListID

func (*CancelOCOService) Symbol

func (s *CancelOCOService) Symbol(symbol string) *CancelOCOService

Symbol set symbol

type Client

type Client struct {
	APIKey     string
	SecretKey  string
	BaseURL    string
	UserAgent  string
	HTTPClient *http.Client
	Debug      bool
	Logger     *log.Logger
	TimeOffset int64
	// contains filtered or unexported fields
}

Client define API client

func NewClient

func NewClient(apiKey, secretKey string) *Client

NewClient initialize an API client instance with API key and secret key. You should always call this function before using this SDK. Services will be created by the form client.NewXXXService().

func (*Client) NewCancelOCOService

func (c *Client) NewCancelOCOService() *CancelOCOService

NewCancelOCOService init cancel order service

func (*Client) NewCreateOCOService

func (c *Client) NewCreateOCOService() *CreateOCOService

NewCreateOCOService init creating OCO service

func (*Client) NewGetOCOService

func (c *Client) NewGetOCOService() *GetOCOService

NewGetOCOService init get order service

func (*Client) NewListOCOService

func (c *Client) NewListOCOService() *ListOCOService

NewListOCOService init listing orders service

func (*Client) NewListOpenOCOService

func (c *Client) NewListOpenOCOService() *ListOpenOCOService

NewListOpenOCOService init list open orders service

func (*Client) NewPingService

func (c *Client) NewPingService() *PingService

NewPingService init ping service

func (*Client) NewServerTimeService

func (c *Client) NewServerTimeService() *ServerTimeService

NewServerTimeService init server time service

func (*Client) NewSetServerTimeService

func (c *Client) NewSetServerTimeService() *SetServerTimeService

NewSetServerTimeService init set server time service

type CreateOCOResponse

type CreateOCOResponse struct {
	OrderListID       int64                  `json:"orderListId"`
	ContingencyType   string                 `json:"contingencyType"`
	ListStatusType    OCOListStatusType      `json:"listStatusType"`
	ListOrderStatus   OCOListOrderStatusType `json:"listOrderStatus"`
	ListClientOrderID string                 `json:"listClientOrderId"`
	TransactionTime   int64                  `json:"transactionTime"`
	Symbol            string                 `json:"symbol"`
	Orders            []*OCOOrder            `json:"orders"`
	OrderReports      []*OCOOrderReport      `json:"orderReports"`
}

CreateOCOResponse define create OCO order response

type CreateOCOService

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

CreateOCOService create OCO order

func (*CreateOCOService) Do

func (s *CreateOCOService) Do(ctx context.Context, opts ...RequestOption) (res *CreateOCOResponse, err error)

Do send request

func (*CreateOCOService) LimitClientOrderID

func (s *CreateOCOService) LimitClientOrderID(limitClientOrderID string) *CreateOCOService

LimitClientOrderID set limitClientOrderID

func (*CreateOCOService) NewOrderRespType

func (s *CreateOCOService) NewOrderRespType(newOrderRespType NewOrderRespType) *CreateOCOService

NewOrderRespType set icebergQuantity

func (*CreateOCOService) Price

func (s *CreateOCOService) Price(price string) *CreateOCOService

Price set price

func (*CreateOCOService) Quantity

func (s *CreateOCOService) Quantity(quantity string) *CreateOCOService

Quantity set quantity

func (*CreateOCOService) Side

Side set side

func (*CreateOCOService) StopClientOrderID

func (s *CreateOCOService) StopClientOrderID(stopClientOrderID string) *CreateOCOService

StopClientOrderID set stopClientOrderID

func (*CreateOCOService) StopIcebergQty

func (s *CreateOCOService) StopIcebergQty(stopIcebergQty string) *CreateOCOService

StopIcebergQty set stop limit price

func (*CreateOCOService) StopLimitPrice

func (s *CreateOCOService) StopLimitPrice(stopLimitPrice string) *CreateOCOService

StopLimitPrice set stop limit price

func (*CreateOCOService) StopLimitTimeInForce

func (s *CreateOCOService) StopLimitTimeInForce(stopLimitTimeInForce TimeInForceType) *CreateOCOService

StopLimitTimeInForce set stopLimitTimeInForce

func (*CreateOCOService) StopPrice

func (s *CreateOCOService) StopPrice(stopPrice string) *CreateOCOService

StopPrice set stop price

func (*CreateOCOService) Symbol

func (s *CreateOCOService) Symbol(symbol string) *CreateOCOService

Symbol set symbol

type ErrHandler

type ErrHandler func(err error)

ErrHandler handles errors

type GetOCOService

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

GetOCOService get an OCO order

func (*GetOCOService) Do

func (s *GetOCOService) Do(ctx context.Context, opts ...RequestOption) (res *OCOResponse, err error)

Do send request

func (*GetOCOService) OrderListID

func (s *GetOCOService) OrderListID(orderListID int64) *GetOCOService

OrderListID set orderListID

func (*GetOCOService) OrigClientOrderID

func (s *GetOCOService) OrigClientOrderID(origClientOrderID string) *GetOCOService

OrigClientOrderID set listClientOrderID

type ListOCOService

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

ListOCOService all account orders; active, canceled, or filled

func (*ListOCOService) Do

func (s *ListOCOService) Do(ctx context.Context, opts ...RequestOption) (res []*OCOResponse, err error)

Do send request

func (*ListOCOService) EndTime

func (s *ListOCOService) EndTime(endTime int64) *ListOCOService

EndTime set endtime

func (*ListOCOService) FromID

func (s *ListOCOService) FromID(fromID int64) *ListOCOService

FromID set orderListID

func (*ListOCOService) Limit

func (s *ListOCOService) Limit(limit int) *ListOCOService

Limit set limit

func (*ListOCOService) StartTime

func (s *ListOCOService) StartTime(startTime int64) *ListOCOService

StartTime set starttime

func (*ListOCOService) Symbol

func (s *ListOCOService) Symbol(symbol string) *ListOCOService

Symbol set symbol

type ListOpenOCOService

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

ListOpenOCOService list opened OCO orders

func (*ListOpenOCOService) Do

func (s *ListOpenOCOService) Do(ctx context.Context, opts ...RequestOption) (res []*OCOResponse, err error)

Do send request

type NewOrderRespType

type NewOrderRespType string

NewOrderRespType define response JSON verbosity

type OCOListOrderStatusType

type OCOListOrderStatusType string

type OCOListStatusType

type OCOListStatusType string

type OCOOrder

type OCOOrder struct {
	Symbol        string `json:"symbol"`
	OrderID       int64  `json:"orderId"`
	ClientOrderID string `json:"clientOrderId"`
}

OCOOrder may be returned in an array of OCOOrder in a CreateOCOResponse.

type OCOOrderReport

type OCOOrderReport struct {
	Symbol                   string          `json:"symbol"`
	OrderID                  int64           `json:"orderId"`
	OrderListID              int64           `json:"orderListId"`
	ClientOrderID            string          `json:"clientOrderId"`
	TransactionTime          int64           `json:"transactionTime"`
	Price                    string          `json:"price"`
	OrigQuantity             string          `json:"origQty"`
	ExecutedQuantity         string          `json:"executedQty"`
	CummulativeQuoteQuantity string          `json:"cummulativeQuoteQty"`
	Status                   OrderStatusType `json:"status"`
	TimeInForce              TimeInForceType `json:"timeInForce"`
	Type                     OrderType       `json:"type"`
	Side                     SideType        `json:"side"`
	StopPrice                string          `json:"stopPrice"`
}

OCOOrderReport may be returned in an array of OCOOrderReport in a CreateOCOResponse.

type OCOResponse

type OCOResponse struct {
	OrderListID       int64                  `json:"orderListId"`
	ContingencyType   string                 `json:"contingencyType"`
	ListStatusType    OCOListStatusType      `json:"listStatusType"`
	ListOrderStatus   OCOListOrderStatusType `json:"listOrderStatus"`
	ListClientOrderID string                 `json:"listClientOrderId"`
	TransactionTime   int64                  `json:"transactionTime"`
	Symbol            string                 `json:"symbol"`
	Orders            []*OCOOrder            `json:"orders"`
}

OCOResponse define OCO order response

type OrderStatusType

type OrderStatusType string

OrderStatusType define order status type

type OrderType

type OrderType string

OrderType define order type

type PingService

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

PingService ping server

func (*PingService) Do

func (s *PingService) Do(ctx context.Context, opts ...RequestOption) (err error)

Do send request

type RequestOption

type RequestOption func(*request)

RequestOption define option type for request

func WithRecvWindow

func WithRecvWindow(recvWindow int64) RequestOption

WithRecvWindow set recvWindow param for the request

type ServerTimeService

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

ServerTimeService get server time

func (*ServerTimeService) Do

func (s *ServerTimeService) Do(ctx context.Context, opts ...RequestOption) (serverTime int64, err error)

Do send request

type SetServerTimeService

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

SetServerTimeService set server time

func (*SetServerTimeService) Do

func (s *SetServerTimeService) Do(ctx context.Context, opts ...RequestOption) (timeOffset int64, err error)

Do send request

type SideType

type SideType string

SideType define side type of order

type TimeInForceType

type TimeInForceType string

TimeInForceType define time in force type of order

type WsBookTickerEvent

type WsBookTickerEvent struct {
	UpdateID    int64  `json:"u"`
	Symbol      string `json:"s"`
	BidPrice    string `json:"b"`
	BidQuantity string `json:"B"`
	AskPrice    string `json:"a"`
	AskQuantity string `json:"A"`
}

WsBookTickerEvent define websocket individual book ticker event

type WsBookTickerHandler

type WsBookTickerHandler func(event *WsBookTickerEvent)

WsBookTickerHandler handle websocket partial depth event

type WsConfig

type WsConfig struct {
	Endpoint string
}

WsConfig webservice configuration

type WsHandler

type WsHandler func(message []byte)

WsHandler handle raw websocket message

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL