Skip to content

Commit

Permalink
Merge branch 'adshao:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
ntminh611 authored Apr 4, 2024
2 parents 090f348 + d3e61bd commit 0c79288
Show file tree
Hide file tree
Showing 9 changed files with 502 additions and 247 deletions.
10 changes: 5 additions & 5 deletions v2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ type RateLimitInterval string
type AccountType string

// Endpoints
const (
baseAPIMainURL = "https://api.binance.com"
baseAPITestnetURL = "https://testnet.binance.vision"
var (
BaseAPIMainURL = "https://api.binance.com"
BaseAPITestnetURL = "https://testnet.binance.vision"
)

// UseTestnet switch all the API endpoints from production to the testnet
Expand Down Expand Up @@ -261,9 +261,9 @@ func newJSON(data []byte) (j *simplejson.Json, err error) {
// getAPIEndpoint return the base endpoint of the Rest API according the UseTestnet flag
func getAPIEndpoint() string {
if UseTestnet {
return baseAPITestnetURL
return BaseAPITestnetURL
}
return baseAPIMainURL
return BaseAPIMainURL
}

// NewClient initialize an API client instance with API key and secret key.
Expand Down
2 changes: 1 addition & 1 deletion v2/exchange_info_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ func (s *Symbol) MarketLotSizeFilter() *MarketLotSizeFilter {
return nil
}

//For specific meanings, please refer to the type definition MaxNumOrders
// For specific meanings, please refer to the type definition MaxNumOrders
func (s *Symbol) MaxNumOrdersFilter() *MaxNumOrdersFilter {
for _, filter := range s.Filters {
if filter["filterType"].(string) == string(SymbolFilterTypeMaxNumOrders) {
Expand Down
15 changes: 9 additions & 6 deletions v2/futures/mark_price.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ func (s *PremiumIndexService) Do(ctx context.Context, opts ...RequestOption) (re

// PremiumIndex define premium index of mark price
type PremiumIndex struct {
Symbol string `json:"symbol"`
MarkPrice string `json:"markPrice"`
LastFundingRate string `json:"lastFundingRate"`
NextFundingTime int64 `json:"nextFundingTime"`
Time int64 `json:"time"`
Symbol string `json:"symbol"`
MarkPrice string `json:"markPrice"`
IndexPrice string `json:"indexPrice"`
EstimatedSettlePrice string `json:"estimatedSettlePrice"`
LastFundingRate string `json:"lastFundingRate"`
NextFundingTime int64 `json:"nextFundingTime"`
InterestRate string `json:"interestRate"`
Time int64 `json:"time"`
}

// FundingRateService get funding rate
Expand Down Expand Up @@ -119,7 +122,7 @@ type FundingRate struct {
Symbol string `json:"symbol"`
FundingRate string `json:"fundingRate"`
FundingTime int64 `json:"fundingTime"`
Time int64 `json:"time"`
MarkPrice string `json:"markPrice"`
}

// GetLeverageBracketService get funding rate
Expand Down
29 changes: 19 additions & 10 deletions v2/futures/mark_price_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ func (s *premiumIndexServiceTestSuite) TestGetPremiumIndex() {
data := []byte(`[{
"symbol": "BTCUSDT",
"markPrice": "11012.80409769",
"indexPrice": "11781.80495970",
"estimatedSettlePrice": "11781.80495970",
"lastFundingRate": "-0.03750000",
"nextFundingTime": 1562569200000,
"interestRate": "0.00010000",
"time": 1562566020000
}]`)
s.mockDo(data, nil)
Expand All @@ -36,11 +39,14 @@ func (s *premiumIndexServiceTestSuite) TestGetPremiumIndex() {
res, err := s.client.NewPremiumIndexService().Symbol(symbol).Do(newContext())
s.r().NoError(err)
e := []*PremiumIndex{&PremiumIndex{
Symbol: symbol,
MarkPrice: "11012.80409769",
LastFundingRate: "-0.03750000",
NextFundingTime: int64(1562569200000),
Time: int64(1562566020000),
Symbol: symbol,
MarkPrice: "11012.80409769",
IndexPrice: "11781.80495970",
EstimatedSettlePrice: "11781.80495970",
LastFundingRate: "-0.03750000",
NextFundingTime: int64(1562569200000),
InterestRate: "0.00010000",
Time: int64(1562566020000),
},
}
s.assertPremiumIndexEqual(e, res)
Expand All @@ -50,8 +56,11 @@ func (s *premiumIndexServiceTestSuite) assertPremiumIndexEqual(e, a []*PremiumIn
r := s.r()
r.Equal(e[0].Symbol, a[0].Symbol, "Symbol")
r.Equal(e[0].MarkPrice, a[0].MarkPrice, "MarkPrice")
r.Equal(e[0].IndexPrice, a[0].IndexPrice, "IndexPrice")
r.Equal(e[0].EstimatedSettlePrice, a[0].EstimatedSettlePrice, "EstimatedSettlePrice")
r.Equal(e[0].LastFundingRate, a[0].LastFundingRate, "LastFundingRate")
r.Equal(e[0].NextFundingTime, a[0].NextFundingTime, "NextFundingTime")
r.Equal(e[0].InterestRate, a[0].InterestRate, "InterestRate")
r.Equal(e[0].Time, a[0].Time, "Time")
}

Expand All @@ -69,13 +78,13 @@ func (s *fundingRateServiceTestSuite) TestGetFundingRate() {
"symbol": "BTCUSDT",
"fundingRate": "-0.03750000",
"fundingTime": 1570608000000,
"time": 1576566020000
"markPrice": "1576566020000"
},
{
"symbol": "BTCUSDT",
"fundingRate": "0.00010000",
"fundingTime": 1570636800000,
"time": 1576566020000
"markPrice": "1576566020000"
}
]`)
s.mockDo(data, nil)
Expand Down Expand Up @@ -103,13 +112,13 @@ func (s *fundingRateServiceTestSuite) TestGetFundingRate() {
Symbol: symbol,
FundingRate: "-0.03750000",
FundingTime: int64(1570608000000),
Time: int64(1576566020000),
MarkPrice: "1576566020000",
},
{
Symbol: symbol,
FundingRate: "0.00010000",
FundingTime: int64(1570636800000),
Time: int64(1576566020000),
MarkPrice: "1576566020000",
},
}
s.r().Len(res, len(e))
Expand All @@ -123,7 +132,7 @@ func (s *fundingRateServiceTestSuite) assertFundingRateEqual(e, a *FundingRate)
r.Equal(e.Symbol, a.Symbol, "Symbol")
r.Equal(e.FundingRate, a.FundingRate, "FundingRate")
r.Equal(e.FundingTime, a.FundingTime, "FundingTime")
r.Equal(e.Time, a.Time, "Time")
r.Equal(e.MarkPrice, a.MarkPrice, "MarkPrice")
}

type getLeverageBracketServiceTestSuite struct {
Expand Down
102 changes: 55 additions & 47 deletions v2/futures/order_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,29 +204,34 @@ func (s *CreateOrderService) Do(ctx context.Context, opts ...RequestOption) (res

// CreateOrderResponse define create order response
type CreateOrderResponse struct {
Symbol string `json:"symbol"`
OrderID int64 `json:"orderId"`
ClientOrderID string `json:"clientOrderId"`
Price string `json:"price"`
OrigQuantity string `json:"origQty"`
ExecutedQuantity string `json:"executedQty"`
CumQuote string `json:"cumQuote"`
ReduceOnly bool `json:"reduceOnly"`
Status OrderStatusType `json:"status"`
StopPrice string `json:"stopPrice"`
TimeInForce TimeInForceType `json:"timeInForce"`
Type OrderType `json:"type"`
Side SideType `json:"side"`
UpdateTime int64 `json:"updateTime"`
WorkingType WorkingType `json:"workingType"`
ActivatePrice string `json:"activatePrice"`
PriceRate string `json:"priceRate"`
AvgPrice string `json:"avgPrice"`
PositionSide PositionSideType `json:"positionSide"`
ClosePosition bool `json:"closePosition"`
PriceProtect bool `json:"priceProtect"`
RateLimitOrder10s string `json:"rateLimitOrder10s,omitempty"`
RateLimitOrder1m string `json:"rateLimitOrder1m,omitempty"`
Symbol string `json:"symbol"` //
OrderID int64 `json:"orderId"` //
ClientOrderID string `json:"clientOrderId"` //
Price string `json:"price"` //
OrigQuantity string `json:"origQty"` //
ExecutedQuantity string `json:"executedQty"` //
CumQuote string `json:"cumQuote"` //
ReduceOnly bool `json:"reduceOnly"` //
Status OrderStatusType `json:"status"` //
StopPrice string `json:"stopPrice"` // please ignore when order type is TRAILING_STOP_MARKET
TimeInForce TimeInForceType `json:"timeInForce"` //
Type OrderType `json:"type"` //
Side SideType `json:"side"` //
UpdateTime int64 `json:"updateTime"` // update time
WorkingType WorkingType `json:"workingType"` //
ActivatePrice string `json:"activatePrice"` // activation price, only return with TRAILING_STOP_MARKET order
PriceRate string `json:"priceRate"` // callback rate, only return with TRAILING_STOP_MARKET order
AvgPrice string `json:"avgPrice"` //
PositionSide PositionSideType `json:"positionSide"` //
ClosePosition bool `json:"closePosition"` // if Close-All
PriceProtect bool `json:"priceProtect"` // if conditional order trigger is protected
PriceMatch string `json:"priceMatch"` // price match mode
SelfTradePreventionMode string `json:"selfTradePreventionMode"` // self trading preventation mode
GoodTillDate int64 `json:"goodTillDate"` // order pre-set auto cancel time for TIF GTD order
CumQty string `json:"cumQty"` //
OrigType OrderType `json:"origType"` //
RateLimitOrder10s string `json:"rateLimitOrder10s,omitempty"` //
RateLimitOrder1m string `json:"rateLimitOrder1m,omitempty"` //
}

// ListOpenOrdersService list opened orders
Expand Down Expand Up @@ -368,30 +373,33 @@ func (s *GetOrderService) Do(ctx context.Context, opts ...RequestOption) (res *O

// Order define order info
type Order struct {
Symbol string `json:"symbol"`
OrderID int64 `json:"orderId"`
ClientOrderID string `json:"clientOrderId"`
Price string `json:"price"`
ReduceOnly bool `json:"reduceOnly"`
OrigQuantity string `json:"origQty"`
ExecutedQuantity string `json:"executedQty"`
CumQuantity string `json:"cumQty"`
CumQuote string `json:"cumQuote"`
Status OrderStatusType `json:"status"`
TimeInForce TimeInForceType `json:"timeInForce"`
Type OrderType `json:"type"`
Side SideType `json:"side"`
StopPrice string `json:"stopPrice"`
Time int64 `json:"time"`
UpdateTime int64 `json:"updateTime"`
WorkingType WorkingType `json:"workingType"`
ActivatePrice string `json:"activatePrice"`
PriceRate string `json:"priceRate"`
AvgPrice string `json:"avgPrice"`
OrigType string `json:"origType"`
PositionSide PositionSideType `json:"positionSide"`
PriceProtect bool `json:"priceProtect"`
ClosePosition bool `json:"closePosition"`
Symbol string `json:"symbol"`
OrderID int64 `json:"orderId"`
ClientOrderID string `json:"clientOrderId"`
Price string `json:"price"`
ReduceOnly bool `json:"reduceOnly"`
OrigQuantity string `json:"origQty"`
ExecutedQuantity string `json:"executedQty"`
CumQuantity string `json:"cumQty"`
CumQuote string `json:"cumQuote"`
Status OrderStatusType `json:"status"`
TimeInForce TimeInForceType `json:"timeInForce"`
Type OrderType `json:"type"`
Side SideType `json:"side"`
StopPrice string `json:"stopPrice"`
Time int64 `json:"time"`
UpdateTime int64 `json:"updateTime"`
WorkingType WorkingType `json:"workingType"`
ActivatePrice string `json:"activatePrice"`
PriceRate string `json:"priceRate"`
AvgPrice string `json:"avgPrice"`
OrigType OrderType `json:"origType"`
PositionSide PositionSideType `json:"positionSide"`
PriceProtect bool `json:"priceProtect"`
ClosePosition bool `json:"closePosition"`
PriceMatch string `json:"priceMatch"`
SelfTradePreventionMode string `json:"selfTradePreventionMode"`
GoodTillDate int64 `json:"goodTillDate"`
}

// ListOrdersService all account orders; active, canceled, or filled
Expand Down
51 changes: 27 additions & 24 deletions v2/futures/order_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -665,30 +665,33 @@ func (s *orderServiceTestSuite) TestCreateBatchOrders() {
N: 3,
Orders: []*Order{
{
Symbol: "BTCUSDT",
OrderID: 22542179,
ClientOrderID: "testOrder",
Price: "100",
ReduceOnly: false,
OrigQuantity: "10",
ExecutedQuantity: "0",
CumQuantity: "0",
CumQuote: "0",
Status: "NEW",
TimeInForce: "GTC",
Type: "TRAILING_STOP_MARKET",
Side: "BUY",
StopPrice: "9300",
Time: 0,
UpdateTime: 1566818724722,
WorkingType: "CONTRACT_PRICE",
ActivatePrice: "9020",
PriceRate: "0.3",
AvgPrice: "0.00000",
OrigType: "TRAILING_STOP_MARKET",
PositionSide: "SHORT",
PriceProtect: false,
ClosePosition: false,
Symbol: "BTCUSDT",
OrderID: 22542179,
ClientOrderID: "testOrder",
Price: "100",
ReduceOnly: false,
OrigQuantity: "10",
ExecutedQuantity: "0",
CumQuantity: "0",
CumQuote: "0",
Status: "NEW",
TimeInForce: "GTC",
Type: "TRAILING_STOP_MARKET",
Side: "BUY",
StopPrice: "9300",
Time: 0,
UpdateTime: 1566818724722,
WorkingType: "CONTRACT_PRICE",
ActivatePrice: "9020",
PriceRate: "0.3",
AvgPrice: "0.00000",
OrigType: "TRAILING_STOP_MARKET",
PositionSide: "SHORT",
PriceProtect: false,
ClosePosition: false,
PriceMatch: "NONE",
SelfTradePreventionMode: "NONE",
GoodTillDate: 0,
},
},
Errors: []error{
Expand Down
64 changes: 34 additions & 30 deletions v2/futures/websocket_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1035,36 +1035,40 @@ type WsPosition struct {

// WsOrderTradeUpdate define order trade update
type WsOrderTradeUpdate struct {
Symbol string `json:"s"`
ClientOrderID string `json:"c"`
Side SideType `json:"S"`
Type OrderType `json:"o"`
TimeInForce TimeInForceType `json:"f"`
OriginalQty string `json:"q"`
OriginalPrice string `json:"p"`
AveragePrice string `json:"ap"`
StopPrice string `json:"sp"`
ExecutionType OrderExecutionType `json:"x"`
Status OrderStatusType `json:"X"`
ID int64 `json:"i"`
LastFilledQty string `json:"l"`
AccumulatedFilledQty string `json:"z"`
LastFilledPrice string `json:"L"`
CommissionAsset string `json:"N"`
Commission string `json:"n"`
TradeTime int64 `json:"T"`
TradeID int64 `json:"t"`
BidsNotional string `json:"b"`
AsksNotional string `json:"a"`
IsMaker bool `json:"m"`
IsReduceOnly bool `json:"R"`
WorkingType WorkingType `json:"wt"`
OriginalType OrderType `json:"ot"`
PositionSide PositionSideType `json:"ps"`
IsClosingPosition bool `json:"cp"`
ActivationPrice string `json:"AP"`
CallbackRate string `json:"cr"`
RealizedPnL string `json:"rp"`
Symbol string `json:"s"` // Symbol
ClientOrderID string `json:"c"` // Client order ID
Side SideType `json:"S"` // Side
Type OrderType `json:"o"` // Order type
TimeInForce TimeInForceType `json:"f"` // Time in force
OriginalQty string `json:"q"` // Original quantity
OriginalPrice string `json:"p"` // Original price
AveragePrice string `json:"ap"` // Average price
StopPrice string `json:"sp"` // Stop price. Please ignore with TRAILING_STOP_MARKET order
ExecutionType OrderExecutionType `json:"x"` // Execution type
Status OrderStatusType `json:"X"` // Order status
ID int64 `json:"i"` // Order ID
LastFilledQty string `json:"l"` // Order Last Filled Quantity
AccumulatedFilledQty string `json:"z"` // Order Filled Accumulated Quantity
LastFilledPrice string `json:"L"` // Last Filled Price
CommissionAsset string `json:"N"` // Commission Asset, will not push if no commission
Commission string `json:"n"` // Commission, will not push if no commission
TradeTime int64 `json:"T"` // Order Trade Time
TradeID int64 `json:"t"` // Trade ID
BidsNotional string `json:"b"` // Bids Notional
AsksNotional string `json:"a"` // Asks Notional
IsMaker bool `json:"m"` // Is this trade the maker side?
IsReduceOnly bool `json:"R"` // Is this reduce only
WorkingType WorkingType `json:"wt"` // Stop Price Working Type
OriginalType OrderType `json:"ot"` // Original Order Type
PositionSide PositionSideType `json:"ps"` // Position Side
IsClosingPosition bool `json:"cp"` // If Close-All, pushed with conditional order
ActivationPrice string `json:"AP"` // Activation Price, only puhed with TRAILING_STOP_MARKET order
CallbackRate string `json:"cr"` // Callback Rate, only puhed with TRAILING_STOP_MARKET order
PriceProtect bool `json:"pP"` // If price protection is turned on
RealizedPnL string `json:"rp"` // Realized Profit of the trade
STP string `json:"V"` // STP mode
PriceMode string `json:"pm"` // Price match mode
GTD int64 `json:"gtd"` // TIF GTD order auto cancel time
}

// WsAccountConfigUpdate define account config update
Expand Down
Loading

0 comments on commit 0c79288

Please sign in to comment.