binance

package
v1.58.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: AGPL-3.0 Imports: 25 Imported by: 10

Documentation

Index

Constants

View Source
const BNB = "BNB"
View Source
const BinanceTestBaseURL = "https://testnet.binance.vision"
View Source
const BinanceUSBaseURL = "https://api.binance.us"
View Source
const BinanceUSWebSocketURL = "wss://stream.binance.us:9443"
View Source
const DefaultDepthLimit = 5000
View Source
const FutureTestBaseURL = "https://testnet.binancefuture.com"
View Source
const FuturesWebSocketTestURL = "wss://stream.binancefuture.com"
View Source
const FuturesWebSocketURL = "wss://fstream.binance.com"
View Source
const WebSocketTestURL = "wss://testnet.binance.vision"
View Source
const WebSocketURL = "wss://stream.binance.com:9443"

Variables

View Source
var SupportedIntervals = map[types.Interval]int{
	types.Interval1s:  1,
	types.Interval1m:  1 * 60,
	types.Interval5m:  5 * 60,
	types.Interval15m: 15 * 60,
	types.Interval30m: 30 * 60,
	types.Interval1h:  60 * 60,
	types.Interval2h:  60 * 60 * 2,
	types.Interval4h:  60 * 60 * 4,
	types.Interval6h:  60 * 60 * 6,
	types.Interval12h: 60 * 60 * 12,
	types.Interval1d:  60 * 60 * 24,
	types.Interval3d:  60 * 60 * 24 * 3,
	types.Interval1w:  60 * 60 * 24 * 7,
}

in seconds

Functions

This section is empty.

Types

type AccountConfigUpdateEvent added in v1.21.1

type AccountConfigUpdateEvent struct {
	EventBase
	Transaction int64 `json:"T"`

	// When the leverage of a trade pair changes,
	// the payload will contain the object ac to represent the account configuration of the trade pair,
	// where s represents the specific trade pair and l represents the leverage
	AccountConfig struct {
		Symbol   string           `json:"s"`
		Leverage fixedpoint.Value `json:"l"`
	} `json:"ac"`

	// When the user Multi-Assets margin mode changes the payload will contain the object ai representing the user account configuration,
	// where j represents the user Multi-Assets margin mode
	MarginModeConfig struct {
		MultiAssetsMode bool `json:"j"`
	} `json:"ai"`
}

type AccountUpdate added in v1.21.1

type AccountUpdate struct {
	// m: DEPOSIT WITHDRAW
	// ORDER FUNDING_FEE
	// WITHDRAW_REJECT ADJUSTMENT
	// INSURANCE_CLEAR
	// ADMIN_DEPOSIT ADMIN_WITHDRAW
	// MARGIN_TRANSFER MARGIN_TYPE_CHANGE
	// ASSET_TRANSFER
	// OPTIONS_PREMIUM_FEE OPTIONS_SETTLE_PROFIT
	// AUTO_EXCHANGE
	// COIN_SWAP_DEPOSIT COIN_SWAP_WITHDRAW
	EventReasonType AccountUpdateEventReasonType `json:"m"`
	Balances        []FuturesStreamBalance       `json:"B,omitempty"`
	Positions       []FuturesStreamPosition      `json:"P,omitempty"`
}

type AccountUpdateEvent added in v1.21.1

type AccountUpdateEvent struct {
	EventBase
	Transaction   int64         `json:"T"`
	AccountUpdate AccountUpdate `json:"a"`
}

AccountUpdateEvent is only used in the futures user data stream

type AccountUpdateEventReasonType added in v1.45.0

type AccountUpdateEventReasonType string
const (
	AccountUpdateEventReasonDeposit          AccountUpdateEventReasonType = "DEPOSIT"
	AccountUpdateEventReasonWithdraw         AccountUpdateEventReasonType = "WITHDRAW"
	AccountUpdateEventReasonOrder            AccountUpdateEventReasonType = "ORDER"
	AccountUpdateEventReasonFundingFee       AccountUpdateEventReasonType = "FUNDING_FEE"
	AccountUpdateEventReasonMarginTransfer   AccountUpdateEventReasonType = "MARGIN_TRANSFER"
	AccountUpdateEventReasonMarginTypeChange AccountUpdateEventReasonType = "MARGIN_TYPE_CHANGE"
	AccountUpdateEventReasonAssetTransfer    AccountUpdateEventReasonType = "ASSET_TRANSFER"
	AccountUpdateEventReasonAdminDeposit     AccountUpdateEventReasonType = "ADMIN_DEPOSIT"
	AccountUpdateEventReasonAdminWithdraw    AccountUpdateEventReasonType = "ADMIN_WITHDRAW"
)

type AggTradeEvent added in v1.43.0

type AggTradeEvent struct {
	EventBase
	Symbol         string           `json:"s"`
	Quantity       fixedpoint.Value `json:"q"`
	Price          fixedpoint.Value `json:"p"`
	FirstTradeId   int64            `json:"f"`
	LastTradeId    int64            `json:"l"`
	OrderTradeTime int64            `json:"T"`
	IsMaker        bool             `json:"m"`
	Dummy          bool             `json:"M"`
}

