Skip to content

Commit

Permalink
fix Mark Price, Order futures (#533)
Browse files Browse the repository at this point in the history
* fix Mark Price

* fix Order futures

* fix Mark Price, Order futures (remove commenting code)
  • Loading branch information
mmavka committed Mar 10, 2024
1 parent b962076 commit d8fca1e
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 87 deletions.
13 changes: 8 additions & 5 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
19 changes: 14 additions & 5 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 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
64 changes: 34 additions & 30 deletions v2/futures/websocket_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -999,36 +999,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

0 comments on commit d8fca1e

Please sign in to comment.