@medievalrain/binance-ts 0.4.0 → 0.5.1

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 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
- credentials,
795
+ apiKey,
796
+ apiSecret,
801
797
  httpOptions
802
798
  }: {
803
799
  baseUrl: string;
804
- credentials?: ApiCredentials;
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
- credentials,
896
+ apiKey,
897
+ apiSecret,
900
898
  httpOptions
901
899
  }: {
902
- credentials?: ApiCredentials;
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
- credentials,
1390
+ apiKey,
1391
+ apiSecret,
1392
1392
  httpOptions
1393
1393
  }: {
1394
- credentials?: ApiCredentials;
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
- credentials?: ApiCredentials;
1410
+ apiKey?: string;
1411
+ apiSecret?: string;
1410
1412
  baseUrls?: {
1411
1413
  spot?: string;
1412
1414
  futures?: string;
package/dist/index.js CHANGED
@@ -598,10 +598,12 @@ const ErrorResponseSchema = z.object({
598
598
  //#endregion
599
599
  //#region src/shared/base-rest-client.ts
600
600
  var BaseRestClient = class {
601
- credentials;
602
601
  httpCleint;
603
- constructor({ baseUrl, credentials, httpOptions }) {
604
- this.credentials = credentials;
602
+ apiKey;
603
+ apiSecret;
604
+ constructor({ baseUrl, apiKey, apiSecret, httpOptions }) {
605
+ this.apiKey = apiKey;
606
+ this.apiSecret = apiSecret;
605
607
  this.httpCleint = new Client(baseUrl, {
606
608
  allowH2: true,
607
609
  connect: {
@@ -665,26 +667,24 @@ var BaseRestClient = class {
665
667
  method: "GET",
666
668
  path: endpoint,
667
669
  query: searchParams,
668
- headers: { "X-MBX-APIKEY": this.credentials?.secret }
670
+ headers: { "X-MBX-APIKEY": this.apiKey }
669
671
  });
670
672
  return this.parseResponse(schema, response, endpoint);
671
673
  }
672
674
  async privateRequest({ endpoint, params, schema, method }) {
673
- if (!this.credentials) throw new ApiError({
675
+ if (!this.apiKey || !this.apiSecret) throw new ApiError({
674
676
  endpoint,
675
677
  metadata: { cause: "Empty credentials" }
676
678
  });
677
679
  const searchParams = this.toSearchParams(params);
678
- if (this.credentials) {
679
- searchParams["timestamp"] = (/* @__PURE__ */ new Date()).getTime().toString();
680
- searchParams["signature"] = this.sign(new URLSearchParams(searchParams).toString(), this.credentials.secret);
681
- }
680
+ searchParams["timestamp"] = (/* @__PURE__ */ new Date()).getTime().toString();
681
+ searchParams["signature"] = this.sign(new URLSearchParams(searchParams).toString(), this.apiSecret);
682
682
  const response = await this.httpCleint.request({
683
683
  method,
684
684
  path: endpoint,
685
685
  query: method !== "POST" ? searchParams : void 0,
686
686
  body: method === "POST" ? new URLSearchParams(searchParams).toString() : void 0,
687
- headers: { "X-MBX-APIKEY": this.credentials?.key }
687
+ headers: { "X-MBX-APIKEY": this.apiKey }
688
688
  });
689
689
  return this.parseResponse(schema, response, endpoint);
690
690
  }
@@ -696,10 +696,11 @@ var BaseRestClient = class {
696
696
  //#endregion
697
697
  //#region src/rest/futures/client.ts
698
698
  var FuturesRestClient = class extends BaseRestClient {
699
- constructor({ baseUrl = "https://fapi.binance.com", credentials, httpOptions }) {
699
+ constructor({ baseUrl = "https://fapi.binance.com", apiKey, apiSecret, httpOptions }) {
700
700
  super({
701
701
  baseUrl,
702
- credentials,
702
+ apiKey,
703
+ apiSecret,
703
704
  httpOptions
704
705
  });
705
706
  }
@@ -998,10 +999,11 @@ const SpotCheckServerTimeSchema = z.object({ serverTime: z.number() });
998
999
  //#endregion
999
1000
  //#region src/rest/spot/client.ts
1000
1001
  var SpotRestClient = class extends BaseRestClient {
1001
- constructor({ baseUrl = "https://api.binance.com", credentials, httpOptions }) {
1002
+ constructor({ baseUrl = "https://api.binance.com", apiKey, apiSecret, httpOptions }) {
1002
1003
  super({
1003
1004
  baseUrl,
1004
- credentials,
1005
+ apiKey,
1006
+ apiSecret,
1005
1007
  httpOptions
1006
1008
  });
1007
1009
  }
@@ -1026,13 +1028,11 @@ var BinanceRestClient = class {
1026
1028
  spot;
1027
1029
  constructor(options) {
1028
1030
  this.futures = new FuturesRestClient({
1029
- credentials: options?.credentials,
1031
+ apiKey: options?.apiKey,
1032
+ apiSecret: options?.apiSecret,
1030
1033
  baseUrl: options?.baseUrls?.futures
1031
1034
  });
1032
- this.spot = new SpotRestClient({
1033
- credentials: options?.credentials,
1034
- baseUrl: options?.baseUrls?.spot
1035
- });
1035
+ this.spot = new SpotRestClient({ baseUrl: options?.baseUrls?.spot });
1036
1036
  }
1037
1037
  };
1038
1038
 
@@ -1203,9 +1203,8 @@ const createWebsocketClient = (baseUrl, symbolConverter$1) => {
1203
1203
  unsubscribe: (symbols, ...args) => {
1204
1204
  return section.unsubscribe(symbols.map((s) => converter(s, ...args)));
1205
1205
  },
1206
- addEventListener: (callback, options) => {
1207
- section.addEventListener("marketMessage", callback, options);
1208
- }
1206
+ addEventListener: section.addEventListener,
1207
+ removeEventListener: section.removeEventListener
1209
1208
  });
1210
1209
  } });
1211
1210
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medievalrain/binance-ts",
3
- "version": "0.4.0",
3
+ "version": "0.5.1",
4
4
  "description": "Binance API SDK",
5
5
  "access": "public",
6
6
  "type": "module",