Skip to content

Commit

Permalink
Merge pull request #11 from tiagosiebler/#10/sign
Browse files Browse the repository at this point in the history
fix(#10): signature error for param-less non-GET requests
  • Loading branch information
tiagosiebler authored May 5, 2021
2 parents 4ec5aa3 + 09dcacc commit daf8cb0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ftx-api",
"version": "1.0.6",
"version": "1.0.7",
"description": "Node.js connector for FTX's REST APIs and WebSockets",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
11 changes: 7 additions & 4 deletions src/util/requestWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ export default class RequestUtil {
};
}

getRequestSignature(
private getRequestSignature(
method: Method,
endpoint: string,
secret: string | undefined,
params: string | object = ''
secret?: string | undefined,
params?: string | object
): { timestamp: number; sign: string; } {
const timestamp = Date.now() + (this.timeOffset || 0);
if (!secret) {
Expand All @@ -188,7 +188,10 @@ export default class RequestUtil {
};
}

const paramsPayload = method == 'GET' ? params : JSON.stringify(params);
const paramsPayload = method === 'GET'
? params
: params ? JSON.stringify(params) : '';

const signature_payload = `${timestamp}${method}/api/${endpoint}${paramsPayload}`;
return {
timestamp,
Expand Down

0 comments on commit daf8cb0

Please sign in to comment.