-
Notifications
You must be signed in to change notification settings - Fork 774
feat(client): add spotCloseDataStream #953
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -656,14 +656,19 @@ export default class Binance { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async signedRequest(url: string, data: Dict = {}, method: HttpMethod = 'GET', noDataInSignature = false) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.requireApiSecret('signedRequest'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const isListenKeyEndpoint = url.includes('v3/userDataStream'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data.timestamp = new Date().getTime(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (this.timeOffset) data.timestamp += this.timeOffset; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!data.recvWindow) data.recvWindow = this.Options.recvWindow; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const query = method === 'POST' && noDataInSignature ? '' : this.makeQueryString(data); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const signature = this.generateSignature(query); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let signature = undefined; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let signature = undefined; | |
| let signature; |
Copilot
AI
Sep 6, 2025
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 error handling logic for missing listenKey is duplicated across both methods. Consider extracting this validation into a private helper method to reduce code duplication.
| async spotKeepDataStream(listenKey: string | undefined = undefined, params: Dict = {}) { | |
| listenKey = listenKey || this.Options.listenKey; | |
| if (!listenKey) throw new Error('A listenKey is required, either as an argument or in this.Options.listenKey'); | |
| return await this.privateSpotRequest('v3/userDataStream', { listenKey, ...params }, 'PUT'); | |
| } | |
| async spotCloseDataStream(listenKey: string | undefined = undefined, params: Dict = {}) { | |
| listenKey = listenKey || this.Options.listenKey; | |
| if (!listenKey) throw new Error('A listenKey is required, either as an argument or in this.Options.listenKey'); | |
| return await this.privateSpotRequest('v3/userDataStream', { listenKey, ...params }, 'DELETE'); | |
| /** | |
| * Helper to validate and retrieve a listenKey from argument or options. | |
| * Throws if neither is present. | |
| */ | |
| private _getValidListenKey(listenKey?: string): string { | |
| const key = listenKey || this.Options.listenKey; | |
| if (!key) throw new Error('A listenKey is required, either as an argument or in this.Options.listenKey'); | |
| return key; | |
| } | |
| async spotKeepDataStream(listenKey: string | undefined = undefined, params: Dict = {}) { | |
| const validListenKey = this._getValidListenKey(listenKey); | |
| return await this.privateSpotRequest('v3/userDataStream', { listenKey: validListenKey, ...params }, 'PUT'); | |
| } | |
| async spotCloseDataStream(listenKey: string | undefined = undefined, params: Dict = {}) { | |
| const validListenKey = this._getValidListenKey(listenKey); | |
| return await this.privateSpotRequest('v3/userDataStream', { listenKey: validListenKey, ...params }, 'DELETE'); |
Copilot
AI
Sep 6, 2025
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 error handling logic for missing listenKey is duplicated across both methods. Consider extracting this validation into a private helper method to reduce code duplication.
| async spotKeepDataStream(listenKey: string | undefined = undefined, params: Dict = {}) { | |
| listenKey = listenKey || this.Options.listenKey; | |
| if (!listenKey) throw new Error('A listenKey is required, either as an argument or in this.Options.listenKey'); | |
| return await this.privateSpotRequest('v3/userDataStream', { listenKey, ...params }, 'PUT'); | |
| } | |
| async spotCloseDataStream(listenKey: string | undefined = undefined, params: Dict = {}) { | |
| listenKey = listenKey || this.Options.listenKey; | |
| if (!listenKey) throw new Error('A listenKey is required, either as an argument or in this.Options.listenKey'); | |
| return await this.privateSpotRequest('v3/userDataStream', { listenKey, ...params }, 'DELETE'); | |
| /** | |
| * Helper to get listenKey or throw error if missing | |
| */ | |
| private _getListenKeyOrThrow(listenKey?: string): string { | |
| const key = listenKey || this.Options.listenKey; | |
| if (!key) throw new Error('A listenKey is required, either as an argument or in this.Options.listenKey'); | |
| return key; | |
| } | |
| async spotKeepDataStream(listenKey: string | undefined = undefined, params: Dict = {}) { | |
| const key = this._getListenKeyOrThrow(listenKey); | |
| return await this.privateSpotRequest('v3/userDataStream', { listenKey: key, ...params }, 'PUT'); | |
| } | |
| async spotCloseDataStream(listenKey: string | undefined = undefined, params: Dict = {}) { | |
| const key = this._getListenKeyOrThrow(listenKey); | |
| return await this.privateSpotRequest('v3/userDataStream', { listenKey: key, ...params }, 'DELETE'); |
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.
Hard-coded URL path detection is fragile. Consider using a more robust method like checking against a constant or using URL parsing to identify listen key endpoints.