func (*AggTradeEvent) Trade added in v1.43.0

func (e *AggTradeEvent) Trade() types.Trade

type Balance

type Balance struct {
	Asset  string           `json:"a"`
	Free   fixedpoint.Value `json:"f"`
	Locked fixedpoint.Value `json:"l"`
}

outboundAccountInfo

{
  "e": "outboundAccountInfo",   // KLineEvent type
  "E": 1499405658849,           // KLineEvent time
  "m": 0,                       // Maker commission rate (bips)
  "t": 0,                       // Taker commission rate (bips)
  "b": 0,                       // Buyer commission rate (bips)
  "s": 0,                       // Seller commission rate (bips)
  "T": true,                    // Can trade?
  "W": true,                    // Can withdraw?
  "D": true,                    // Can deposit?
  "u": 1499405658848,           // Time of last account update
  "B": [                        // AccountBalances array
    {
      "a": "LTC",               // Asset
      "f": "17366.18538083",    // Free amount
      "l": "0.00000000"         // Locked amount
    },
    {
      "a": "BTC",
      "f": "10537.85314051",
      "l": "2.19464093"
    },
    {
      "a": "ETH",
      "f": "17902.35190619",
      "l": "0.00000000"
    },
    {
      "a": "BNC",
      "f": "1114503.29769312",
      "l": "0.00000000"
    },
    {
      "a": "NEO",
      "f": "0.00000000",
      "l": "0.00000000"
    }
  ],
  "P": [                       // Account Permissions
        "SPOT"
  ]
}

type BalanceUpdateEvent

type BalanceUpdateEvent struct {
	EventBase

	Asset     string                     `json:"a"`
	Delta     fixedpoint.Value           `json:"d"`
	ClearTime types.MillisecondTimestamp `json:"T"`
}

event: balanceUpdate

Balance Update occurs during the following:

Deposits or withdrawals from the account Transfer of funds between accounts (e.g. Spot to Margin)

{
  "e": "balanceUpdate",         //KLineEvent Type
  "E": 1573200697110,           //KLineEvent Time
  "a": "BTC",                   //Asset
  "d": "100.00000000",          //Balance Delta
  "T": 1573200697068            //Clear Time
}

This event is only for Spot

func (*BalanceUpdateEvent) SlackAttachment added in v1.48.0

func (e *BalanceUpdateEvent) SlackAttachment() slack.Attachment

type BookTickerEvent added in v1.21.0

type BookTickerEvent struct {
	EventBase
	UpdateID int64            `json:"u"`
	Symbol   string           `json:"s"`
	Buy      fixedpoint.Value `json:"b"`
	BuySize  fixedpoint.Value `json:"B"`
	Sell     fixedpoint.Value `json:"a"`
	SellSize fixedpoint.Value `json:"A"`
}
{
  "u":400900217,     // order book updateId
  "s":"BNBUSDT",     // symbol
  "b":"25.35190000", // best bid price
  "B":"31.21000000", // best bid qty
  "a":"25.36520000", // best ask price
  "A":"40.66000000"  // best ask qty
}

func (*BookTickerEvent) BookTicker added in v1.21.0

func (k *BookTickerEvent) BookTicker() types.BookTicker

type BorrowRepayType added in v1.57.0

type BorrowRepayType interface {
	types.MarginLoan | types.MarginRepay
}

type ContinuousKLineEvent added in v1.18.1

type ContinuousKLineEvent struct {
	EventBase
	Symbol string `json:"ps"`

	KLine KLine `json:"k,omitempty"`
	// contains filtered or unexported fields
}

type DepthEntry

type DepthEntry struct {
	PriceLevel fixedpoint.Value
	Quantity   fixedpoint.Value
}

type DepthEvent

type DepthEvent struct {
	EventBase

	Symbol        string `json:"s"`
	FirstUpdateID int64  `json:"U"`
	FinalUpdateID int64  `json:"u"`

	Bids types.PriceVolumeSlice `json:"b"`
	Asks types.PriceVolumeSlice `json:"a"`
}

func (*DepthEvent) OrderBook

func (e *DepthEvent) OrderBook() (book types.SliceOrderBook, err error)

func (*DepthEvent) String added in v1.17.0

func (e *DepthEvent) String() (o string)

type EventBase

type EventBase struct {
	Event string                     `json:"e"` // event name
	Time  types.MillisecondTimestamp `json:"E"` // event time
}

type EventType added in v1.57.0

type EventType = string
const (
	EventTypeKLine                   EventType = "kline"
	EventTypeOutboundAccountPosition EventType = "outboundAccountPosition"
	EventTypeOutboundAccountInfo     EventType = "outboundAccountInfo"
	EventTypeBalanceUpdate           EventType = "balanceUpdate"
	EventTypeExecutionReport         EventType = "executionReport"
	EventTypeDepthUpdate             EventType = "depthUpdate"
	EventTypeListenKeyExpired        EventType = "listenKeyExpired"
	EventTypeTrade                   EventType = "trade"
	EventTypeAggTrade                EventType = "aggTrade"
	EventTypeForceOrder              EventType = "forceOrder"

	// Our side defines the following event types since binance doesn't
	// define the event name from the server messages.
	//
	EventTypeBookTicker   EventType = "bookTicker"
	EventTypePartialDepth EventType = "partialDepth"
)

