Skip to content

Commit

Permalink
feat: added self trade prevention mode to futures ws client
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur Abelian committed Nov 13, 2024
1 parent 0bc676c commit b3d4f87
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pkg/
.idea
*.iml
.env
coverage.txt
5 changes: 5 additions & 0 deletions v2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,11 @@ const (
FuturesAlgoOrderStatusTypeWorking FuturesAlgoOrderStatusType = "WORKING"
FuturesAlgoOrderStatusTypeFinished FuturesAlgoOrderStatusType = "FINISHED"
FuturesAlgoOrderStatusTypeCancelled FuturesAlgoOrderStatusType = "CANCELLED"

SelfTradePreventionModeNone SelfTradePreventionMode = "NONE"
SelfTradePreventionModeExpireTaker SelfTradePreventionMode = "EXPIRE_TAKER"
SelfTradePreventionModeExpireBoth SelfTradePreventionMode = "EXPIRE_BOTH"
SelfTradePreventionModeExpireMaker SelfTradePreventionMode = "EXPIRE_MAKER"
)

func currentTimestamp() int64 {
Expand Down
42 changes: 26 additions & 16 deletions v2/futures/order_place_service_ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,23 @@ type OrderPlaceWsService struct {

// OrderPlaceWsRequest parameters for 'order.place' websocket API
type OrderPlaceWsRequest struct {
symbol string
side SideType
positionSide *PositionSideType
orderType OrderType
timeInForce *TimeInForceType
quantity string
reduceOnly *bool
price *string
newClientOrderID *string
stopPrice *string
workingType *WorkingType
activationPrice *string
callbackRate *string
priceProtect *bool
newOrderRespType NewOrderRespType
closePosition *bool
symbol string
side SideType
positionSide *PositionSideType
orderType OrderType
timeInForce *TimeInForceType
quantity string
reduceOnly *bool
price *string
newClientOrderID *string
stopPrice *string
workingType *WorkingType
activationPrice *string
callbackRate *string
priceProtect *bool
newOrderRespType NewOrderRespType
closePosition *bool
selfTradePreventionMode *SelfTradePreventionMode
}

// NewOrderPlaceWsRequest init OrderPlaceWsRequest
Expand Down Expand Up @@ -134,6 +135,12 @@ func (s *OrderPlaceWsRequest) ClosePosition(closePosition bool) *OrderPlaceWsReq
return s
}

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

// CreateOrderResult define order creation result
type CreateOrderResult struct {
CreateOrderResponse
Expand Down Expand Up @@ -193,6 +200,9 @@ func (s *OrderPlaceWsRequest) buildParams() params {
if s.closePosition != nil {
m["closePosition"] = *s.closePosition
}
if s.selfTradePreventionMode != nil {
m["selfTradePreventionMode"] = *s.selfTradePreventionMode
}

return m
}
Expand Down

0 comments on commit b3d4f87

Please sign in to comment.