Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion v2/futures/order_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,9 @@ func (s *CancelMultiplesOrdersService) Do(ctx context.Context, opts ...RequestOp
r.setFormParam("orderIdList", orderIDListString)
}
if s.origClientOrderIDList != nil {
r.setFormParam("origClientOrderIdList", s.origClientOrderIDList)
// convert a slice of strings to a string e.g. ["my_id_1","my_id_2"], encode the double quotes. No space after comma.
Copy link

Copilot AI Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment states "encode the double quotes," but the implementation doesn't actually encode them - it embeds literal escaped quotes in the string using backslash notation. If the API requires URL-encoded double quotes, consider using url.QueryEscape or clarifying the comment to accurately describe what the code does (e.g., "escape the double quotes with backslashes").

Suggested change
// convert a slice of strings to a string e.g. ["my_id_1","my_id_2"], encode the double quotes. No space after comma.
// convert a slice of strings to a JSON-style array string e.g. ["my_id_1","my_id_2"], escaping the double quotes with backslashes. No space after comma.

Copilot uses AI. Check for mistakes.
origClientOrderIDListString := "[\"" + strings.Join(s.origClientOrderIDList, "\",\"") + "\"]"
Copy link

Copilot AI Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The formatting approach is inconsistent with the options API implementation in v2/options/order_service.go (lines 453-459), which uses a different pattern involving fmt.Sprintf to quote individual elements. While both approaches could work, consider aligning the implementation for consistency across the codebase. The options implementation uses fmt.Sprint on the slice which handles edge cases differently.

Suggested change
origClientOrderIDListString := "[\"" + strings.Join(s.origClientOrderIDList, "\",\"") + "\"]"
list := fmt.Sprint(s.origClientOrderIDList) // e.g. "[my_id_1 my_id_2]"
list = strings.Trim(list, "[]")
origClientOrderIDListString := "[]"
if list != "" {
items := strings.Split(list, " ")
for i, v := range items {
items[i] = fmt.Sprintf("%q", v)
}
origClientOrderIDListString = "[" + strings.Join(items, ",") + "]"
}

Copilot uses AI. Check for mistakes.
r.setFormParam("origClientOrderIdList", origClientOrderIDListString)
Comment on lines +795 to +796
Copy link

Copilot AI Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The string formatting logic doesn't handle empty slices correctly. When origClientOrderIDList is an empty slice (not nil, but length 0), this code will produce the string [""] instead of []. This happens because strings.Join on an empty slice returns an empty string, and the code then wraps it with [" + "" + "].

Consider checking the length of the slice before formatting, similar to how the nil check is done.

Suggested change
origClientOrderIDListString := "[\"" + strings.Join(s.origClientOrderIDList, "\",\"") + "\"]"
r.setFormParam("origClientOrderIdList", origClientOrderIDListString)
if len(s.origClientOrderIDList) == 0 {
r.setFormParam("origClientOrderIdList", "[]")
} else {
origClientOrderIDListString := "[\"" + strings.Join(s.origClientOrderIDList, "\",\"") + "\"]"
r.setFormParam("origClientOrderIdList", origClientOrderIDListString)
}

Copilot uses AI. Check for mistakes.
Comment on lines +794 to +796
Copy link

Copilot AI Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The string concatenation doesn't handle special characters that could appear in client order IDs. If an order ID contains a double quote character, the resulting string will be malformed. Consider using json.Marshal for proper escaping of special characters in the string values, or add validation/escaping for characters like quotes and backslashes.

Suggested change
// convert a slice of strings to a string e.g. ["my_id_1","my_id_2"], encode the double quotes. No space after comma.
origClientOrderIDListString := "[\"" + strings.Join(s.origClientOrderIDList, "\",\"") + "\"]"
r.setFormParam("origClientOrderIdList", origClientOrderIDListString)
// convert a slice of strings to a JSON array string, ensuring proper escaping of special characters
origClientOrderIDListJSON, err := json.Marshal(s.origClientOrderIDList)
if err != nil {
return nil, err
}
r.setFormParam("origClientOrderIdList", string(origClientOrderIDListJSON))

Copilot uses AI. Check for mistakes.
}
data, _, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
Expand Down
Loading