type Exchange

type Exchange struct {
	types.MarginSettings
	types.FuturesSettings
	// contains filtered or unexported fields
}

func New

func New(key, secret string) *Exchange

func (*Exchange) BorrowMarginAsset added in v1.31.0

func (e *Exchange) BorrowMarginAsset(ctx context.Context, asset string, amount fixedpoint.Value) error

func (*Exchange) CancelOrders

func (e *Exchange) CancelOrders(ctx context.Context, orders ...types.Order) (err error)

func (*Exchange) CancelReplace added in v1.43.0

func (e *Exchange) CancelReplace(ctx context.Context, cancelReplaceMode types.CancelReplaceModeType, o types.Order) (*types.Order, error)

func (*Exchange) DefaultFeeRates added in v1.33.0

func (e *Exchange) DefaultFeeRates() types.ExchangeFee

DefaultFeeRates returns the Binance VIP 0 fee schedule See also https://www.binance.com/en/fee/schedule See futures fee at: https://www.binance.com/en/fee/futureFee

func (*Exchange) GetFuturesClient added in v1.45.0

func (e *Exchange) GetFuturesClient() *binanceapi.FuturesRestClient

func (*Exchange) IsSupportedInterval added in v1.38.0

func (e *Exchange) IsSupportedInterval(interval types.Interval) bool

func (*Exchange) Name

func (e *Exchange) Name() types.ExchangeName

func (*Exchange) NewStream

func (e *Exchange) NewStream() types.Stream

func (*Exchange) PlatformFeeCurrency

func (e *Exchange) PlatformFeeCurrency() string

func (*Exchange) QueryAccount

func (e *Exchange) QueryAccount(ctx context.Context) (*types.Account, error)

func (*Exchange) QueryAccountBalances

func (e *Exchange) QueryAccountBalances(ctx context.Context) (types.BalanceMap, error)

func (*Exchange) QueryAveragePrice

func (e *Exchange) QueryAveragePrice(ctx context.Context, symbol string) (fixedpoint.Value, error)

func (*Exchange) QueryClosedOrders

func (e *Exchange) QueryClosedOrders(
	ctx context.Context, symbol string, since, until time.Time, lastOrderID uint64,
) (orders []types.Order, err error)

func (*Exchange) QueryCrossMarginAccount added in v1.40.0

func (e *Exchange) QueryCrossMarginAccount(ctx context.Context) (*types.Account, error)

func (*Exchange) QueryDepositHistory

func (e *Exchange) QueryDepositHistory(ctx context.Context, asset string, since, until time.Time) (allDeposits []types.Deposit, err error)

func (*Exchange) QueryDepth added in v1.21.0

func (e *Exchange) QueryDepth(ctx context.Context, symbol string) (snapshot types.SliceOrderBook, finalUpdateID int64, err error)

QueryDepth query the order book depth of a symbol

func (*Exchange) QueryFundingRateHistory added in v1.18.0

func (e *Exchange) QueryFundingRateHistory(ctx context.Context, symbol string) (*types.FundingRate, error)

func (*Exchange) QueryFuturesAccount added in v1.26.2

func (e *Exchange) QueryFuturesAccount(ctx context.Context) (*types.Account, error)

QueryFuturesAccount gets the futures account balances from Binance Balance.Available = Wallet Balance(in Binance UI) - Used Margin Balance.Locked = Used Margin

func (*Exchange) QueryFuturesIncomeHistory added in v1.45.0

func (e *Exchange) QueryFuturesIncomeHistory(
	ctx context.Context, symbol string, incomeType binanceapi.FuturesIncomeType, startTime, endTime *time.Time,
) ([]binanceapi.FuturesIncome, error)

QueryFuturesIncomeHistory queries the income history on the binance futures account This is more binance futures specific API, the convert function is not designed yet. TODO: consider other futures platforms and design the common data structure for this

func (*Exchange) QueryFuturesKLines added in v1.34.0

func (e *Exchange) QueryFuturesKLines(
	ctx context.Context, symbol string, interval types.Interval, options types.KLineQueryOptions,
) ([]types.KLine, error)

func (*Exchange) QueryFuturesPositionRisks added in v1.45.0

func (e *Exchange) QueryFuturesPositionRisks(ctx context.Context, symbol string) error

func (*Exchange) QueryHistoricalTrades added in v1.44.0

func (e *Exchange) QueryHistoricalTrades(ctx context.Context, symbol string, limit uint64) ([]types.Trade, error)

func (*Exchange) QueryInterestHistory added in v1.33.0

func (e *Exchange) QueryInterestHistory(ctx context.Context, asset string, startTime, endTime *time.Time) ([]types.MarginInterest, error)

func (*Exchange) QueryIsolatedMarginAccount added in v1.8.0

func (e *Exchange) QueryIsolatedMarginAccount(ctx context.Context) (*types.Account, error)

func (*Exchange) QueryKLines

