Skip to content

Commit

Permalink
feat: added self trade prevention mode to spot client
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur Abelian committed Nov 13, 2024
1 parent f3ca3ee commit 0bc676c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 27 deletions.
3 changes: 3 additions & 0 deletions v2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ var (
BaseAPITestnetURL = "https://testnet.binance.vision"
)

// SelfTradePreventionMode define self trade prevention strategy
type SelfTradePreventionMode string

// UseTestnet switch all the API endpoints from production to the testnet
var UseTestnet = false

Expand Down
67 changes: 40 additions & 27 deletions v2/order_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@ import (

// CreateOrderService create order
type CreateOrderService struct {
c *Client
symbol string
side SideType
orderType OrderType
timeInForce *TimeInForceType
newOrderRespType *NewOrderRespType
quantity *string
quoteOrderQty *string
price *string
newClientOrderID *string
stopPrice *string
trailingDelta *string
icebergQuantity *string
c *Client
symbol string
side SideType
orderType OrderType
timeInForce *TimeInForceType
newOrderRespType *NewOrderRespType
quantity *string
quoteOrderQty *string
price *string
newClientOrderID *string
stopPrice *string
trailingDelta *string
icebergQuantity *string
selfTradePreventionMode *SelfTradePreventionMode
}

// Symbol set symbol
Expand Down Expand Up @@ -95,6 +96,12 @@ func (s *CreateOrderService) NewOrderRespType(newOrderRespType NewOrderRespType)
return s
}

// SelfTradePreventionMode set selfTradePreventionMode
func (s *CreateOrderService) SelfTradePreventionMode(selfTradePreventionMode SelfTradePreventionMode) *CreateOrderService {
s.selfTradePreventionMode = &selfTradePreventionMode
return s
}

func (s *CreateOrderService) createOrder(ctx context.Context, endpoint string, opts ...RequestOption) (data []byte, err error) {
r := &request{
method: http.MethodPost,
Expand Down Expand Up @@ -133,6 +140,9 @@ func (s *CreateOrderService) createOrder(ctx context.Context, endpoint string, o
if s.newOrderRespType != nil {
m["newOrderRespType"] = *s.newOrderRespType
}
if s.selfTradePreventionMode != nil {
m["selfTradePreventionMode"] = *s.selfTradePreventionMode
}
r.setFormParams(m)
data, err = s.c.callAPI(ctx, r, opts...)
if err != nil {
Expand Down Expand Up @@ -182,6 +192,8 @@ type CreateOrderResponse struct {
Fills []*Fill `json:"fills"`
MarginBuyBorrowAmount string `json:"marginBuyBorrowAmount"` // for margin
MarginBuyBorrowAsset string `json:"marginBuyBorrowAsset"`

SelfTradePreventionMode SelfTradePreventionMode `json:"selfTradePreventionMode"`
}

// Fill may be returned in an array of fills in a CreateOrderResponse.
Expand Down Expand Up @@ -787,20 +799,21 @@ type CancelOpenOrdersResponse struct {

// CancelOrderResponse may be returned included in a CancelOpenOrdersResponse.
type CancelOrderResponse struct {
Symbol string `json:"symbol"`
OrigClientOrderID string `json:"origClientOrderId"`
OrderID int64 `json:"orderId"`
OrderListID int64 `json:"orderListId"`
ClientOrderID string `json:"clientOrderId"`
TransactTime int64 `json:"transactTime"`
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"`
Symbol string `json:"symbol"`
OrigClientOrderID string `json:"origClientOrderId"`
OrderID int64 `json:"orderId"`
OrderListID int64 `json:"orderListId"`
ClientOrderID string `json:"clientOrderId"`
TransactTime int64 `json:"transactTime"`
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"`
SelfTradePreventionMode SelfTradePreventionMode `json:"selfTradePreventionMode"`
}

// CancelOCOResponse may be returned included in a CancelOpenOrdersResponse.
Expand Down

0 comments on commit 0bc676c

Please sign in to comment.