-
Notifications
You must be signed in to change notification settings - Fork 782
support place algo order via websocket api #795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,187 @@ | ||||||
| package binance | ||||||
|
|
||||||
| import ( | ||||||
| "encoding/json" | ||||||
| "time" | ||||||
|
|
||||||
| "github.com/adshao/go-binance/v2/common" | ||||||
| "github.com/adshao/go-binance/v2/common/websocket" | ||||||
| "github.com/adshao/go-binance/v2/futures" | ||||||
| ) | ||||||
|
|
||||||
| // AlgoOrderCancelWsService cancels algo order using WebSocket API | ||||||
| type AlgoOrderCancelWsService struct { | ||||||
| c websocket.Client | ||||||
| ApiKey string | ||||||
| SecretKey string | ||||||
| KeyType string | ||||||
| TimeOffset int64 | ||||||
| } | ||||||
|
|
||||||
| // NewAlgoOrderCancelWsService init AlgoOrderCancelWsService | ||||||
| func NewAlgoOrderCancelWsService(apiKey, secretKey string) (*AlgoOrderCancelWsService, error) { | ||||||
| conn, err := websocket.NewConnection(futures.WsApiInitReadWriteConn, futures.WebsocketKeepalive, futures.WebsocketTimeoutReadWriteConnection) | ||||||
| if err != nil { | ||||||
| return nil, err | ||||||
| } | ||||||
|
|
||||||
| client, err := websocket.NewClient(conn) | ||||||
| if err != nil { | ||||||
| return nil, err | ||||||
| } | ||||||
|
|
||||||
| return &AlgoOrderCancelWsService{ | ||||||
| c: client, | ||||||
| ApiKey: apiKey, | ||||||
| SecretKey: secretKey, | ||||||
| KeyType: common.KeyTypeHmac, | ||||||
| }, nil | ||||||
| } | ||||||
|
|
||||||
| // AlgoOrderCancelWsRequest parameters for 'algoOrder.cancel' websocket API | ||||||
| type AlgoOrderCancelWsRequest struct { | ||||||
| algoId *int64 | ||||||
| clientAlgoId *string | ||||||
| recvWindow *int64 | ||||||
| } | ||||||
|
|
||||||
| // NewAlgoOrderCancelWsRequest init AlgoOrderCancelWsRequest | ||||||
| func NewAlgoOrderCancelWsRequest() *AlgoOrderCancelWsRequest { | ||||||
| return &AlgoOrderCancelWsRequest{} | ||||||
| } | ||||||
|
|
||||||
| // AlgoID set algoID | ||||||
| func (s *AlgoOrderCancelWsRequest) AlgoID(algoID int64) *AlgoOrderCancelWsRequest { | ||||||
| s.algoId = &algoID | ||||||
| return s | ||||||
| } | ||||||
|
|
||||||
| // ClientAlgoID set clientAlgoID | ||||||
| func (s *AlgoOrderCancelWsRequest) ClientAlgoID(clientAlgoID string) *AlgoOrderCancelWsRequest { | ||||||
| s.clientAlgoId = &clientAlgoID | ||||||
| return s | ||||||
| } | ||||||
|
|
||||||
| // RecvWindow set recvWindow | ||||||
| func (s *AlgoOrderCancelWsRequest) RecvWindow(recvWindow int64) *AlgoOrderCancelWsRequest { | ||||||
| s.recvWindow = &recvWindow | ||||||
| return s | ||||||
| } | ||||||
|
|
||||||
| // buildParams builds params | ||||||
| func (s *AlgoOrderCancelWsRequest) buildParams() map[string]interface{} { | ||||||
| m := map[string]interface{}{} | ||||||
|
|
||||||
| if s.algoId != nil { | ||||||
| m["algoid"] = *s.algoId | ||||||
| } | ||||||
|
|
||||||
| if s.clientAlgoId != nil { | ||||||
| m["clientalgoid"] = *s.clientAlgoId | ||||||
|
||||||
| m["clientalgoid"] = *s.clientAlgoId | |
| m["clientAlgoId"] = *s.clientAlgoId |
Copilot
AI
Jan 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new AlgoOrderCancelWsService lacks test coverage. Other similar WebSocket services in this codebase (e.g., order_service_ws_create.go, sor_order_place_service_ws.go, order_list_cancel_service_ws.go) all have corresponding test files. Consider adding comprehensive tests to verify the service initialization, request building, parameter handling, and response parsing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parameter name should be "algoId" (camelCase) instead of "algoid" to match the API specification and maintain consistency with the REST API implementation in futures/algo_order_service.go which uses "algoId".