func (e *Exchange) QueryKLines(
	ctx context.Context, symbol string, interval types.Interval, options types.KLineQueryOptions,
) ([]types.KLine, error)

QueryKLines queries the Kline/candlestick bars for a symbol. Klines are uniquely identified by their open time. Binance uses inclusive start time query range, eg: https://api.binance.com/api/v3/klines?symbol=BTCUSDT&interval=1m&startTime=1620172860000 the above query will return a kline with startTime = 1620172860000 and, https://api.binance.com/api/v3/klines?symbol=BTCUSDT&interval=1m&startTime=1620172860000&endTime=1620172920000 the above query will return a kline with startTime = 1620172860000, and a kline with endTime = 1620172860000

the endTime of a binance kline, is the (startTime + interval time - 1 millisecond), e.g., millisecond unix timestamp: 1620172860000 and 1620172919999

func (*Exchange) QueryLiquidationHistory added in v1.33.0

func (e *Exchange) QueryLiquidationHistory(ctx context.Context, startTime, endTime *time.Time) ([]types.MarginLiquidation, error)

func (*Exchange) QueryLoanHistory added in v1.33.0

func (e *Exchange) QueryLoanHistory(ctx context.Context, asset string, startTime, endTime *time.Time) ([]types.MarginLoan, error)

func (*Exchange) QueryMarginAssetMaxBorrowable added in v1.31.0

func (e *Exchange) QueryMarginAssetMaxBorrowable(ctx context.Context, asset string) (amount fixedpoint.Value, err error)

func (*Exchange) QueryMarginBorrowHistory added in v1.33.0

func (e *Exchange) QueryMarginBorrowHistory(ctx context.Context, asset string) error

func (*Exchange) QueryMarkets

func (e *Exchange) QueryMarkets(ctx context.Context) (types.MarketMap, error)

func (*Exchange) QueryOpenOrders

func (e *Exchange) QueryOpenOrders(ctx context.Context, symbol string) (orders []types.Order, err error)

func (*Exchange) QueryOrder added in v1.28.0

func (e *Exchange) QueryOrder(ctx context.Context, q types.OrderQuery) (*types.Order, error)

func (*Exchange) QueryOrderTrades added in v1.39.0

func (e *Exchange) QueryOrderTrades(ctx context.Context, q types.OrderQuery) ([]types.Trade, error)

func (*Exchange) QueryPositionRisk added in v1.26.2

func (e *Exchange) QueryPositionRisk(ctx context.Context, symbol string) (*types.PositionRisk, error)

func (*Exchange) QueryPremiumIndex added in v1.18.0

func (e *Exchange) QueryPremiumIndex(ctx context.Context, symbol string) (*types.PremiumIndex, error)

QueryPremiumIndex is only for futures

func (*Exchange) QueryRepayHistory added in v1.33.0

func (e *Exchange) QueryRepayHistory(ctx context.Context, asset string, startTime, endTime *time.Time) ([]types.MarginRepay, error)

func (*Exchange) QueryRewards added in v1.36.0

func (e *Exchange) QueryRewards(ctx context.Context, startTime time.Time) ([]types.Reward, error)

func (*Exchange) QuerySpotAccount added in v1.26.2

func (e *Exchange) QuerySpotAccount(ctx context.Context) (*types.Account, error)

func (*Exchange) QueryTicker added in v1.11.1

func (e *Exchange) QueryTicker(ctx context.Context, symbol string) (*types.Ticker, error)

func (*Exchange) QueryTickers added in v1.11.0

func (e *Exchange) QueryTickers(ctx context.Context, symbol ...string) (map[string]types.Ticker, error)

func (*Exchange) QueryTrades

func (e *Exchange) QueryTrades(ctx context.Context, symbol string, options *types.TradeQueryOptions) ([]types.Trade, error)

func (*Exchange) QueryWithdrawHistory

func (e *Exchange) QueryWithdrawHistory(ctx context.Context, asset string, since, until time.Time) (withdraws []types.Withdraw, err error)

func (*Exchange) RepayMarginAsset added in v1.31.0

func (e *Exchange) RepayMarginAsset(ctx context.Context, asset string, amount fixedpoint.Value) error

func (*Exchange) SubmitOrder added in v1.40.3

func (e *Exchange) SubmitOrder(ctx context.Context, order types.SubmitOrder) (createdOrder *types.Order, err error)

func (*Exchange) SupportedInterval added in v1.38.0

func (e *Exchange) SupportedInterval() map[types.Interval]int

func (*Exchange) TransferFuturesAccountAsset added in v1.45.0

func (e *Exchange) TransferFuturesAccountAsset(
	ctx context.Context, asset string, amount fixedpoint.Value, io types.TransferDirection,
) error

func (*Exchange) TransferMarginAccountAsset added in v1.52.0

func (e *Exchange) TransferMarginAccountAsset(
	ctx context.Context, asset string, amount fixedpoint.Value, io types.TransferDirection,
) error

TransferMarginAccountAsset transfers the asset into/out from the margin account

types.TransferIn => Spot to Margin types.TransferOut => Margin to Spot

to call this method, you must set the IsMargin = true

func (*Exchange) Withdraw added in v1.33.0

