MCPcopy Create free account
hub / github.com/ccxt/node-binance-api / signedRequest

Method signedRequest

src/node-binance-api.ts:742–784  ·  view source on GitHub ↗

* Create a signed http request * @param {string} url - The http endpoint * @param {object} data - The data to send * @param {function} callback - The callback method to call * @param {string} method - the http method * @param {boolean} noDataInSignature - Prevents data from

(url: string, data: Dict = {}, method: HttpMethod = 'GET', noDataInSignature = false)

Source from the content-addressed store, hash-verified

740 * @return {undefined}
741 */
742 async signedRequest(url: string, data: Dict = {}, method: HttpMethod = 'GET', noDataInSignature = false) {
743 this.requireApiSecret('signedRequest');
744 const isListenKeyEndpoint = url.includes('v3/userDataStream');
745
746 let query = method === 'POST' && noDataInSignature ? '' : this.makeQueryString(data);
747
748 let signature = undefined;
749 if (!noDataInSignature && !isListenKeyEndpoint) {
750 data.timestamp = new Date().getTime();
751
752 if (this.timeOffset) data.timestamp += this.timeOffset;
753
754 if (!data.recvWindow) data.recvWindow = this.Options.recvWindow;
755 query = this.makeQueryString(data);
756 signature = this.generateSignature(query);
757 }
758
759 if (method === 'POST') {
760 const opt = this.reqObjPOST(
761 url,
762 data,
763 method,
764 this.APIKEY
765 );
766 if (signature) {
767 opt.form.signature = signature;
768 }
769 const reqPost = await this.proxyRequest(opt);
770 return reqPost;
771 } else {
772 let encodedUrl = url;
773 if (query) encodedUrl += '?' + query;
774 if (signature) encodedUrl += '&signature=' + signature;
775 const opt = this.reqObj(
776 encodedUrl,
777 data,
778 method,
779 this.APIKEY
780 );
781 const reqGet = await this.proxyRequest(opt);
782 return reqGet;
783 }
784 }
785
786 generateSignature(query: string, encode = true) {
787 const secret = this.APISECRET || this.PRIVATEKEY;

Callers 2

privateSpotRequestMethod · 0.95
privateSapiRequestMethod · 0.95

Calls 6

requireApiSecretMethod · 0.95
makeQueryStringMethod · 0.95
generateSignatureMethod · 0.95
reqObjPOSTMethod · 0.95
proxyRequestMethod · 0.95
reqObjMethod · 0.95

Tested by

no test coverage detected