Comparing version 1.0.10 to 1.0.11
@@ -34,5 +34,8 @@ import { AxiosRequestConfig } from 'axios'; | ||
export declare function serializeParams(params?: object, strict_validation?: boolean): string; | ||
export declare function serializeParamPayload(isGetRequest: boolean, params?: string | object, strictParamValidation?: boolean): string | undefined; | ||
export declare type apiNetwork = 'ftxcom' | 'ftxus'; | ||
export declare const programId = "ftxnodeapi"; | ||
export declare const programKey = "externalReferralProgram"; | ||
export declare function getRestBaseUrl(restClientOptions: RestClientOptions): string; | ||
export declare function getWsUrl(options: WebsocketClientOptions): string; | ||
export declare function isPublicEndpoint(endpoint: string): boolean; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isPublicEndpoint = exports.getWsUrl = exports.getRestBaseUrl = exports.serializeParams = exports.signWsAuthenticate = exports.signMessage = void 0; | ||
exports.isPublicEndpoint = exports.getWsUrl = exports.getRestBaseUrl = exports.programKey = exports.programId = exports.serializeParamPayload = exports.serializeParams = exports.signWsAuthenticate = exports.signMessage = void 0; | ||
const crypto_1 = require("crypto"); | ||
@@ -35,2 +35,18 @@ ; | ||
; | ||
function serializeParamPayload(isGetRequest, params, strictParamValidation) { | ||
if (!params) { | ||
return ''; | ||
} | ||
if (!isGetRequest) { | ||
return JSON.stringify(params); | ||
} | ||
if (typeof params === 'string') { | ||
return '?' + params; | ||
} | ||
return '?' + serializeParams(params, strictParamValidation); | ||
} | ||
exports.serializeParamPayload = serializeParamPayload; | ||
; | ||
exports.programId = 'ftxnodeapi'; | ||
exports.programKey = 'externalReferralProgram'; | ||
function getRestBaseUrl(restClientOptions) { | ||
@@ -37,0 +53,0 @@ if (restClientOptions.baseUrl) { |
@@ -6,3 +6,2 @@ import { AxiosRequestConfig, Method } from 'axios'; | ||
private syncTimePromise; | ||
private programId; | ||
private options; | ||
@@ -9,0 +8,0 @@ private baseUrl; |
@@ -49,3 +49,2 @@ "use strict"; | ||
this.syncTimePromise = null; | ||
this.programId = 'ftxnodeapi'; | ||
this.options = Object.assign({ recv_window: 5000, | ||
@@ -81,3 +80,3 @@ // how often to sync time drift with exchange servers | ||
post(endpoint, params) { | ||
return this._call('POST', endpoint, Object.assign({ externalReferralProgram: this.programId }, params)); | ||
return this._call('POST', endpoint, Object.assign(Object.assign({}, params), { [requestUtils_1.programKey]: requestUtils_1.programId })); | ||
} | ||
@@ -94,2 +93,4 @@ delete(endpoint, params) { | ||
options.url = endpoint.startsWith('https') ? endpoint : [this.baseUrl, endpoint].join('/'); | ||
const isGetRequest = method === 'GET'; | ||
const serialisedParams = requestUtils_1.serializeParamPayload(isGetRequest, params, this.options.strict_param_validation); | ||
// Add request sign | ||
@@ -100,8 +101,8 @@ if (this.key && this.secret) { | ||
} | ||
const { timestamp, sign } = this.getRequestSignature(method, endpoint, this.secret, params); | ||
const { timestamp, sign } = this.getRequestSignature(method, endpoint, this.secret, serialisedParams); | ||
options.headers[getHeader('ts', this.options.domain)] = String(timestamp); | ||
options.headers[getHeader('sign', this.options.domain)] = sign; | ||
} | ||
if (method === 'GET') { | ||
options.params = params; | ||
if (isGetRequest) { | ||
options.url += serialisedParams; | ||
} | ||
@@ -145,3 +146,3 @@ else { | ||
} | ||
getRequestSignature(method, endpoint, secret, params = '') { | ||
getRequestSignature(method, endpoint, secret, serialisedParams = '') { | ||
const timestamp = Date.now() + (this.timeOffset || 0); | ||
@@ -154,6 +155,3 @@ if (!secret) { | ||
} | ||
const paramsPayload = method === 'GET' | ||
? params | ||
: params ? JSON.stringify(params) : ''; | ||
const signature_payload = `${timestamp}${method}/api/${endpoint}${paramsPayload}`; | ||
const signature_payload = `${timestamp}${method}/api/${endpoint}${serialisedParams}`; | ||
return { | ||
@@ -160,0 +158,0 @@ timestamp, |
{ | ||
"name": "ftx-api", | ||
"version": "1.0.10", | ||
"version": "1.0.11", | ||
"description": "Node.js connector for FTX's REST APIs and WebSockets", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
116463
1925