func (e *Exchange) Withdraw(
	ctx context.Context, asset string, amount fixedpoint.Value, address string, options *types.WithdrawalOptions,
) error

type ExecutionReportEvent

type ExecutionReportEvent struct {
	EventBase

	Symbol string `json:"s"`
	Side   string `json:"S"`

	ClientOrderID         string `json:"c"`
	OriginalClientOrderID string `json:"C"`

	OrderType         string `json:"o"`
	OrderCreationTime int64  `json:"O"`

	TimeInForce     string           `json:"f"`
	IcebergQuantity fixedpoint.Value `json:"F"`

	OrderQuantity      fixedpoint.Value `json:"q"`
	QuoteOrderQuantity fixedpoint.Value `json:"Q"`

	OrderPrice fixedpoint.Value `json:"p"`
	StopPrice  fixedpoint.Value `json:"P"`

	IsOnBook     bool                       `json:"w"`
	WorkingTime  types.MillisecondTimestamp `json:"W"`
	TrailingTime types.MillisecondTimestamp `json:"D"`

	IsMaker bool `json:"m"`
	Ignore  bool `json:"M"`

	CommissionAmount fixedpoint.Value `json:"n"`
	CommissionAsset  string           `json:"N"`

	CurrentExecutionType string `json:"x"`
	CurrentOrderStatus   string `json:"X"`

	OrderID int64 `json:"i"`
	Ignored int64 `json:"I"`

	TradeID         int64 `json:"t"`
	TransactionTime int64 `json:"T"`

	LastExecutedQuantity fixedpoint.Value `json:"l"`
	LastExecutedPrice    fixedpoint.Value `json:"L"`

	CumulativeFilledQuantity               fixedpoint.Value `json:"z"`
	CumulativeQuoteAssetTransactedQuantity fixedpoint.Value `json:"Z"`

	LastQuoteAssetTransactedQuantity fixedpoint.Value `json:"Y"`
}

executionReport

{
  "e": "executionReport",        // Event type
  "E": 1499405658658,            // Event time
  "s": "ETHBTC",                 // Symbol
  "c": "mUvoqJxFIILMdfAW5iGSOW", // Client order ID
  "S": "BUY",                    // Side
  "o": "LIMIT",                  // Order type
  "f": "GTC",                    // Time in force
  "q": "1.00000000",             // Order quantity
  "p": "0.10264410",             // Order price
  "P": "0.00000000",             // Stop price
  "F": "0.00000000",             // Iceberg quantity
  "g": -1,                       // OrderListId
  "C": null,                     // Original client order ID; This is the ID of the order being canceled
  "x": "NEW",                    // Current execution type
  "X": "NEW",                    // Current order status
  "r": "NONE",                   // Order reject reason; will be an error code.
  "i": 4293153,                  // Order ID
  "l": "0.00000000",             // Last executed quantity
  "z": "0.00000000",             // Cumulative filled quantity
  "L": "0.00000000",             // Last executed price
  "n": "0",                      // Commission amount
  "N": null,                     // Commission asset
  "T": 1499405658657,            // Transaction time
  "t": -1,                       // Trade ID
  "I": 8641984,                  // Ignore
  "w": true,                     // Is the order on the book?
  "m": false,                    // Is this trade the maker side?
  "M": false,                    // Ignore
  "O": 1499405658657,            // Order creation time
  "Z": "0.00000000",             // Cumulative quote asset transacted quantity
  "Y": "0.00000000",             // Last quote asset transacted quantity (i.e. lastPrice * lastQty)
  "Q": "0.00000000"              // Quote Order Quantity
}

func (*ExecutionReportEvent) Order

func (e *ExecutionReportEvent) Order() (*types.Order, error)

func (*ExecutionReportEvent) Trade

func (e *ExecutionReportEvent) Trade() (*types.Trade, error)

type ForceOrderEvent added in v1.53.0

type ForceOrderEvent struct {
	EventBase
	Order ForceOrderEventInner `json:"o"`
}

func (*ForceOrderEvent) LiquidationInfo added in v1.53.0

func (e *ForceOrderEvent) LiquidationInfo() types.LiquidationInfo

type ForceOrderEventInner added in v1.53.0

type ForceOrderEventInner struct {
	Symbol                string                     `json:"s"`
	TradeTime             types.MillisecondTimestamp `json:"T"`
	Side                  string                     `json:"S"`
	OrderType             string                     `json:"o"`
	TimeInForce           string                     `json:"f"`
	Quantity              fixedpoint.Value           `json:"q"`
	Price                 fixedpoint.Value           `json:"p"`
	AveragePrice          fixedpoint.Value           `json:"ap"`
	OrderStatus           string                     `json:"X"`
	LastFilledQuantity    fixedpoint.Value           `json:"l"`
	LastFilledAccQuantity fixedpoint.Value           `json:"z"`
}

type FuturesStreamBalance added in v1.45.0

type FuturesStreamBalance struct {
	Asset              string           `json:"a"`
	WalletBalance      fixedpoint.Value `json:"wb"`
	CrossWalletBalance fixedpoint.Value `json:"cw"`
	BalanceChange      fixedpoint.Value `json:"bc"`
}

