binance

package
v0.0.0-...-5439e55 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2022 License: MIT Imports: 17 Imported by: 2

Documentation

Index

Constants

View Source
const (
	API_URL              = "https://api.binance.com"
	CONTRACT_URL         = "https://fapi.binance.com"
	CONTRACT_TESTNET_URL = "https://testnet.binancefuture.com" ////
)

The Base Endpoint URL

View Source
const (
	DEFAULT_ID           = 1
	DEFAULT_TAKER_FEE    = 0.001
	DEFAULT_MAKER_FEE    = 0.001
	DEFAULT_LOT_SIZE     = 0.00000001
	DEFAULT_PRICE_FILTER = 0.00000001 //PRICE FILTER

	DEFAULT_TXFEE        = 0.005
	DEFAULT_WITHDRAW     = true
	DEFAULT_DEPOSIT      = true
	DEFAULT_CONFIRMATION = 2
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountBalances

type AccountBalances struct {
	MakerCommission  int  `json:"makerCommission"`
	TakerCommission  int  `json:"takerCommission"`
	BuyerCommission  int  `json:"buyerCommission"`
	SellerCommission int  `json:"sellerCommission"`
	CanTrade         bool `json:"canTrade"`
	CanWithdraw      bool `json:"canWithdraw"`
	CanDeposit       bool `json:"canDeposit"`
	Balances         []struct {
		Asset  string `json:"asset"`
		Free   string `json:"free"`
		Locked string `json:"locked"`
	} `json:"balances"`
}

type Binance

type Binance struct {
	ID      int
	Name    string `bson:"name"`
	Website string `bson:"website"`

	API_KEY    string
	API_SECRET string

	Source    exchange.DataSource // / exchange API / microservicve api 1 / PSQL
	SourceURI string
}

func CreateBinance

func CreateBinance(config *exchange.Config) *Binance

*************************************************

func (*Binance) ApiKeyGet

func (e *Binance) ApiKeyGet(mapParams map[string]string, strRequestPath string) string

************** Signature Http Request ************** Method: API Request and Signature is required Step 1: Change Instance Name (e *<exchange Instance Name>) Step 2: Create mapParams Depend on API Signature request Step 3: Add HttpGetRequest below strUrl if API has different requests

func (*Binance) ApiKeyRequest

func (e *Binance) ApiKeyRequest(strMethod string, mapParams map[string]string, strRequestPath string) string

Method: API Request and Signature is required Step 1: Change Instance Name (e *<exchange Instance Name>) Step 2: Create mapParams Depend on API Signature request Step 3: Add HttpGetRequest below strUrl if API has different requests

func (*Binance) CanDeposit

func (e *Binance) CanDeposit(coin *coin.Coin) bool

func (*Binance) CanWithdraw

func (e *Binance) CanWithdraw(coin *coin.Coin) bool

func (*Binance) CancelAllOrder

func (e *Binance) CancelAllOrder() error

func (*Binance) CancelOrder

func (e *Binance) CancelOrder(order *exchange.Order) error

func (*Binance) ContractApiKeyRequest

func (e *Binance) ContractApiKeyRequest(strMethod string, mapParams map[string]string, strRequestPath string, testMode bool) string

func (*Binance) DeleteCoin

func (e *Binance) DeleteCoin(coin *coin.Coin)

func (*Binance) DeletePair

func (e *Binance) DeletePair(pair *pair.Pair)

func (*Binance) DoAccountOperation

func (e *Binance) DoAccountOperation(operation *exchange.AccountOperation) error

func (*Binance) GetBalance

func (e *Binance) GetBalance(coin *coin.Coin) float64

func (*Binance) GetCoinBySymbol

func (e *Binance) GetCoinBySymbol(symbol string) *coin.Coin

func (*Binance) GetCoinConstraint

func (e *Binance) GetCoinConstraint(coin *coin.Coin) *exchange.CoinConstraint

************** Coins on the Exchanges **************

func (*Binance) GetCoins

func (e *Binance) GetCoins() []*coin.Coin

func (*Binance) GetCoinsData

func (e *Binance) GetCoinsData() error

************** Public API ************** Get Coins Information (If API provide) Step 1: Change Instance Name (e *<exchange Instance Name>) Step 2: Add Model of API Response Step 3: Modify API Path(strRequestUrl)

func (*Binance) GetConfirmation

func (e *Binance) GetConfirmation(coin *coin.Coin) int

func (*Binance) GetConstraintFetchMethod

func (e *Binance) GetConstraintFetchMethod(pair *pair.Pair) *exchange.ConstrainFetchMethod

*************** Exchange Constraint ***************

func (*Binance) GetFee

func (e *Binance) GetFee(pair *pair.Pair) float64

*************** Pair Constraint ***************

func (*Binance) GetID

func (e *Binance) GetID() int

*************** Exchange Information ***************

func (*Binance) GetLotSize

func (e *Binance) GetLotSize(pair *pair.Pair) float64

func (*Binance) GetName

func (e *Binance) GetName() exchange.ExchangeName

func (*Binance) GetPairBySymbol

func (e *Binance) GetPairBySymbol(symbol string) *pair.Pair

func (*Binance) GetPairConstraint

func (e *Binance) GetPairConstraint(pair *pair.Pair) *exchange.PairConstraint

************** Pairs on the Exchanges **************

func (*Binance) GetPairs

func (e *Binance) GetPairs() []*pair.Pair

func (*Binance) GetPairsData

func (e *Binance) GetPairsData() error
GetPairsData - Get Pairs Information (If API provide)

Step 1: Change Instance Name (e *<exchange Instance Name>) Step 2: Add Model of API Response Step 3: Modify API Path(strRequestUrl)

func (*Binance) GetPriceFilter

func (e *Binance) GetPriceFilter(pair *pair.Pair) float64

func (*Binance) GetSymbolByCoin

func (e *Binance) GetSymbolByCoin(coin *coin.Coin) string

func (*Binance) GetSymbolByPair

func (e *Binance) GetSymbolByPair(pair *pair.Pair) string

func (*Binance) GetTradingWebURL

func (e *Binance) GetTradingWebURL(pair *pair.Pair) string

func (*Binance) GetTxFee

func (e *Binance) GetTxFee(coin *coin.Coin) float64

*************** Coin Constraint ***************

func (*Binance) HasPair

func (e *Binance) HasPair(pair *pair.Pair) bool

func (*Binance) InitData

func (e *Binance) InitData() error

func (*Binance) LimitBuy

func (e *Binance) LimitBuy(pair *pair.Pair, quantity, rate float64) (*exchange.Order, error)

func (*Binance) LimitSell

func (e *Binance) LimitSell(pair *pair.Pair, quantity, rate float64) (*exchange.Order, error)

func (*Binance) ListOrders

func (e *Binance) ListOrders() ([]*exchange.Order, error)

func (*Binance) LoadPublicData

func (e *Binance) LoadPublicData(operation *exchange.PublicOperation) error

************** PUBLIC API **************

func (*Binance) OrderBook

func (e *Binance) OrderBook(p *pair.Pair) (*exchange.Maker, error)

Get Pair Market Depth Step 1: Change Instance Name (e *<exchange Instance Name>) Step 2: Add Model of API Response Step 3: Get Exchange Pair Code ex. symbol := e.GetPairCode(p) Step 4: Modify API Path(strRequestUrl) Step 5: Add Params - Depend on API request Step 6: Convert the response to Standard Maker struct

func (*Binance) OrderStatus

func (e *Binance) OrderStatus(order *exchange.Order) error

func (*Binance) SetCoinConstraint

func (e *Binance) SetCoinConstraint(coinConstraint *exchange.CoinConstraint)

func (*Binance) SetPairConstraint

func (e *Binance) SetPairConstraint(pairConstraint *exchange.PairConstraint)

func (*Binance) TestApi

func (e *Binance) TestApi() string

func (*Binance) UpdateAllBalances

func (e *Binance) UpdateAllBalances()

func (*Binance) UpdateConstraint

func (e *Binance) UpdateConstraint()

func (*Binance) WApiKeyRequest

func (e *Binance) WApiKeyRequest(strMethod string, mapParams map[string]string, strRequestPath string) string

Method: API Request and Signature is required Step 1: Change Instance Name (e *<exchange Instance Name>) Step 2: Create mapParams Depend on API Signature request Step 3: Add HttpGetRequest below strUrl if API has different requests

func (*Binance) Withdraw

func (e *Binance) Withdraw(coin *coin.Coin, quantity float64, addr, tag string) bool

Withdraw(coin *coin.Coin, quantity float64, addr, tag string)

type CloseOrders

type CloseOrders []struct {
	Symbol          string `json:"symbol"`
	ID              int    `json:"id"`
	OrderID         int    `json:"orderId"`
	OrderListID     int    `json:"orderListId"`
	Price           string `json:"price"`
	Qty             string `json:"qty"`
	QuoteQty        string `json:"quoteQty"`
	Commission      string `json:"commission"`
	CommissionAsset string `json:"commissionAsset"`
	Time            int64  `json:"time"`
	IsBuyer         bool   `json:"isBuyer"`
	IsMaker         bool   `json:"isMaker"`
	IsBestMatch     bool   `json:"isBestMatch"`
}

type CoinsData

type CoinsData []struct {
	Coin             string `json:"coin"`
	DepositAllEnable bool   `json:"depositAllEnable"`
	Free             string `json:"free"`
	Freeze           string `json:"freeze"`
	Ipoable          string `json:"ipoable"`
	Ipoing           string `json:"ipoing"`
	IsLegalMoney     bool   `json:"isLegalMoney"`
	Locked           string `json:"locked"`
	Name             string `json:"name"`
	NetworkList      []struct {
		AddressRegex            string `json:"addressRegex"`
		Coin                    string `json:"coin"`
		DepositDesc             string `json:"depositDesc,omitempty"`
		DepositEnable           bool   `json:"depositEnable"`
		IsDefault               bool   `json:"isDefault"`
		MemoRegex               string `json:"memoRegex"`
		MinConfirm              int    `json:"minConfirm"`
		Name                    string `json:"name"`
		Network                 string `json:"network"`
		ResetAddressStatus      bool   `json:"resetAddressStatus"`
		SpecialTips             string `json:"specialTips"`
		UnLockConfirm           int    `json:"unLockConfirm"`
		WithdrawDesc            string `json:"withdrawDesc,omitempty"`
		WithdrawEnable          bool   `json:"withdrawEnable"`
		WithdrawFee             string `json:"withdrawFee"`
		WithdrawMin             string `json:"withdrawMin"`
		InsertTime              int64  `json:"insertTime,omitempty"`
		UpdateTime              int64  `json:"updateTime,omitempty"`
		WithdrawIntegerMultiple string `json:"withdrawIntegerMultiple,omitempty"`
	} `json:"networkList"`
	Storage           string `json:"storage"`
	Trading           bool   `json:"trading"`
	WithdrawAllEnable bool   `json:"withdrawAllEnable"`
	Withdrawing       string `json:"withdrawing"`
}

type ContractBalance

type ContractBalance struct {
	Assets []struct {
		Asset                  string `json:"asset"`
		InitialMargin          string `json:"initialMargin"`
		MaintMargin            string `json:"maintMargin"`
		MarginBalance          string `json:"marginBalance"`
		MaxWithdrawAmount      string `json:"maxWithdrawAmount"`
		OpenOrderInitialMargin string `json:"openOrderInitialMargin"`
		PositionInitialMargin  string `json:"positionInitialMargin"`
		UnrealizedProfit       string `json:"unrealizedProfit"`
		WalletBalance          string `json:"walletBalance"`
	} `json:"assets"`
	CanDeposit        bool   `json:"canDeposit"`
	CanTrade          bool   `json:"canTrade"`
	CanWithdraw       bool   `json:"canWithdraw"`
	FeeTier           int    `json:"feeTier"`
	MaxWithdrawAmount string `json:"maxWithdrawAmount"`
	Positions         []struct {
		Isolated               bool   `json:"isolated"`
		Leverage               string `json:"leverage"`
		InitialMargin          string `json:"initialMargin"`
		MaintMargin            string `json:"maintMargin"`
		OpenOrderInitialMargin string `json:"openOrderInitialMargin"`
		PositionInitialMargin  string `json:"positionInitialMargin"`
		Symbol                 string `json:"symbol"`
		UnrealizedProfit       string `json:"unrealizedProfit"`
	} `json:"positions"`
	TotalInitialMargin          string `json:"totalInitialMargin"`
	TotalMaintMargin            string `json:"totalMaintMargin"`
	TotalMarginBalance          string `json:"totalMarginBalance"`
	TotalOpenOrderInitialMargin string `json:"totalOpenOrderInitialMargin"`
	TotalPositionInitialMargin  string `json:"totalPositionInitialMargin"`
	TotalUnrealizedProfit       string `json:"totalUnrealizedProfit"`
	TotalWalletBalance          string `json:"totalWalletBalance"`
	UpdateTime                  int    `json:"updateTime"`
}

type ContractCancelOrder

type ContractCancelOrder struct {
	ClientOrderID string `json:"clientOrderId"`
	CumQty        string `json:"cumQty"`
	CumQuote      string `json:"cumQuote"`
	ExecutedQty   string `json:"executedQty"`
	OrderID       int    `json:"orderId"`
	OrigQty       string `json:"origQty"`
	Price         string `json:"price"`
	ReduceOnly    bool   `json:"reduceOnly"`
	Side          string `json:"side"`
	Status        string `json:"status"`
	StopPrice     string `json:"stopPrice"`
	Symbol        string `json:"symbol"`
	TimeInForce   string `json:"timeInForce"`
	OrigType      string `json:"origType"`
	Type          string `json:"type"`
	ActivatePrice string `json:"activatePrice"`
	PriceRate     string `json:"priceRate"`
	UpdateTime    int64  `json:"updateTime"`
	WorkingType   string `json:"workingType"`
}

type ContractOpenOrders

type ContractOpenOrders []struct {
	AvgPrice      string `json:"avgPrice"`
	ClientOrderID string `json:"clientOrderId"`
	CumQuote      string `json:"cumQuote"`
	ExecutedQty   string `json:"executedQty"`
	OrderID       int    `json:"orderId"`
	OrigQty       string `json:"origQty"`
	OrigType      string `json:"origType"`
	Price         string `json:"price"`
	ReduceOnly    bool   `json:"reduceOnly"`
	Side          string `json:"side"`
	PositionSide  string `json:"positionSide"`
	Status        string `json:"status"`
	StopPrice     string `json:"stopPrice"`
	Symbol        string `json:"symbol"`
	Time          int64  `json:"time"`
	TimeInForce   string `json:"timeInForce"`
	Type          string `json:"type"`
	ActivatePrice string `json:"activatePrice"`
	PriceRate     string `json:"priceRate"`
	UpdateTime    int64  `json:"updateTime"`
	WorkingType   string `json:"workingType"`
}

type ContractOrderBook

type ContractOrderBook struct {
	LastUpdateID int64      `json:"lastUpdateId"`
	E            int64      `json:"E"`
	T            int64      `json:"T"`
	Bids         [][]string `json:"bids"`
	Asks         [][]string `json:"asks"`
}

type ContractOrderStatus

type ContractOrderStatus struct {
	AvgPrice      string `json:"avgPrice"`
	ClientOrderID string `json:"clientOrderId"`
	CumQuote      string `json:"cumQuote"`
	ExecutedQty   string `json:"executedQty"`
	OrderID       int    `json:"orderId"`
	OrigQty       string `json:"origQty"`
	OrigType      string `json:"origType"`
	Price         string `json:"price"`
	ReduceOnly    bool   `json:"reduceOnly"`
	Side          string `json:"side"`
	Status        string `json:"status"`
	StopPrice     string `json:"stopPrice"`
	Symbol        string `json:"symbol"`
	Time          int64  `json:"time"`
	TimeInForce   string `json:"timeInForce"`
	Type          string `json:"type"`
	ActivatePrice string `json:"activatePrice"`
	PriceRate     string `json:"priceRate"`
	UpdateTime    int64  `json:"updateTime"`
	WorkingType   string `json:"workingType"`
}

type ContractPlaceOrder

type ContractPlaceOrder struct {
	ClientOrderID string `json:"clientOrderId"`
	CumQuote      string `json:"cumQuote"`
	ExecutedQty   string `json:"executedQty"`
	OrderID       int    `json:"orderId"`
	OrigQty       string `json:"origQty"`
	Price         string `json:"price"`
	ReduceOnly    bool   `json:"reduceOnly"`
	Side          string `json:"side"`
	Status        string `json:"status"`
	StopPrice     string `json:"stopPrice"`
	Symbol        string `json:"symbol"`
	TimeInForce   string `json:"timeInForce"`
	Type          string `json:"type"`
	ActivatePrice string `json:"activatePrice"`
	PriceRate     string `json:"priceRate"`
	UpdateTime    int64  `json:"updateTime"`
	WorkingType   string `json:"workingType"`
}

type ContractTransferHistory

type ContractTransferHistory struct {
	Rows []struct {
		Asset     string `json:"asset"`
		TranID    int    `json:"tranId"`
		Amount    string `json:"amount"`
		Type      int    `json:"type"`
		Timestamp int64  `json:"timestamp"`
		Status    string `json:"status"`
	} `json:"rows"`
	Total int `json:"total"`
}

type DepositAddress

type DepositAddress struct {
	Code    int    `json:"code"`
	Address string `json:"address"`
	Coin    string `json:"coin"`
	Tag     string `json:"tag"`
	URL     string `json:"url"`
}

type DepositHistory

type DepositHistory []struct {
	Address    string `json:"address"`
	AddressTag string `json:"addressTag"`
	Amount     string `json:"amount"`
	Coin       string `json:"coin"`
	InsertTime int64  `json:"insertTime"`
	Network    string `json:"network"`
	Status     int    `json:"status"`
	TxID       string `json:"txId"`
}

type FutureBalance

type FutureBalance struct {
	AccountAlias       string `json:"accountAlias"`
	Asset              string `json:"asset"`
	Balance            string `json:"balance"`
	CrossWalletBalance string `json:"crossWalletBalance"`
	CrossUnPnl         string `json:"crossUnPnl"`
	AvailableBalance   string `json:"availableBalance"`
	MaxWithdrawAmount  string `json:"maxWithdrawAmount"`
}

type FutureLeverage

type FutureLeverage struct {
	Leverage         int    `json:"leverage"`
	MaxNotionalValue string `json:"maxNotionalValue"`
	Symbol           string `json:"symbol"`
}

type OpenOrders

type OpenOrders []struct {
	Symbol              string `json:"symbol"`
	OrderID             int    `json:"orderId"`
	OrderListID         int    `json:"orderListId"`
	ClientOrderID       string `json:"clientOrderId"`
	Price               string `json:"price"`
	OrigQty             string `json:"origQty"`
	ExecutedQty         string `json:"executedQty"`
	CummulativeQuoteQty string `json:"cummulativeQuoteQty"`
	Status              string `json:"status"`
	TimeInForce         string `json:"timeInForce"`
	Type                string `json:"type"`
	Side                string `json:"side"`
	StopPrice           string `json:"stopPrice"`
	IcebergQty          string `json:"icebergQty"`
	Time                int64  `json:"time"`
	UpdateTime          int64  `json:"updateTime"`
	IsWorking           bool   `json:"isWorking"`
	OrigQuoteOrderQty   string `json:"origQuoteOrderQty"`
}

private operation

type OrderBook

type OrderBook struct {
	Code         int             `json:"code"`
	LastUpdateID int             `json:"lastUpdateId"`
	Bids         [][]interface{} `json:"bids"`
	Asks         [][]interface{} `json:"asks"`
}

type PairsData

type PairsData struct {
	Timezone   string `json:"timezone"`
	ServerTime int64  `json:"serverTime"`
	RateLimits []struct {
		RateLimitType string `json:"rateLimitType"`
		Interval      string `json:"interval"`
		Limit         int    `json:"limit"`
	} `json:"rateLimits"`
	ExchangeFilters []interface{} `json:"exchangeFilters"`
	Symbols         []struct {
		Symbol             string   `json:"symbol"`
		Status             string   `json:"status"`
		BaseAsset          string   `json:"baseAsset"`
		BaseAssetPrecision int      `json:"baseAssetPrecision"`
		QuoteAsset         string   `json:"quoteAsset"`
		QuotePrecision     int      `json:"quotePrecision"`
		OrderTypes         []string `json:"orderTypes"`
		IcebergAllowed     bool     `json:"icebergAllowed"`
		Filters            []struct {
			FilterType       string `json:"filterType"`
			MinPrice         string `json:"minPrice,omitempty"`
			MaxPrice         string `json:"maxPrice,omitempty"`
			TickSize         string `json:"tickSize,omitempty"`
			MinQty           string `json:"minQty,omitempty"`
			MaxQty           string `json:"maxQty,omitempty"`
			StepSize         string `json:"stepSize,omitempty"`
			MinNotional      string `json:"minNotional,omitempty"`
			Limit            int    `json:"limit,omitempty"`
			MaxNumAlgoOrders int    `json:"maxNumAlgoOrders,omitempty"`
		} `json:"filters"`
	} `json:"symbols"`
}

type PlaceOrder

type PlaceOrder struct {
	Symbol        string `json:"symbol"`
	OrderID       int    `json:"orderId"`
	ClientOrderID string `json:"clientOrderId"`
	TransactTime  int64  `json:"transactTime"`
	Price         string `json:"price"`
	OrigQty       string `json:"origQty"`
	ExecutedQty   string `json:"executedQty"`
	Status        string `json:"status"`
	TimeInForce   string `json:"timeInForce"`
	Type          string `json:"type"`
	Side          string `json:"side"`
	StopPrice     string `json:"stopPrice"`
	IcebergQty    string `json:"icebergQty"`
	Time          int64  `json:"time"`
	Code          int    `json:"code"`
	Msg           string `json:"msg"`
}

type SubAccountBalances

type SubAccountBalances struct {
	Success  bool `json:"success"`
	Balances []struct {
		Asset  string  `json:"asset"`
		Free   float64 `json:"free"`
		Locked float64 `json:"locked"`
	} `json:"balances"`
}

type SubAccountList

type SubAccountList struct {
	Success     bool `json:"success"`
	SubAccounts []struct {
		Email      string `json:"email"`
		Status     string `json:"status"`
		Activated  bool   `json:"activated"`
		Mobile     string `json:"mobile"`
		GAuth      bool   `json:"gAuth"`
		CreateTime int64  `json:"createTime"`
	} `json:"subAccounts"`
}

type SubTransfer

type SubTransfer struct {
	Success bool   `json:"success"`
	TxnID   string `json:"txnId"`
}

type TickerPrice

type TickerPrice []struct {
	Symbol string `json:"symbol"`
	Price  string `json:"price"`
}

type TradeHistory

type TradeHistory []struct {
	ID           int    `json:"id"`
	Price        string `json:"price"`
	Qty          string `json:"qty"`
	QuoteQty     string `json:"quoteQty"`
	Time         int64  `json:"time"`
	IsBuyerMaker bool   `json:"isBuyerMaker"`
	IsBestMatch  bool   `json:"isBestMatch"`
}

type TransferHistory

type TransferHistory []struct {
	CounterParty string `json:"counterParty"`
	Email        string `json:"email"`
	Type         int    `json:"type"`
	Asset        string `json:"asset"`
	Qty          string `json:"qty"`
	Time         int64  `json:"time"`
}

type WithdrawHistory

type WithdrawHistory []struct {
	Address         string    `json:"address"`
	Amount          string    `json:"amount"`
	ApplyTime       time.Time `json:"applyTime"`
	Coin            string    `json:"coin"`
	ID              string    `json:"id"`
	WithdrawOrderID string    `json:"withdrawOrderId,omitempty"`
	Network         string    `json:"network"`
	TransferType    int       `json:"transferType"`
	Status          int       `json:"status"`
	TxID            string    `json:"txId"`
}

type WithdrawResponse

type WithdrawResponse struct {
	Msg     string `json:"msg"`
	Success bool   `json:"success"`
	ID      string `json:"id"`
}

Jump to

Keyboard shortcuts

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