@medievalrain/binance-ts 0.5.0 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +16 -14
- package/dist/index.js +21 -23
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2,12 +2,6 @@ import z$1, { z } from "zod";
|
|
|
2
2
|
import { Client } from "undici";
|
|
3
3
|
import * as z4 from "zod/v4/core";
|
|
4
4
|
|
|
5
|
-
//#region src/types.d.ts
|
|
6
|
-
type ApiCredentials = {
|
|
7
|
-
key: string;
|
|
8
|
-
secret: string;
|
|
9
|
-
};
|
|
10
|
-
//#endregion
|
|
11
5
|
//#region src/rest/futures/schema.d.ts
|
|
12
6
|
declare const FuturesTestConnectivitySchema: z.ZodObject<{}, z.core.$strip>;
|
|
13
7
|
declare const FuturesCheckServerTimeSchema: z.ZodObject<{
|
|
@@ -793,15 +787,18 @@ declare const FuturesNewOrderSchema: z.ZodObject<{
|
|
|
793
787
|
//#region src/shared/base-rest-client.d.ts
|
|
794
788
|
type RawSearchParams = Record<string, string | undefined | null | string[] | number | boolean>;
|
|
795
789
|
declare class BaseRestClient {
|
|
796
|
-
private credentials?;
|
|
797
790
|
private httpCleint;
|
|
791
|
+
private apiKey?;
|
|
792
|
+
private apiSecret?;
|
|
798
793
|
constructor({
|
|
799
794
|
baseUrl,
|
|
800
|
-
|
|
795
|
+
apiKey,
|
|
796
|
+
apiSecret,
|
|
801
797
|
httpOptions
|
|
802
798
|
}: {
|
|
803
799
|
baseUrl: string;
|
|
804
|
-
|
|
800
|
+
apiKey?: string;
|
|
801
|
+
apiSecret?: string;
|
|
805
802
|
httpOptions?: Client.Options;
|
|
806
803
|
});
|
|
807
804
|
private toSearchParams;
|
|
@@ -896,10 +893,12 @@ type FuturesNewOrder = z$1.infer<typeof FuturesNewOrderSchema>;
|
|
|
896
893
|
declare class FuturesRestClient extends BaseRestClient {
|
|
897
894
|
constructor({
|
|
898
895
|
baseUrl,
|
|
899
|
-
|
|
896
|
+
apiKey,
|
|
897
|
+
apiSecret,
|
|
900
898
|
httpOptions
|
|
901
899
|
}: {
|
|
902
|
-
|
|
900
|
+
apiKey?: string;
|
|
901
|
+
apiSecret?: string;
|
|
903
902
|
baseUrl?: string;
|
|
904
903
|
httpOptions?: Client.Options;
|
|
905
904
|
});
|
|
@@ -1388,10 +1387,12 @@ declare class FuturesRestClient extends BaseRestClient {
|
|
|
1388
1387
|
declare class SpotRestClient extends BaseRestClient {
|
|
1389
1388
|
constructor({
|
|
1390
1389
|
baseUrl,
|
|
1391
|
-
|
|
1390
|
+
apiKey,
|
|
1391
|
+
apiSecret,
|
|
1392
1392
|
httpOptions
|
|
1393
1393
|
}: {
|
|
1394
|
-
|
|
1394
|
+
apiKey?: string;
|
|
1395
|
+
apiSecret?: string;
|
|
1395
1396
|
baseUrl?: string;
|
|
1396
1397
|
httpOptions?: Client.Options;
|
|
1397
1398
|
});
|
|
@@ -1406,7 +1407,8 @@ declare class BinanceRestClient {
|
|
|
1406
1407
|
futures: FuturesRestClient;
|
|
1407
1408
|
spot: SpotRestClient;
|
|
1408
1409
|
constructor(options?: {
|
|
1409
|
-
|
|
1410
|
+
apiKey?: string;
|
|
1411
|
+
apiSecret?: string;
|
|
1410
1412
|
baseUrls?: {
|
|
1411
1413
|
spot?: string;
|
|
1412
1414
|
futures?: string;
|
package/dist/index.js
CHANGED
|
@@ -582,7 +582,6 @@ var MalformedParamError = class extends ResponseError {
|
|
|
582
582
|
}
|
|
583
583
|
parseParam(message) {
|
|
584
584
|
const match = message.match(/'([^']+)'/);
|
|
585
|
-
if (match) console.log(match[1]);
|
|
586
585
|
if (!match) throw new ErrorMessageParsingError("Can't parse param data");
|
|
587
586
|
return String(match[1]);
|
|
588
587
|
}
|
|
@@ -598,10 +597,12 @@ const ErrorResponseSchema = z.object({
|
|
|
598
597
|
//#endregion
|
|
599
598
|
//#region src/shared/base-rest-client.ts
|
|
600
599
|
var BaseRestClient = class {
|
|
601
|
-
credentials;
|
|
602
600
|
httpCleint;
|
|
603
|
-
|
|
604
|
-
|
|
601
|
+
apiKey;
|
|
602
|
+
apiSecret;
|
|
603
|
+
constructor({ baseUrl, apiKey, apiSecret, httpOptions }) {
|
|
604
|
+
this.apiKey = apiKey;
|
|
605
|
+
this.apiSecret = apiSecret;
|
|
605
606
|
this.httpCleint = new Client(baseUrl, {
|
|
606
607
|
allowH2: true,
|
|
607
608
|
connect: {
|
|
@@ -665,26 +666,24 @@ var BaseRestClient = class {
|
|
|
665
666
|
method: "GET",
|
|
666
667
|
path: endpoint,
|
|
667
668
|
query: searchParams,
|
|
668
|
-
headers: { "X-MBX-APIKEY": this.
|
|
669
|
+
headers: { "X-MBX-APIKEY": this.apiKey }
|
|
669
670
|
});
|
|
670
671
|
return this.parseResponse(schema, response, endpoint);
|
|
671
672
|
}
|
|
672
673
|
async privateRequest({ endpoint, params, schema, method }) {
|
|
673
|
-
if (!this.
|
|
674
|
+
if (!this.apiKey || !this.apiSecret) throw new ApiError({
|
|
674
675
|
endpoint,
|
|
675
676
|
metadata: { cause: "Empty credentials" }
|
|
676
677
|
});
|
|
677
678
|
const searchParams = this.toSearchParams(params);
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
searchParams["signature"] = this.sign(new URLSearchParams(searchParams).toString(), this.credentials.secret);
|
|
681
|
-
}
|
|
679
|
+
searchParams["timestamp"] = (/* @__PURE__ */ new Date()).getTime().toString();
|
|
680
|
+
searchParams["signature"] = this.sign(new URLSearchParams(searchParams).toString(), this.apiSecret);
|
|
682
681
|
const response = await this.httpCleint.request({
|
|
683
682
|
method,
|
|
684
683
|
path: endpoint,
|
|
685
684
|
query: method !== "POST" ? searchParams : void 0,
|
|
686
685
|
body: method === "POST" ? new URLSearchParams(searchParams).toString() : void 0,
|
|
687
|
-
headers: { "X-MBX-APIKEY": this.
|
|
686
|
+
headers: { "X-MBX-APIKEY": this.apiKey }
|
|
688
687
|
});
|
|
689
688
|
return this.parseResponse(schema, response, endpoint);
|
|
690
689
|
}
|
|
@@ -696,10 +695,11 @@ var BaseRestClient = class {
|
|
|
696
695
|
//#endregion
|
|
697
696
|
//#region src/rest/futures/client.ts
|
|
698
697
|
var FuturesRestClient = class extends BaseRestClient {
|
|
699
|
-
constructor({ baseUrl = "https://fapi.binance.com",
|
|
698
|
+
constructor({ baseUrl = "https://fapi.binance.com", apiKey, apiSecret, httpOptions }) {
|
|
700
699
|
super({
|
|
701
700
|
baseUrl,
|
|
702
|
-
|
|
701
|
+
apiKey,
|
|
702
|
+
apiSecret,
|
|
703
703
|
httpOptions
|
|
704
704
|
});
|
|
705
705
|
}
|
|
@@ -998,10 +998,11 @@ const SpotCheckServerTimeSchema = z.object({ serverTime: z.number() });
|
|
|
998
998
|
//#endregion
|
|
999
999
|
//#region src/rest/spot/client.ts
|
|
1000
1000
|
var SpotRestClient = class extends BaseRestClient {
|
|
1001
|
-
constructor({ baseUrl = "https://api.binance.com",
|
|
1001
|
+
constructor({ baseUrl = "https://api.binance.com", apiKey, apiSecret, httpOptions }) {
|
|
1002
1002
|
super({
|
|
1003
1003
|
baseUrl,
|
|
1004
|
-
|
|
1004
|
+
apiKey,
|
|
1005
|
+
apiSecret,
|
|
1005
1006
|
httpOptions
|
|
1006
1007
|
});
|
|
1007
1008
|
}
|
|
@@ -1026,13 +1027,11 @@ var BinanceRestClient = class {
|
|
|
1026
1027
|
spot;
|
|
1027
1028
|
constructor(options) {
|
|
1028
1029
|
this.futures = new FuturesRestClient({
|
|
1029
|
-
|
|
1030
|
+
apiKey: options?.apiKey,
|
|
1031
|
+
apiSecret: options?.apiSecret,
|
|
1030
1032
|
baseUrl: options?.baseUrls?.futures
|
|
1031
1033
|
});
|
|
1032
|
-
this.spot = new SpotRestClient({
|
|
1033
|
-
credentials: options?.credentials,
|
|
1034
|
-
baseUrl: options?.baseUrls?.spot
|
|
1035
|
-
});
|
|
1034
|
+
this.spot = new SpotRestClient({ baseUrl: options?.baseUrls?.spot });
|
|
1036
1035
|
}
|
|
1037
1036
|
};
|
|
1038
1037
|
|
|
@@ -1203,9 +1202,8 @@ const createWebsocketClient = (baseUrl, symbolConverter$1) => {
|
|
|
1203
1202
|
unsubscribe: (symbols, ...args) => {
|
|
1204
1203
|
return section.unsubscribe(symbols.map((s) => converter(s, ...args)));
|
|
1205
1204
|
},
|
|
1206
|
-
addEventListener:
|
|
1207
|
-
|
|
1208
|
-
}
|
|
1205
|
+
addEventListener: section.addEventListener,
|
|
1206
|
+
removeEventListener: section.removeEventListener
|
|
1209
1207
|
});
|
|
1210
1208
|
} });
|
|
1211
1209
|
};
|