type FuturesStreamPosition added in v1.45.0

type FuturesStreamPosition struct {
	Symbol                 string           `json:"s"`
	PositionAmount         fixedpoint.Value `json:"pa"`
	EntryPrice             fixedpoint.Value `json:"ep"`
	AccumulatedRealizedPnL fixedpoint.Value `json:"cr"` // (Pre-fee) Accumulated Realized PnL
	UnrealizedPnL          fixedpoint.Value `json:"up"`
	MarginType             string           `json:"mt"`
	IsolatedWallet         fixedpoint.Value `json:"iw"`
	PositionSide           string           `json:"ps"`
}

type KLine

type KLine struct {
	StartTime int64 `json:"t"`
	EndTime   int64 `json:"T"`

	Symbol   string `json:"s"`
	Interval string `json:"i"`

	Open  fixedpoint.Value `json:"o"`
	Close fixedpoint.Value `json:"c"`
	High  fixedpoint.Value `json:"h"`
	Low   fixedpoint.Value `json:"l"`

	Volume      fixedpoint.Value `json:"v"` // base asset volume (like 10 BTC)
	QuoteVolume fixedpoint.Value `json:"q"` // quote asset volume

	TakerBuyBaseAssetVolume  fixedpoint.Value `json:"V"` // taker buy base asset volume (like 10 BTC)
	TakerBuyQuoteAssetVolume fixedpoint.Value `json:"Q"` // taker buy quote asset volume (like 1000USDT)

	LastTradeID    int   `json:"L"`
	NumberOfTrades int64 `json:"n"`
	Closed         bool  `json:"x"`
}

func (*KLine) KLine

func (k *KLine) KLine() types.KLine

type KLineEvent

type KLineEvent struct {
	EventBase
	Symbol string `json:"s"`
	KLine  KLine  `json:"k,omitempty"`
}

type ListenKeyExpired added in v1.40.3

type ListenKeyExpired struct {
	EventBase
}

type MarginCallEvent added in v1.45.0

type MarginCallEvent struct {
	EventBase

	CrossWalletBalance fixedpoint.Value `json:"cw"`
	P                  []struct {
		Symbol                    string           `json:"s"`
		PositionSide              string           `json:"ps"`
		PositionAmount            fixedpoint.Value `json:"pa"`
		MarginType                string           `json:"mt"`
		IsolatedWallet            fixedpoint.Value `json:"iw"`
		MarkPrice                 fixedpoint.Value `json:"mp"`
		UnrealizedPnL             fixedpoint.Value `json:"up"`
		MaintenanceMarginRequired fixedpoint.Value `json:"mm"`
	} `json:"p"` // Position(s) of Margin Call
}

type MarkPriceUpdateEvent added in v1.18.1

type MarkPriceUpdateEvent struct {
	EventBase

	Symbol string `json:"s"`

	MarkPrice      fixedpoint.Value `json:"p"`
	IndexPrice     fixedpoint.Value `json:"i"`
	EstimatedPrice fixedpoint.Value `json:"P"`

	FundingRate     fixedpoint.Value `json:"r"`
	NextFundingTime int64            `json:"T"`
}

type MarketTradeEvent added in v1.29.0

type MarketTradeEvent struct {
	EventBase
	Symbol   string           `json:"s"`
	Quantity fixedpoint.Value `json:"q"`
	Price    fixedpoint.Value `json:"p"`

	BuyerOrderId  int64 `json:"b"`
	SellerOrderId int64 `json:"a"`

	OrderTradeTime int64 `json:"T"`
	TradeId        int64 `json:"t"`

	IsMaker bool `json:"m"`
	Dummy   bool `json:"M"`
}

func (*MarketTradeEvent) Trade added in v1.29.0

func (e *MarketTradeEvent) Trade() types.Trade

type OrderTrade added in v1.21.0

type OrderTrade struct {
	Symbol           string           `json:"s"`
	ClientOrderID    string           `json:"c"`
	Side             string           `json:"S"`
	OrderType        string           `json:"o"`
	TimeInForce      string           `json:"f"`
	OriginalQuantity fixedpoint.Value `json:"q"`
	OriginalPrice    fixedpoint.Value `json:"p"`

	AveragePrice         fixedpoint.Value `json:"ap"`
	StopPrice            fixedpoint.Value `json:"sp"`
	CurrentExecutionType string           `json:"x"`
	CurrentOrderStatus   string           `json:"X"`

	OrderId                        int64            `json:"i"`
	OrderLastFilledQuantity        fixedpoint.Value `json:"l"`
	OrderFilledAccumulatedQuantity fixedpoint.Value `json:"z"`
	LastFilledPrice                fixedpoint.Value `json:"L"`

	CommissionAmount fixedpoint.Value `json:"n"`
	CommissionAsset  string           `json:"N"`

	OrderTradeTime types.MillisecondTimestamp `json:"T"`
	TradeId        int64                      `json:"t"`

	BidsNotional string `json:"b"`
	AskNotional  string `json:"a"`

	IsMaker      bool `json:"m"`
	IsReduceOnly bool ` json:"r"`

	StopPriceWorkingType string `json:"wt"`
	OriginalOrderType    string `json:"ot"`
	PositionSide         string `json:"ps"`
	RealizedProfit       string `json:"rp"`
}

Similar to the ExecutionReportEvent's fields. But with totally different json key. e.g., Stop price. So that, we can not merge them.

type OrderTradeUpdateEvent added in v1.21.0

type OrderTradeUpdateEvent struct {
	EventBase
	Transaction int64      `json:"T"`
	OrderTrade  OrderTrade `json:"o"`
}

func (*OrderTradeUpdateEvent) OrderFutures added in v1.21.0

func (e *OrderTradeUpdateEvent) OrderFutures() (*types.Order, error)

func (*OrderTradeUpdateEvent) TradeFutures added in v1.26.2

func (e *OrderTradeUpdateEvent) TradeFutures() (*types.Trade, error)

type OutboundAccountInfoEvent

type OutboundAccountInfoEvent struct {
	EventBase

	MakerCommissionRate  int `json:"m"`
	TakerCommissionRate  int `json:"t"`
	BuyerCommissionRate  int `json:"b"`
	SellerCommissionRate int `json:"s"`

	CanTrade    bool `json:"T"`
	CanWithdraw bool `json:"W"`
	CanDeposit  bool `json:"D"`

	LastAccountUpdateTime int `json:"u"`

	Balances    []Balance `json:"B,omitempty"`
	Permissions []string  `json:"P,omitempty"`
}

type OutboundAccountPositionEvent added in v1.8.0

type OutboundAccountPositionEvent struct {
	EventBase

	LastAccountUpdateTime int       `json:"u"`
	Balances              []Balance `json:"B,omitempty"`
}

type PartialDepthEvent added in v1.57.0

type PartialDepthEvent struct {
	EventBase

	binanceapi.Depth
}
{
  "lastUpdateId": 160,  // Last update ID
  "bids": [             // Bids to be updated
    [
      "0.0024",         // Price level to be updated
      "10"              // Quantity
    ]
  ],
  "asks": [             // Asks to be updated
    [
      "0.0026",         // Price level to be updated
      "100"             // Quantity
    ]
  ]
}

type ResultEvent

type ResultEvent struct {
	Result interface{} `json:"result,omitempty"`
	ID     int         `json:"id"`
}

type Stream

type Stream struct {
	types.MarginSettings
	types.FuturesSettings
	types.StandardStream
	// contains filtered or unexported fields
}

func NewStream

func NewStream(ex *Exchange, client *binance.Client, futuresClient *futures.Client) *Stream

func (*Stream) EmitAccountConfigUpdateEvent added in v1.22.0

func (s *Stream) EmitAccountConfigUpdateEvent(e *AccountConfigUpdateEvent)

func (*Stream) EmitAccountUpdateEvent added in v1.22.0

func (s *Stream) EmitAccountUpdateEvent(e *AccountUpdateEvent)

func (*Stream) EmitAggTradeEvent added in v1.43.0

func (s *Stream) EmitAggTradeEvent(e *AggTradeEvent)

func (*Stream) EmitBalanceUpdateEvent

func (s *Stream) EmitBalanceUpdateEvent(event *BalanceUpdateEvent)

func (*Stream) EmitBookTickerEvent added in v1.21.0

func (s *Stream) EmitBookTickerEvent(event *BookTickerEvent)

func (*Stream) EmitContinuousKLineClosedEvent added in v1.21.0

func (s *Stream) EmitContinuousKLineClosedEvent(e *ContinuousKLineEvent)

func (*Stream) EmitContinuousKLineEvent added in v1.18.1

func (s *Stream) EmitContinuousKLineEvent(e *ContinuousKLineEvent)

func (*Stream) EmitDepthEvent

func (s *Stream) EmitDepthEvent(e *DepthEvent)

func (*Stream) EmitExecutionReportEvent

func (s *Stream) EmitExecutionReportEvent(event *ExecutionReportEvent)

func (*Stream) EmitForceOrderEvent added in v1.53.0

func (s *Stream) EmitForceOrderEvent(e *ForceOrderEvent)

func (*Stream) EmitKLineClosedEvent

func (s *Stream) EmitKLineClosedEvent(e *KLineEvent)

func (*Stream) EmitKLineEvent

func (s *Stream) EmitKLineEvent(e *KLineEvent)

func (*Stream) EmitListenKeyExpired added in v1.40.3

func (s *Stream) EmitListenKeyExpired(e *ListenKeyExpired)

func (*Stream) EmitMarginCallEvent added in v1.45.0

func (s *Stream) EmitMarginCallEvent(e *MarginCallEvent)

func (*Stream) EmitMarkPriceUpdateEvent added in v1.18.1

func (s *Stream) EmitMarkPriceUpdateEvent(e *MarkPriceUpdateEvent)

func (*Stream) EmitMarketTradeEvent added in v1.29.0

func (s *Stream) EmitMarketTradeEvent(e *MarketTradeEvent)

func (*Stream) EmitOrderTradeUpdateEvent added in v1.21.0

func (s *Stream) EmitOrderTradeUpdateEvent(e *OrderTradeUpdateEvent)

func (*Stream) EmitOutboundAccountInfoEvent

func (s *Stream) EmitOutboundAccountInfoEvent(event *OutboundAccountInfoEvent)

func (*Stream) EmitOutboundAccountPositionEvent added in v1.8.0

func (s *Stream) EmitOutboundAccountPositionEvent(event *OutboundAccountPositionEvent)

func (*Stream) OnAccountConfigUpdateEvent added in v1.22.0

func (s *Stream) OnAccountConfigUpdateEvent(cb func(e *AccountConfigUpdateEvent))

func (*Stream) OnAccountUpdateEvent added in v1.22.0

func (s *Stream) OnAccountUpdateEvent(cb func(e *AccountUpdateEvent))

func (*Stream) OnAggTradeEvent added in v1.43.0

func (s *Stream) OnAggTradeEvent(cb func(e *AggTradeEvent))

func (*Stream) OnBalanceUpdateEvent

func (s *Stream) OnBalanceUpdateEvent(cb func(event *BalanceUpdateEvent))

func (*Stream) OnBookTickerEvent added in v1.21.0

func (s *Stream) OnBookTickerEvent(cb func(event *BookTickerEvent))

func (*Stream) OnContinuousKLineClosedEvent added in v1.21.0

func (s *Stream) OnContinuousKLineClosedEvent(cb func(e *ContinuousKLineEvent))

func (*Stream) OnContinuousKLineEvent added in v1.18.1

func (s *Stream) OnContinuousKLineEvent(cb func(e *ContinuousKLineEvent))

func (*Stream) OnDepthEvent

func (s *Stream) OnDepthEvent(cb func(e *DepthEvent))

func (*Stream) OnExecutionReportEvent

func (s *Stream) OnExecutionReportEvent(cb func(event *ExecutionReportEvent))

func (*Stream) OnForceOrderEvent added in v1.53.0

func (s *Stream) OnForceOrderEvent(cb func(e *ForceOrderEvent))

func (*Stream) OnKLineClosedEvent

func (s *Stream) OnKLineClosedEvent(cb func(e *KLineEvent))

func (*Stream) OnKLineEvent

func (s *Stream) OnKLineEvent(cb func(e *KLineEvent))

func (*Stream) OnListenKeyExpired added in v1.40.3

func (s *Stream) OnListenKeyExpired(cb func(e *ListenKeyExpired))

func (*Stream) OnMarginCallEvent added in v1.45.0

func (s *Stream) OnMarginCallEvent(cb func(e *MarginCallEvent))

func (*Stream) OnMarkPriceUpdateEvent added in v1.18.1

func (s *Stream) OnMarkPriceUpdateEvent(cb func(e *MarkPriceUpdateEvent))

func (*Stream) OnMarketTradeEvent added in v1.29.0

func (s *Stream) OnMarketTradeEvent(cb func(e *MarketTradeEvent))

func (*Stream) OnOrderTradeUpdateEvent added in v1.21.0

func (s *Stream) OnOrderTradeUpdateEvent(cb func(e *OrderTradeUpdateEvent))

func (*Stream) OnOutboundAccountInfoEvent

func (s *Stream) OnOutboundAccountInfoEvent(cb func(event *OutboundAccountInfoEvent))

func (*Stream) OnOutboundAccountPositionEvent added in v1.8.0

func (s *Stream) OnOutboundAccountPositionEvent(cb func(event *OutboundAccountPositionEvent))

type StreamEventHub

type StreamEventHub interface {
	OnDepthEvent(cb func(e *DepthEvent))

	OnKLineEvent(cb func(e *KLineEvent))

	OnKLineClosedEvent(cb func(e *KLineEvent))

	OnMarketTradeEvent(cb func(e *MarketTradeEvent))

	OnAggTradeEvent(cb func(e *AggTradeEvent))

	OnForceOrderEvent(cb func(e *ForceOrderEvent))

	OnBalanceUpdateEvent(cb func(event *BalanceUpdateEvent))

	OnOutboundAccountInfoEvent(cb func(event *OutboundAccountInfoEvent))

	OnOutboundAccountPositionEvent(cb func(event *OutboundAccountPositionEvent))

	OnExecutionReportEvent(cb func(event *ExecutionReportEvent))

	OnBookTickerEvent(cb func(event *BookTickerEvent))

	OnMarkPriceUpdateEvent(cb func(e *MarkPriceUpdateEvent))

	OnContinuousKLineEvent(cb func(e *ContinuousKLineEvent))

	OnContinuousKLineClosedEvent(cb func(e *ContinuousKLineEvent))

	OnOrderTradeUpdateEvent(cb func(e *OrderTradeUpdateEvent))

	OnAccountUpdateEvent(cb func(e *AccountUpdateEvent))

	OnAccountConfigUpdateEvent(cb func(e *AccountConfigUpdateEvent))

	OnMarginCallEvent(cb func(e *MarginCallEvent))

	OnListenKeyExpired(cb func(e *ListenKeyExpired))
}

type WebSocketCommand added in v1.21.3

type WebSocketCommand struct {
	// request ID is required
	ID     int      `json:"id"`
	Method string   `json:"method"`
	Params []string `json:"params"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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