@yuants/vendor-binance 0.12.3 → 0.12.4

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.
@@ -1,8 +1,28 @@
1
1
  import { GlobalPrometheusRegistry, Terminal } from '@yuants/protocol';
2
- import { encodeHex, formatTime, HmacSHA256, newError } from '@yuants/utils';
2
+ import { encodeHex, formatTime, HmacSHA256, newError, tokenBucket } from '@yuants/utils';
3
3
  const MetricBinanceApiUsedWeight = GlobalPrometheusRegistry.gauge('binance_api_used_weight', '');
4
4
  const MetricBinanceApiCounter = GlobalPrometheusRegistry.counter('binance_api_request_total', '');
5
5
  const terminal = Terminal.fromNodeEnv();
6
+ export const spotAPIBucket = tokenBucket('api.binance.com', {
7
+ capacity: 6000,
8
+ refillInterval: 60000,
9
+ refillAmount: 6000,
10
+ });
11
+ export const futureAPIBucket = tokenBucket('fapi.binance.com', {
12
+ capacity: 2400,
13
+ refillInterval: 60000,
14
+ refillAmount: 2400,
15
+ });
16
+ export const unifiedAPIBucket = tokenBucket('papi.binance.com', {
17
+ capacity: 6000,
18
+ refillInterval: 60000,
19
+ refillAmount: 6000,
20
+ });
21
+ export const unifiedOrderAPIBucket = tokenBucket('order/unified/minute', {
22
+ capacity: 1200,
23
+ refillInterval: 60000,
24
+ refillAmount: 1200,
25
+ });
6
26
  // 每个接口单独进行主动限流控制
7
27
  const mapPathToRetryAfterUntil = {};
8
28
  export const isApiError = (value) => typeof (value === null || value === void 0 ? void 0 : value.code) === 'number' && typeof (value === null || value === void 0 ? void 0 : value.msg) === 'string';
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE5E,MAAM,0BAA0B,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;KACtF;IACD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC;AACpC,CAAC,CAAC","sourcesContent":["import { GlobalPrometheusRegistry, Terminal } from '@yuants/protocol';\nimport { encodeHex, formatTime, HmacSHA256, newError } from '@yuants/utils';\n\nconst MetricBinanceApiUsedWeight = GlobalPrometheusRegistry.gauge('binance_api_used_weight', '');\nconst MetricBinanceApiCounter = GlobalPrometheusRegistry.counter('binance_api_request_total', '');\nconst terminal = Terminal.fromNodeEnv();\n\ntype HttpMethod = 'GET' | 'POST' | 'DELETE' | 'PUT';\n\ntype RequestParams = Record<string, string | number | boolean | undefined>;\n\nexport interface ICredential {\n access_key: string;\n secret_key: string;\n}\n\nexport interface IApiError {\n code: number;\n msg: string;\n}\n\n// 每个接口单独进行主动限流控制\nconst mapPathToRetryAfterUntil: Record<string, number> = {};\n\nexport const isApiError = <T>(value: T | IApiError): value is IApiError =>\n typeof (value as IApiError)?.code === 'number' && typeof (value as IApiError)?.msg === 'string';\n\nconst appendParams = (url: URL, params?: RequestParams) => {\n if (!params) return;\n const entries = Object.entries(params).filter(([, value]) => value !== undefined);\n const timestampEntry = entries.find(([key]) => key === 'timestamp');\n const restEntries = entries.filter(([key]) => key !== 'timestamp');\n restEntries\n .sort(([keyA], [keyB]) => keyA.localeCompare(keyB))\n .forEach(([key, value]) => {\n url.searchParams.set(key, String(value));\n });\n if (timestampEntry) {\n url.searchParams.set(timestampEntry[0], String(timestampEntry[1]));\n }\n};\n\nconst callApi = async <T>(\n method: HttpMethod,\n endpoint: string,\n params?: RequestParams,\n credential?: ICredential,\n): Promise<T> => {\n const url = new URL(endpoint);\n const normalizedParams: RequestParams = { ...params };\n if (credential) {\n if (normalizedParams.recvWindow === undefined) {\n // FYI https://developers.binance.com/docs/derivatives/usds-margined-futures/general-info#timing-security\n normalizedParams.recvWindow = 5000;\n }\n if (normalizedParams.timestamp === undefined) {\n normalizedParams.timestamp = Date.now();\n }\n }\n appendParams(url, normalizedParams);\n\n let headers: Record<string, string> | undefined;\n if (credential) {\n const signData = url.search.slice(1);\n\n const signature = encodeHex(\n await HmacSHA256(new TextEncoder().encode(signData), new TextEncoder().encode(credential.secret_key)),\n );\n url.searchParams.set('signature', signature);\n headers = {\n 'Content-Type': 'application/json;charset=utf-8',\n 'X-MBX-APIKEY': credential.access_key,\n };\n console.info(\n formatTime(Date.now()),\n method,\n url.href,\n JSON.stringify(headers),\n url.searchParams.toString(),\n signData,\n );\n } else {\n console.info(formatTime(Date.now()), method, url.href);\n }\n\n const retryAfterUntil = mapPathToRetryAfterUntil[endpoint];\n\n if (retryAfterUntil) {\n if (Date.now() <= retryAfterUntil) {\n // 主动限流\n throw newError('ACTIVE_RATE_LIMIT', {\n wait_time: `${retryAfterUntil - Date.now()}ms`,\n retryAfterUntil,\n url: url.href,\n endpoint,\n });\n }\n delete mapPathToRetryAfterUntil[endpoint];\n }\n\n MetricBinanceApiCounter.labels({ path: url.pathname, terminal_id: terminal.terminal_id }).inc();\n\n const res = await fetch(url.href, {\n method,\n headers,\n });\n const usedWeight1M = res.headers.get('x-mbx-used-weight-1m');\n const retryAfter = res.headers.get('Retry-After');\n if (retryAfter) {\n mapPathToRetryAfterUntil[endpoint] = Date.now() + parseInt(retryAfter, 10) * 1000;\n }\n console.info(\n formatTime(Date.now()),\n 'response',\n method,\n url.href,\n `status=${res.status}`,\n retryAfter ? `retryAfter=${retryAfter}` : '',\n `usedWeight1M=${usedWeight1M ?? 'N/A'}`,\n );\n if (usedWeight1M) {\n MetricBinanceApiUsedWeight.labels({ path: endpoint, terminal_id: terminal.terminal_id }).set(\n +usedWeight1M,\n );\n }\n return res.json() as Promise<T>;\n};\n\nexport const requestPublic = <T>(method: HttpMethod, endpoint: string, params?: RequestParams) =>\n callApi<T>(method, endpoint, params);\n\nexport const requestPrivate = <T>(\n credential: ICredential,\n method: HttpMethod,\n endpoint: string,\n params?: RequestParams,\n) => callApi<T>(method, endpoint, params, credential);\n\nexport const getDefaultCredential = (): ICredential => {\n const access_key = process.env.ACCESS_KEY;\n const secret_key = process.env.SECRET_KEY;\n if (!access_key || !secret_key) {\n throw new Error('Missing Binance credential: ACCESS_KEY and SECRET_KEY must be set');\n }\n return { access_key, secret_key };\n};\n"]}
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEzF,MAAM,0BAA0B,GAAG,wBAAwB,CAAC,KAAK,CAAC,yBAAyB,EAAE,EAAE,CAAC,CAAC;AACjG,MAAM,uBAAuB,GAAG,wBAAwB,CAAC,OAAO,CAAC,2BAA2B,EAAE,EAAE,CAAC,CAAC;AAClG,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;AAgBxC,MAAM,CAAC,MAAM,aAAa,GAAG,WAAW,CAAC,iBAAiB,EAAE;IAC1D,QAAQ,EAAE,IAAI;IACd,cAAc,EAAE,KAAM;IACtB,YAAY,EAAE,IAAI;CACnB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,eAAe,GAAG,WAAW,CAAC,kBAAkB,EAAE;IAC7D,QAAQ,EAAE,IAAI;IACd,cAAc,EAAE,KAAM;IACtB,YAAY,EAAE,IAAI;CACnB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,WAAW,CAAC,kBAAkB,EAAE;IAC9D,QAAQ,EAAE,IAAI;IACd,cAAc,EAAE,KAAM;IACtB,YAAY,EAAE,IAAI;CACnB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,qBAAqB,GAAG,WAAW,CAAC,sBAAsB,EAAE;IACvE,QAAQ,EAAE,IAAI;IACd,cAAc,EAAE,KAAM;IACtB,YAAY,EAAE,IAAI;CACnB,CAAC,CAAC;AAEH,iB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,GAAG,CAAC,MAAM,EAAE,EACtB,UAAU,CAAC,CAAC,CAAC,cAAc,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,EAC5C,gBAAgB,YAAY,aAAZ,YAAY,cAAZ,YAAY,GAAI,KAAK,EAAE,CACxC,CAAC;IACF,IAAI,YAAY,EAAE;QAChB,0BAA0B,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC,GAAG,CAC1F,CAAC,YAAY,CACd,CAAC;KACH;IACD,OAAO,GAAG,CAAC,IAAI,EAAgB,CAAC;AAClC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,CAAI,MAAkB,EAAE,QAAgB,EAAE,MAAsB,EAAE,EAAE,CAC/F,OAAO,CAAI,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;AAEvC,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,UAAuB,EACvB,MAAkB,EAClB,QAAgB,EAChB,MAAsB,EACtB,EAAE,CAAC,OAAO,CAAI,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;AAEtD,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAgB,EAAE;IACpD,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC;IAC1C,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC;IAC1C,IAAI,CAAC,UAAU,IAAI,CAAC,UAAU,EAAE;QAC9B,MAAM,IAAI,KAAK,CAAC,mEAAmE,CAAC,CAAC;KACtF;IACD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC;AACpC,CAAC,CAAC","sourcesContent":["import { GlobalPrometheusRegistry, Terminal } from '@yuants/protocol';\nimport { encodeHex, formatTime, HmacSHA256, newError, tokenBucket } from '@yuants/utils';\n\nconst MetricBinanceApiUsedWeight = GlobalPrometheusRegistry.gauge('binance_api_used_weight', '');\nconst MetricBinanceApiCounter = GlobalPrometheusRegistry.counter('binance_api_request_total', '');\nconst terminal = Terminal.fromNodeEnv();\n\ntype HttpMethod = 'GET' | 'POST' | 'DELETE' | 'PUT';\n\ntype RequestParams = Record<string, string | number | boolean | undefined>;\n\nexport interface ICredential {\n access_key: string;\n secret_key: string;\n}\n\nexport interface IApiError {\n code: number;\n msg: string;\n}\n\nexport const spotAPIBucket = tokenBucket('api.binance.com', {\n capacity: 6000,\n refillInterval: 60_000,\n refillAmount: 6000,\n});\n\nexport const futureAPIBucket = tokenBucket('fapi.binance.com', {\n capacity: 2400,\n refillInterval: 60_000,\n refillAmount: 2400,\n});\n\nexport const unifiedAPIBucket = tokenBucket('papi.binance.com', {\n capacity: 6000,\n refillInterval: 60_000,\n refillAmount: 6000,\n});\n\nexport const unifiedOrderAPIBucket = tokenBucket('order/unified/minute', {\n capacity: 1200,\n refillInterval: 60_000,\n refillAmount: 1200,\n});\n\n// 每个接口单独进行主动限流控制\nconst mapPathToRetryAfterUntil: Record<string, number> = {};\n\nexport const isApiError = <T>(value: T | IApiError): value is IApiError =>\n typeof (value as IApiError)?.code === 'number' && typeof (value as IApiError)?.msg === 'string';\n\nconst appendParams = (url: URL, params?: RequestParams) => {\n if (!params) return;\n const entries = Object.entries(params).filter(([, value]) => value !== undefined);\n const timestampEntry = entries.find(([key]) => key === 'timestamp');\n const restEntries = entries.filter(([key]) => key !== 'timestamp');\n restEntries\n .sort(([keyA], [keyB]) => keyA.localeCompare(keyB))\n .forEach(([key, value]) => {\n url.searchParams.set(key, String(value));\n });\n if (timestampEntry) {\n url.searchParams.set(timestampEntry[0], String(timestampEntry[1]));\n }\n};\n\nconst callApi = async <T>(\n method: HttpMethod,\n endpoint: string,\n params?: RequestParams,\n credential?: ICredential,\n): Promise<T> => {\n const url = new URL(endpoint);\n const normalizedParams: RequestParams = { ...params };\n if (credential) {\n if (normalizedParams.recvWindow === undefined) {\n // FYI https://developers.binance.com/docs/derivatives/usds-margined-futures/general-info#timing-security\n normalizedParams.recvWindow = 5000;\n }\n if (normalizedParams.timestamp === undefined) {\n normalizedParams.timestamp = Date.now();\n }\n }\n appendParams(url, normalizedParams);\n\n let headers: Record<string, string> | undefined;\n if (credential) {\n const signData = url.search.slice(1);\n\n const signature = encodeHex(\n await HmacSHA256(new TextEncoder().encode(signData), new TextEncoder().encode(credential.secret_key)),\n );\n url.searchParams.set('signature', signature);\n headers = {\n 'Content-Type': 'application/json;charset=utf-8',\n 'X-MBX-APIKEY': credential.access_key,\n };\n console.info(\n formatTime(Date.now()),\n method,\n url.href,\n JSON.stringify(headers),\n url.searchParams.toString(),\n signData,\n );\n } else {\n console.info(formatTime(Date.now()), method, url.href);\n }\n\n const retryAfterUntil = mapPathToRetryAfterUntil[endpoint];\n\n if (retryAfterUntil) {\n if (Date.now() <= retryAfterUntil) {\n // 主动限流\n throw newError('ACTIVE_RATE_LIMIT', {\n wait_time: `${retryAfterUntil - Date.now()}ms`,\n retryAfterUntil,\n url: url.href,\n endpoint,\n });\n }\n delete mapPathToRetryAfterUntil[endpoint];\n }\n\n MetricBinanceApiCounter.labels({ path: url.pathname, terminal_id: terminal.terminal_id }).inc();\n\n const res = await fetch(url.href, {\n method,\n headers,\n });\n const usedWeight1M = res.headers.get('x-mbx-used-weight-1m');\n const retryAfter = res.headers.get('Retry-After');\n if (retryAfter) {\n mapPathToRetryAfterUntil[endpoint] = Date.now() + parseInt(retryAfter, 10) * 1000;\n }\n console.info(\n formatTime(Date.now()),\n 'response',\n method,\n url.href,\n `status=${res.status}`,\n retryAfter ? `retryAfter=${retryAfter}` : '',\n `usedWeight1M=${usedWeight1M ?? 'N/A'}`,\n );\n if (usedWeight1M) {\n MetricBinanceApiUsedWeight.labels({ path: endpoint, terminal_id: terminal.terminal_id }).set(\n +usedWeight1M,\n );\n }\n return res.json() as Promise<T>;\n};\n\nexport const requestPublic = <T>(method: HttpMethod, endpoint: string, params?: RequestParams) =>\n callApi<T>(method, endpoint, params);\n\nexport const requestPrivate = <T>(\n credential: ICredential,\n method: HttpMethod,\n endpoint: string,\n params?: RequestParams,\n) => callApi<T>(method, endpoint, params, credential);\n\nexport const getDefaultCredential = (): ICredential => {\n const access_key = process.env.ACCESS_KEY;\n const secret_key = process.env.SECRET_KEY;\n if (!access_key || !secret_key) {\n throw new Error('Missing Binance credential: ACCESS_KEY and SECRET_KEY must be set');\n }\n return { access_key, secret_key };\n};\n"]}
@@ -1,3 +1,4 @@
1
+ import { scopeError, tokenBucket } from '@yuants/utils';
1
2
  import { getDefaultCredential, requestPrivate } from './client';
2
3
  /**
3
4
  * 查询账户信息(USER_DATA)
@@ -8,7 +9,13 @@ import { getDefaultCredential, requestPrivate } from './client';
8
9
  *
9
10
  * https://developers.binance.com/docs/zh-CN/derivatives/portfolio-margin/account/Account-Information
10
11
  */
11
- export const getUnifiedAccountInfo = (credential) => requestPrivate(credential, 'GET', 'https://papi.binance.com/papi/v1/account');
12
+ export const getUnifiedAccountInfo = (credential) => {
13
+ const endpoint = 'https://papi.binance.com/papi/v1/account';
14
+ const url = new URL(endpoint);
15
+ const weight = 20;
16
+ scopeError('BINANCE_API_RATE_LIMIT', { method: 'GET', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight }, () => tokenBucket(url.host).acquireSync(weight));
17
+ return requestPrivate(credential, 'GET', endpoint);
18
+ };
12
19
  /**
13
20
  * 获取UM账户信息
14
21
  *
@@ -18,7 +25,13 @@ export const getUnifiedAccountInfo = (credential) => requestPrivate(credential,
18
25
  *
19
26
  * https://developers.binance.com/docs/zh-CN/derivatives/portfolio-margin/account/Get-UM-Account-Detail
20
27
  */
21
- export const getUnifiedUmAccount = (credential) => requestPrivate(credential, 'GET', 'https://papi.binance.com/papi/v1/um/account');
28
+ export const getUnifiedUmAccount = (credential) => {
29
+ const endpoint = 'https://papi.binance.com/papi/v1/um/account';
30
+ const url = new URL(endpoint);
31
+ const weight = 5;
32
+ scopeError('BINANCE_API_RATE_LIMIT', { method: 'GET', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight }, () => tokenBucket(url.host).acquireSync(weight));
33
+ return requestPrivate(credential, 'GET', endpoint);
34
+ };
22
35
  /**
23
36
  * 查看当前全部UM挂单(USER_DATA)
24
37
  *
@@ -28,7 +41,21 @@ export const getUnifiedUmAccount = (credential) => requestPrivate(credential, 'G
28
41
  *
29
42
  * https://developers.binance.com/docs/zh-CN/derivatives/portfolio-margin/trade/Query-All-Current-UM-Open-Orders
30
43
  */
31
- export const getUnifiedUmOpenOrders = (credential, params) => requestPrivate(credential, 'GET', 'https://papi.binance.com/papi/v1/um/openOrders', params);
44
+ export const getUnifiedUmOpenOrders = (credential, params) => {
45
+ const endpoint = 'https://papi.binance.com/papi/v1/um/openOrders';
46
+ const url = new URL(endpoint);
47
+ const weight = (params === null || params === void 0 ? void 0 : params.symbol) ? 1 : 40;
48
+ scopeError('BINANCE_API_RATE_LIMIT', {
49
+ method: 'GET',
50
+ endpoint,
51
+ host: url.host,
52
+ path: url.pathname,
53
+ bucketId: url.host,
54
+ weight,
55
+ hasSymbol: !!(params === null || params === void 0 ? void 0 : params.symbol),
56
+ }, () => tokenBucket(url.host).acquireSync(weight));
57
+ return requestPrivate(credential, 'GET', endpoint, params);
58
+ };
32
59
  /**
33
60
  * 查询账户余额(USER_DATA)
34
61
  *
@@ -38,7 +65,13 @@ export const getUnifiedUmOpenOrders = (credential, params) => requestPrivate(cre
38
65
  *
39
66
  * https://developers.binance.com/docs/zh-CN/derivatives/portfolio-margin/account/Account-Balance
40
67
  */
41
- export const getUnifiedAccountBalance = (credential, params) => requestPrivate(credential, 'GET', 'https://papi.binance.com/papi/v1/balance', params);
68
+ export const getUnifiedAccountBalance = (credential, params) => {
69
+ const endpoint = 'https://papi.binance.com/papi/v1/balance';
70
+ const url = new URL(endpoint);
71
+ const weight = 20;
72
+ scopeError('BINANCE_API_RATE_LIMIT', { method: 'GET', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight }, () => tokenBucket(url.host).acquireSync(weight));
73
+ return requestPrivate(credential, 'GET', endpoint, params);
74
+ };
42
75
  /**
43
76
  * 账户信息 (USER_DATA)
44
77
  *
@@ -46,7 +79,13 @@ export const getUnifiedAccountBalance = (credential, params) => requestPrivate(c
46
79
  *
47
80
  * https://developers.binance.com/docs/zh-CN/binance-spot-api-docs/rest-api#%E8%B4%A6%E6%88%B7%E4%BF%A1%E6%81%AF-user_data
48
81
  */
49
- export const getSpotAccountInfo = (credential, params) => requestPrivate(credential, 'GET', 'https://api.binance.com/api/v3/account', params);
82
+ export const getSpotAccountInfo = (credential, params) => {
83
+ const endpoint = 'https://api.binance.com/api/v3/account';
84
+ const url = new URL(endpoint);
85
+ const weight = 20;
86
+ scopeError('BINANCE_API_RATE_LIMIT', { method: 'GET', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight }, () => tokenBucket(url.host).acquireSync(weight));
87
+ return requestPrivate(credential, 'GET', endpoint, params);
88
+ };
50
89
  /**
51
90
  * Current open orders (USER_DATA)
52
91
  *
@@ -54,7 +93,21 @@ export const getSpotAccountInfo = (credential, params) => requestPrivate(credent
54
93
  *
55
94
  * https://developers.binance.com/docs/zh-CN/binance-spot-api-docs/rest-api/account-endpoints#%E6%9F%A5%E7%9C%8B%E8%B4%A6%E6%88%B7%E5%BD%93%E5%89%8D%E6%8C%82%E5%8D%95-user_data
56
95
  */
57
- export const getSpotOpenOrders = (credential, params) => requestPrivate(credential, 'GET', 'https://api.binance.com/api/v3/openOrders', params);
96
+ export const getSpotOpenOrders = (credential, params) => {
97
+ const endpoint = 'https://api.binance.com/api/v3/openOrders';
98
+ const url = new URL(endpoint);
99
+ const weight = (params === null || params === void 0 ? void 0 : params.symbol) ? 6 : 80;
100
+ scopeError('BINANCE_API_RATE_LIMIT', {
101
+ method: 'GET',
102
+ endpoint,
103
+ host: url.host,
104
+ path: url.pathname,
105
+ bucketId: url.host,
106
+ weight,
107
+ hasSymbol: !!(params === null || params === void 0 ? void 0 : params.symbol),
108
+ }, () => tokenBucket(url.host).acquireSync(weight));
109
+ return requestPrivate(credential, 'GET', endpoint, params);
110
+ };
58
111
  /**
59
112
  * New order (TRADE)
60
113
  *
@@ -62,7 +115,13 @@ export const getSpotOpenOrders = (credential, params) => requestPrivate(credenti
62
115
  *
63
116
  * https://developers.binance.com/docs/zh-CN/binance-spot-api-docs/rest-api/trading-endpoints#%E4%B8%8B%E5%8D%95-trade
64
117
  */
65
- export const postSpotOrder = (credential, params) => requestPrivate(credential, 'POST', 'https://api.binance.com/api/v3/order', params);
118
+ export const postSpotOrder = (credential, params) => {
119
+ const endpoint = 'https://api.binance.com/api/v3/order';
120
+ const url = new URL(endpoint);
121
+ const weight = 1;
122
+ scopeError('BINANCE_API_RATE_LIMIT', { method: 'POST', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight }, () => tokenBucket(url.host).acquireSync(weight));
123
+ return requestPrivate(credential, 'POST', endpoint, params);
124
+ };
66
125
  /**
67
126
  * Cancel order (TRADE)
68
127
  *
@@ -70,7 +129,13 @@ export const postSpotOrder = (credential, params) => requestPrivate(credential,
70
129
  *
71
130
  * https://developers.binance.com/docs/zh-CN/binance-spot-api-docs/rest-api/trading-endpoints#%E6%92%A4%E9%94%80%E8%AE%A2%E5%8D%95-trade
72
131
  */
73
- export const deleteSpotOrder = (credential, params) => requestPrivate(credential, 'DELETE', 'https://api.binance.com/api/v3/order', params);
132
+ export const deleteSpotOrder = (credential, params) => {
133
+ const endpoint = 'https://api.binance.com/api/v3/order';
134
+ const url = new URL(endpoint);
135
+ const weight = 1;
136
+ scopeError('BINANCE_API_RATE_LIMIT', { method: 'DELETE', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight }, () => tokenBucket(url.host).acquireSync(weight));
137
+ return requestPrivate(credential, 'DELETE', endpoint, params);
138
+ };
74
139
  /**
75
140
  * 用户万向划转(USER_DATA)
76
141
  *
@@ -82,7 +147,13 @@ export const deleteSpotOrder = (credential, params) => requestPrivate(credential
82
147
  *
83
148
  * https://developers.binance.com/docs/zh-CN/wallet/asset/user-universal-transfer
84
149
  */
85
- export const postAssetTransfer = (credential, params) => requestPrivate(credential, 'POST', 'https://api.binance.com/sapi/v1/asset/transfer', params);
150
+ export const postAssetTransfer = (credential, params) => {
151
+ const endpoint = 'https://api.binance.com/sapi/v1/asset/transfer';
152
+ const url = new URL(endpoint);
153
+ const weight = 900;
154
+ scopeError('BINANCE_API_RATE_LIMIT', { method: 'POST', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight }, () => tokenBucket(url.host).acquireSync(weight));
155
+ return requestPrivate(credential, 'POST', endpoint, params);
156
+ };
86
157
  /**
87
158
  * 统一账户资金归集(TRADE)
88
159
  *
@@ -94,7 +165,13 @@ export const postAssetTransfer = (credential, params) => requestPrivate(credenti
94
165
  *
95
166
  * ISSUE(2024-07-18): 目前这是唯一能够将资金从原 U 本位合约账户转入统一账户的接口。
96
167
  */
97
- export const postUnifiedAccountAutoCollection = (credential) => requestPrivate(credential, 'POST', 'https://papi.binance.com/papi/v1/auto-collection');
168
+ export const postUnifiedAccountAutoCollection = (credential) => {
169
+ const endpoint = 'https://papi.binance.com/papi/v1/auto-collection';
170
+ const url = new URL(endpoint);
171
+ const weight = 750;
172
+ scopeError('BINANCE_API_RATE_LIMIT', { method: 'POST', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight }, () => tokenBucket(url.host).acquireSync(weight));
173
+ return requestPrivate(credential, 'POST', endpoint);
174
+ };
98
175
  /**
99
176
  * 获取充值地址(支持多网络)(USER_DATA)
100
177
  *
@@ -104,7 +181,13 @@ export const postUnifiedAccountAutoCollection = (credential) => requestPrivate(c
104
181
  *
105
182
  * https://developers.binance.com/docs/zh-CN/wallet/capital/deposite-address
106
183
  */
107
- export const getDepositAddress = (credential, params) => requestPrivate(credential, 'GET', 'https://api.binance.com/sapi/v1/capital/deposit/address', params);
184
+ export const getDepositAddress = (credential, params) => {
185
+ const endpoint = 'https://api.binance.com/sapi/v1/capital/deposit/address';
186
+ const url = new URL(endpoint);
187
+ const weight = 10;
188
+ scopeError('BINANCE_API_RATE_LIMIT', { method: 'GET', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight }, () => tokenBucket(url.host).acquireSync(weight));
189
+ return requestPrivate(credential, 'GET', endpoint, params);
190
+ };
108
191
  /**
109
192
  * 查询子账户列表(适用主账户)
110
193
  *
@@ -112,7 +195,13 @@ export const getDepositAddress = (credential, params) => requestPrivate(credenti
112
195
  *
113
196
  * https://developers.binance.com/docs/zh-CN/sub_account/account-management/Query-Sub-account-List
114
197
  */
115
- export const getSubAccountList = (credential, params) => requestPrivate(credential, 'GET', 'https://api.binance.com/sapi/v1/sub-account/list', params);
198
+ export const getSubAccountList = (credential, params) => {
199
+ const endpoint = 'https://api.binance.com/sapi/v1/sub-account/list';
200
+ const url = new URL(endpoint);
201
+ const weight = 1;
202
+ scopeError('BINANCE_API_RATE_LIMIT', { method: 'GET', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight }, () => tokenBucket(url.host).acquireSync(weight));
203
+ return requestPrivate(credential, 'GET', endpoint, params);
204
+ };
116
205
  /**
117
206
  * 提币(USER_DATA)
118
207
  *
@@ -120,7 +209,13 @@ export const getSubAccountList = (credential, params) => requestPrivate(credenti
120
209
  *
121
210
  * https://developers.binance.com/docs/zh-CN/wallet/capital/withdraw
122
211
  */
123
- export const postWithdraw = (credential, params) => requestPrivate(credential, 'POST', 'https://api.binance.com/sapi/v1/capital/withdraw/apply', params);
212
+ export const postWithdraw = (credential, params) => {
213
+ const endpoint = 'https://api.binance.com/sapi/v1/capital/withdraw/apply';
214
+ const url = new URL(endpoint);
215
+ const weight = 600;
216
+ scopeError('BINANCE_API_RATE_LIMIT', { method: 'POST', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight }, () => tokenBucket(url.host).acquireSync(weight));
217
+ return requestPrivate(credential, 'POST', endpoint, params);
218
+ };
124
219
  /**
125
220
  * 获取提币历史(支持多网络)(USER_DATA)
126
221
  *
@@ -133,7 +228,13 @@ export const postWithdraw = (credential, params) => requestPrivate(credential, '
133
228
  *
134
229
  * https://developers.binance.com/docs/zh-CN/wallet/capital/withdraw-history
135
230
  */
136
- export const getWithdrawHistory = (credential, params) => requestPrivate(credential, 'GET', 'https://api.binance.com/sapi/v1/capital/withdraw/history', params);
231
+ export const getWithdrawHistory = (credential, params) => {
232
+ const endpoint = 'https://api.binance.com/sapi/v1/capital/withdraw/history';
233
+ const url = new URL(endpoint);
234
+ const weight = 1;
235
+ scopeError('BINANCE_API_RATE_LIMIT', { method: 'GET', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight }, () => tokenBucket(url.host).acquireSync(weight));
236
+ return requestPrivate(credential, 'GET', endpoint, params);
237
+ };
137
238
  /**
138
239
  * 获取充值历史(支持多网络)
139
240
  *
@@ -141,7 +242,13 @@ export const getWithdrawHistory = (credential, params) => requestPrivate(credent
141
242
  *
142
243
  * https://developers.binance.com/docs/zh-CN/wallet/capital/deposite-history
143
244
  */
144
- export const getDepositHistory = (credential, params) => requestPrivate(credential, 'GET', 'https://api.binance.com/sapi/v1/capital/deposit/hisrec', params);
245
+ export const getDepositHistory = (credential, params) => {
246
+ const endpoint = 'https://api.binance.com/sapi/v1/capital/deposit/hisrec';
247
+ const url = new URL(endpoint);
248
+ const weight = 1;
249
+ scopeError('BINANCE_API_RATE_LIMIT', { method: 'GET', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight }, () => tokenBucket(url.host).acquireSync(weight));
250
+ return requestPrivate(credential, 'GET', endpoint, params);
251
+ };
145
252
  /**
146
253
  * UM下单(TRADE)
147
254
  *
@@ -149,8 +256,20 @@ export const getDepositHistory = (credential, params) => requestPrivate(credenti
149
256
  *
150
257
  * https://developers.binance.com/docs/zh-CN/derivatives/portfolio-margin/trade/New-UM-Order
151
258
  */
152
- export const postUmOrder = (credential, params) => requestPrivate(credential, 'POST', 'https://papi.binance.com/papi/v1/um/order', params);
153
- export const deleteUmOrder = (credential, params) => requestPrivate(credential, 'DELETE', 'https://papi.binance.com/papi/v1/um/order', params);
259
+ export const postUmOrder = (credential, params) => {
260
+ const endpoint = 'https://papi.binance.com/papi/v1/um/order';
261
+ const url = new URL(endpoint);
262
+ const weight = 1;
263
+ scopeError('BINANCE_UNIFIED_ORDER_API_RATE_LIMIT', { method: 'POST', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight }, () => tokenBucket('order/unified/minute').acquireSync(weight));
264
+ return requestPrivate(credential, 'POST', endpoint, params);
265
+ };
266
+ export const deleteUmOrder = (credential, params) => {
267
+ const endpoint = 'https://papi.binance.com/papi/v1/um/order';
268
+ const url = new URL(endpoint);
269
+ const weight = 1;
270
+ scopeError('BINANCE_UNIFIED_ORDER_API_RATE_LIMIT', { method: 'DELETE', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight }, () => tokenBucket('order/unified/minute').acquireSync(weight));
271
+ return requestPrivate(credential, 'DELETE', endpoint, params);
272
+ };
154
273
  /**
155
274
  * 获取UM损益资金流水(USER_DATA)
156
275
  *
@@ -158,7 +277,13 @@ export const deleteUmOrder = (credential, params) => requestPrivate(credential,
158
277
  *
159
278
  * https://developers.binance.com/docs/zh-CN/derivatives/portfolio-margin/account/Get-UM-Income-History
160
279
  */
161
- export const getUMIncome = (credential, params) => requestPrivate(credential, 'GET', 'https://api.binance.com/papi/v1/um/income', params);
280
+ export const getUMIncome = (credential, params) => {
281
+ const endpoint = 'https://papi.binance.com/papi/v1/um/income';
282
+ const url = new URL(endpoint);
283
+ const weight = 30;
284
+ scopeError('BINANCE_API_RATE_LIMIT', { method: 'GET', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight }, () => tokenBucket(url.host).acquireSync(weight));
285
+ return requestPrivate(credential, 'GET', endpoint, params);
286
+ };
162
287
  /**
163
288
  * Cancel an Existing Order and Send a New Order (TRADE)
164
289
  *
@@ -166,7 +291,13 @@ export const getUMIncome = (credential, params) => requestPrivate(credential, 'G
166
291
  *
167
292
  * https://developers.binance.com/docs/zh-CN/binance-spot-api-docs/rest-api/trading-endpoints#%E6%92%A4%E9%94%80%E5%B9%B6%E9%87%8D%E6%96%B0%E4%B8%8B%E5%8D%95-trade
168
293
  */
169
- export const postSpotOrderCancelReplace = (credential, params) => requestPrivate(credential, 'POST', 'https://api.binance.com/api/v3/order/cancelReplace', params);
294
+ export const postSpotOrderCancelReplace = (credential, params) => {
295
+ const endpoint = 'https://api.binance.com/api/v3/order/cancelReplace';
296
+ const url = new URL(endpoint);
297
+ const weight = 1;
298
+ scopeError('BINANCE_API_RATE_LIMIT', { method: 'POST', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight }, () => tokenBucket(url.host).acquireSync(weight));
299
+ return requestPrivate(credential, 'POST', endpoint, params);
300
+ };
170
301
  /**
171
302
  * Modify Order (TRADE)
172
303
  *
@@ -174,7 +305,13 @@ export const postSpotOrderCancelReplace = (credential, params) => requestPrivate
174
305
  *
175
306
  * https://developers.binance.com/docs/zh-CN/derivatives/portfolio-margin/trade/Modify-UM-Order
176
307
  */
177
- export const putUmOrder = (credential, params) => requestPrivate(credential, 'PUT', 'https://papi.binance.com/papi/v1/um/order', params);
308
+ export const putUmOrder = (credential, params) => {
309
+ const endpoint = 'https://papi.binance.com/papi/v1/um/order';
310
+ const url = new URL(endpoint);
311
+ const weight = 1;
312
+ scopeError('BINANCE_API_RATE_LIMIT', { method: 'PUT', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight }, () => tokenBucket(url.host).acquireSync(weight));
313
+ return requestPrivate(credential, 'PUT', endpoint, params);
314
+ };
178
315
  /**
179
316
  * 获取所有全仓杠杆交易对(MARKET_DATA)
180
317
  *
@@ -184,7 +321,11 @@ export const putUmOrder = (credential, params) => requestPrivate(credential, 'PU
184
321
  */
185
322
  export const getMarginAllPairs = (params) => {
186
323
  const credential = getDefaultCredential();
187
- return requestPrivate(credential, 'GET', 'https://api.binance.com/sapi/v1/margin/allPairs', params);
324
+ const endpoint = 'https://api.binance.com/sapi/v1/margin/allPairs';
325
+ const url = new URL(endpoint);
326
+ const weight = 1;
327
+ scopeError('BINANCE_API_RATE_LIMIT', { method: 'GET', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight }, () => tokenBucket(url.host).acquireSync(weight));
328
+ return requestPrivate(credential, 'GET', endpoint, params);
188
329
  };
189
330
  /**
190
331
  * Get a future hourly interest rate
@@ -193,7 +334,11 @@ export const getMarginAllPairs = (params) => {
193
334
  */
194
335
  export const getMarginNextHourlyInterestRate = (params) => {
195
336
  const credential = getDefaultCredential();
196
- return requestPrivate(credential, 'GET', 'https://api.binance.com/sapi/v1/margin/next-hourly-interest-rate', params);
337
+ const endpoint = 'https://api.binance.com/sapi/v1/margin/next-hourly-interest-rate';
338
+ const url = new URL(endpoint);
339
+ const weight = 1;
340
+ scopeError('BINANCE_API_RATE_LIMIT', { method: 'GET', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight }, () => tokenBucket(url.host).acquireSync(weight));
341
+ return requestPrivate(credential, 'GET', endpoint, params);
197
342
  };
198
343
  /**
199
344
  * Query Margin Interest Rate History
@@ -202,7 +347,11 @@ export const getMarginNextHourlyInterestRate = (params) => {
202
347
  */
203
348
  export const getMarginInterestRateHistory = (params) => {
204
349
  const credential = getDefaultCredential();
205
- return requestPrivate(credential, 'GET', 'https://api.binance.com/sapi/v1/margin/interestRateHistory', params);
350
+ const endpoint = 'https://api.binance.com/sapi/v1/margin/interestRateHistory';
351
+ const url = new URL(endpoint);
352
+ const weight = 1;
353
+ scopeError('BINANCE_API_RATE_LIMIT', { method: 'GET', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight }, () => tokenBucket(url.host).acquireSync(weight));
354
+ return requestPrivate(credential, 'GET', endpoint, params);
206
355
  };
207
356
  /**
208
357
  *获取用户持仓
@@ -212,7 +361,11 @@ export const getMarginInterestRateHistory = (params) => {
212
361
  * @returns
213
362
  */
214
363
  export const getUserAsset = (credential, params) => {
215
- return requestPrivate(credential, 'POST', 'https://api.binance.com/sapi/v3/asset/getUserAsset', params);
364
+ const endpoint = 'https://api.binance.com/sapi/v3/asset/getUserAsset';
365
+ const url = new URL(endpoint);
366
+ const weight = 1;
367
+ scopeError('BINANCE_API_RATE_LIMIT', { method: 'POST', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight }, () => tokenBucket(url.host).acquireSync(weight));
368
+ return requestPrivate(credential, 'POST', endpoint, params);
216
369
  };
217
370
  /**
218
371
  * 查询资金账户
@@ -222,6 +375,10 @@ export const getUserAsset = (credential, params) => {
222
375
  * @returns
223
376
  */
224
377
  export const getFundingAsset = (credential, params) => {
225
- return requestPrivate(credential, 'POST', 'https://api.binance.com/sapi/v1/asset/get-funding-asset', params);
378
+ const endpoint = 'https://api.binance.com/sapi/v1/asset/get-funding-asset';
379
+ const url = new URL(endpoint);
380
+ const weight = 1;
381
+ scopeError('BINANCE_API_RATE_LIMIT', { method: 'POST', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight }, () => tokenBucket(url.host).acquireSync(weight));
382
+ return requestPrivate(credential, 'POST', endpoint, params);
226
383
  };
227
384
  //# sourceMappingURL=private-api.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"private-api.js","sourceRoot":"","sources":["../../src/api/private-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAA0B,cAAc,EAAE,MAAM,UAAU,CAAC;AAsOxF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,UAAuB,EAA4C,EAAE,CACzG,cAAc,CACZ,UAAU,EACV,KAAK,EACL,0CAA0C,CAC3C,CAAC;AAEJ;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,UAAuB,EAA0C,EAAE,CACrG,cAAc,CACZ,UAAU,EACV,KAAK,EACL,6CAA6C,CAC9C,CAAC;AAEJ;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,UAAuB,EACvB,MAEC,EAC+B,EAAE,CAClC,cA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,EAAE,MAAM,CAAC,CAAC;AACtF,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,UAAuB,EACvB,MAKC,EACD,EAAE;IACF,OAAO,cAAc,CAWnB,UAAU,EAAE,MAAM,EAAE,yDAAyD,EAAE,MAAM,CAAC,CAAC;AAC3F,CAAC,CAAC","sourcesContent":["import { getDefaultCredential, IApiError, ICredential, requestPrivate } from './client';\nexport type { ICredential };\n\nexport interface IUnifiedAccountInfo {\n uniMMR: string;\n accountEquity: string;\n actualEquity: string;\n accountInitialMargin: string;\n accountMaintMargin: string;\n accountStatus: string;\n virtualMaxWithdrawAmount: string;\n totalAvailableBalance: string;\n totalMarginOpenLoss: string;\n updateTime: number;\n}\n\nexport interface IUnifiedUmAsset {\n asset: string;\n crossWalletBalance: string;\n crossUnPnl: string;\n maintMargin: string;\n initialMargin: string;\n positionInitialMargin: string;\n openOrderInitialMargin: string;\n updateTime: number;\n}\n\nexport interface IUnifiedUmPosition {\n symbol: string;\n initialMargin: string;\n maintMargin: string;\n unrealizedProfit: string;\n positionInitialMargin: string;\n openOrderInitialMargin: string;\n leverage: string;\n entryPrice: string;\n maxNotional: string;\n bidNotional: string;\n askNotional: string;\n positionSide: string;\n positionAmt: string;\n updateTime: number;\n}\n\nexport interface IUnifiedUmAccount {\n assets: IUnifiedUmAsset[];\n positions: IUnifiedUmPosition[];\n}\n\nexport interface IUnifiedUmOpenOrder {\n avgPrice: string;\n clientOrderId: string;\n cumQuote: string;\n executedQty: string;\n orderId: number;\n origQty: string;\n origType: string;\n price: string;\n reduceOnly: boolean;\n side: string;\n positionSide: string;\n status: string;\n symbol: string;\n time: number;\n timeInForce: string;\n type: string;\n updateTime: number;\n selfTradePreventionMode: string;\n goodTillDate: number;\n}\n\nexport interface IUnifiedAccountBalanceEntry {\n asset: string;\n totalWalletBalance: string;\n crossMarginAsset: string;\n crossMarginBorrowed: string;\n crossMarginFree: string;\n crossMarginInterest: string;\n crossMarginLocked: string;\n umWalletBalance: string;\n umUnrealizedPNL: string;\n cmWalletBalance: string;\n cmUnrealizedPNL: string;\n updateTime: number;\n}\n\nexport interface ISpotAccountInfo {\n makerCommission: number;\n takerCommission: number;\n buyerCommission: number;\n sellerCommission: number;\n commissionRates: {\n maker: string;\n taker: string;\n buyer: string;\n seller: string;\n };\n canTrade: boolean;\n canWithdraw: boolean;\n canDeposit: boolean;\n brokered: boolean;\n requireSelfTradePrevention: boolean;\n preventSor: boolean;\n updateTime: number;\n balances: {\n asset: string;\n free: string;\n locked: string;\n }[];\n permissions: string[];\n uid: number;\n}\n\nexport interface ISpotOrder {\n symbol: string;\n orderId: number;\n orderListId: number;\n clientOrderId: string;\n price: string;\n origQty: string;\n executedQty: string;\n origQuoteOrderQty: string;\n cummulativeQuoteQty: string;\n status: string;\n timeInForce: string;\n type: string;\n side: string;\n stopPrice: string;\n icebergQty: string;\n time: number;\n updateTime: number;\n isWorking: boolean;\n}\n\nexport interface ISpotNewOrderResponse {\n symbol: string;\n orderId: number;\n clientOrderId: string;\n transactTime: number;\n}\n\nexport interface IAssetTransferResponse {\n tranId: number;\n}\n\nexport interface IDepositAddress {\n address: string;\n coin: string;\n tag: string;\n url: string;\n}\n\nexport interface ISubAccountSummary {\n email: string;\n isFreeze: boolean;\n createTime: number;\n isManagedSubAccount: boolean;\n isAssetManagementSubAccount: boolean;\n}\n\nexport interface ISubAccountListResponse {\n subAccounts: ISubAccountSummary[];\n}\n\nexport interface IWithdrawRecord {\n id: string;\n amount: string;\n transactionFee: string;\n coin: string;\n status: number;\n address: string;\n txId: string;\n applyTime: Date;\n network: string;\n transferType: number;\n info: string;\n confirmNo: number;\n walletType: number;\n txKey: string;\n completeTime: Date;\n}\n\nexport interface IDepositRecord {\n id: string;\n amount: string;\n coin: string;\n network: string;\n status: number;\n address: string;\n addressTag: string;\n txId: string;\n insertTime: number;\n transferType: number;\n confirmTimes: string;\n unlockConfirm: number;\n walletType: number;\n}\n\nexport interface IUnifiedUmOrderResponse {\n clientOrderId: string;\n cumQty: string;\n cumQuote: string;\n executedQty: string;\n orderId: number;\n avgPrice: string;\n origQty: string;\n price: string;\n reduceOnly: boolean;\n side: string;\n positionSide: string;\n status: string;\n symbol: string;\n timeInForce: string;\n type: string;\n selfTradePreventionMode: string;\n goodTillDate: number;\n updateTime: number;\n}\n\nexport interface IUMIncomeRecord {\n symbol: string;\n incomeType: string;\n income: string;\n asset: string;\n info: string;\n time: number;\n tranId: string;\n tradeId: string;\n}\n\n/**\n * 查询账户信息(USER_DATA)\n *\n * 查询账户信息\n *\n * 权重: 20\n *\n * https://developers.binance.com/docs/zh-CN/derivatives/portfolio-margin/account/Account-Information\n */\nexport const getUnifiedAccountInfo = (credential: ICredential): Promise<IUnifiedAccountInfo | IApiError> =>\n requestPrivate<IUnifiedAccountInfo | IApiError>(\n credential,\n 'GET',\n 'https://papi.binance.com/papi/v1/account',\n );\n\n/**\n * 获取UM账户信息\n *\n * 现有UM账户资产和仓位信息\n *\n * 权重: 5\n *\n * https://developers.binance.com/docs/zh-CN/derivatives/portfolio-margin/account/Get-UM-Account-Detail\n */\nexport const getUnifiedUmAccount = (credential: ICredential): Promise<IUnifiedUmAccount | IApiError> =>\n requestPrivate<IUnifiedUmAccount | IApiError>(\n credential,\n 'GET',\n 'https://papi.binance.com/papi/v1/um/account',\n );\n\n/**\n * 查看当前全部UM挂单(USER_DATA)\n *\n * 查看当前全部UM挂单,请小心使用不带symbol参数的调用\n *\n * 权重: 带symbol 1 - 不带 40\n *\n * https://developers.binance.com/docs/zh-CN/derivatives/portfolio-margin/trade/Query-All-Current-UM-Open-Orders\n */\nexport const getUnifiedUmOpenOrders = (\n credential: ICredential,\n params?: {\n symbol?: string;\n },\n): Promise<IUnifiedUmOpenOrder[]> =>\n requestPrivate<IUnifiedUmOpenOrder[]>(\n credential,\n 'GET',\n 'https://papi.binance.com/papi/v1/um/openOrders',\n params,\n );\n\n/**\n * 查询账户余额(USER_DATA)\n *\n * 查询账户余额\n *\n * 权重: 20\n *\n * https://developers.binance.com/docs/zh-CN/derivatives/portfolio-margin/account/Account-Balance\n */\nexport const getUnifiedAccountBalance = (\n credential: ICredential,\n params?: {\n assets?: string;\n },\n): Promise<IUnifiedAccountBalanceEntry[] | IApiError> =>\n requestPrivate<IUnifiedAccountBalanceEntry[] | IApiError>(\n credential,\n 'GET',\n 'https://papi.binance.com/papi/v1/balance',\n params,\n );\n\n/**\n * 账户信息 (USER_DATA)\n *\n * 权重: 20\n *\n * https://developers.binance.com/docs/zh-CN/binance-spot-api-docs/rest-api#%E8%B4%A6%E6%88%B7%E4%BF%A1%E6%81%AF-user_data\n */\nexport const getSpotAccountInfo = (\n credential: ICredential,\n params?: {\n omitZeroBalances?: boolean;\n },\n): Promise<ISpotAccountInfo | IApiError> =>\n requestPrivate<ISpotAccountInfo | IApiError>(\n credential,\n 'GET',\n 'https://api.binance.com/api/v3/account',\n params,\n );\n\n/**\n * Current open orders (USER_DATA)\n *\n * 权重: 带symbol: 6 不带: 80\n *\n * https://developers.binance.com/docs/zh-CN/binance-spot-api-docs/rest-api/account-endpoints#%E6%9F%A5%E7%9C%8B%E8%B4%A6%E6%88%B7%E5%BD%93%E5%89%8D%E6%8C%82%E5%8D%95-user_data\n */\nexport const getSpotOpenOrders = (\n credential: ICredential,\n params?: {\n symbol?: string;\n },\n): Promise<ISpotOrder[] | IApiError> =>\n requestPrivate<ISpotOrder[] | IApiError>(\n credential,\n 'GET',\n 'https://api.binance.com/api/v3/openOrders',\n params,\n );\n\n/**\n * New order (TRADE)\n *\n * 权重: 1\n *\n * https://developers.binance.com/docs/zh-CN/binance-spot-api-docs/rest-api/trading-endpoints#%E4%B8%8B%E5%8D%95-trade\n */\nexport const postSpotOrder = (\n credential: ICredential,\n params: {\n symbol: string;\n side: string;\n type: string;\n timeInForce?: string;\n quantity?: number;\n quoteOrderQty?: number;\n price?: number;\n newClientOrderId?: string;\n strategyId?: number;\n strategyType?: number;\n stopPrice?: number;\n trailingDelta?: number;\n icebergQty?: number;\n newOrderRespType?: string;\n selfTradePreventionMode?: string;\n pegPriceType?: string;\n pegOffsetValue?: number;\n pegOffsetType?: string;\n },\n): Promise<ISpotNewOrderResponse | IApiError> =>\n requestPrivate<ISpotNewOrderResponse | IApiError>(\n credential,\n 'POST',\n 'https://api.binance.com/api/v3/order',\n params,\n );\n\n/**\n * Cancel order (TRADE)\n *\n * 权重: 1\n *\n * https://developers.binance.com/docs/zh-CN/binance-spot-api-docs/rest-api/trading-endpoints#%E6%92%A4%E9%94%80%E8%AE%A2%E5%8D%95-trade\n */\nexport const deleteSpotOrder = (\n credential: ICredential,\n params: {\n symbol: string;\n orderId?: string | number;\n origClientOrderId?: string;\n newClientOrderId?: string;\n cancelRestrictions?: string;\n },\n): Promise<ISpotOrder | IApiError> =>\n requestPrivate<ISpotOrder | IApiError>(\n credential,\n 'DELETE',\n 'https://api.binance.com/api/v3/order',\n params,\n );\n\n/**\n * 用户万向划转(USER_DATA)\n *\n * 用户万向划转\n *\n * 您需要开通api key 允许万向划转权限来调用此接口。\n *\n * 权重: 900\n *\n * https://developers.binance.com/docs/zh-CN/wallet/asset/user-universal-transfer\n */\nexport const postAssetTransfer = (\n credential: ICredential,\n params: {\n type: string;\n asset: string;\n amount: number;\n fromSymbol?: string;\n toSymbol?: string;\n },\n): Promise<IAssetTransferResponse | IApiError> =>\n requestPrivate<IAssetTransferResponse | IApiError>(\n credential,\n 'POST',\n 'https://api.binance.com/sapi/v1/asset/transfer',\n params,\n );\n\n/**\n * 统一账户资金归集(TRADE)\n *\n * 资金归集到统一账户钱包\n *\n * 权重: 750\n *\n * https://developers.binance.com/docs/zh-CN/derivatives/portfolio-margin/account/Fund-Auto-collection\n *\n * ISSUE(2024-07-18): 目前这是唯一能够将资金从原 U 本位合约账户转入统一账户的接口。\n */\nexport const postUnifiedAccountAutoCollection = (credential: ICredential): Promise<{ msg: string }> =>\n requestPrivate<{ msg: string }>(credential, 'POST', 'https://papi.binance.com/papi/v1/auto-collection');\n\n/**\n * 获取充值地址(支持多网络)(USER_DATA)\n *\n * 获取充值地址\n *\n * 权重: 10\n *\n * https://developers.binance.com/docs/zh-CN/wallet/capital/deposite-address\n */\nexport const getDepositAddress = (\n credential: ICredential,\n params: {\n coin: string;\n network?: string;\n amount?: number;\n },\n): Promise<IDepositAddress> =>\n requestPrivate<IDepositAddress>(\n credential,\n 'GET',\n 'https://api.binance.com/sapi/v1/capital/deposit/address',\n params,\n );\n\n/**\n * 查询子账户列表(适用主账户)\n *\n * 权重: 1\n *\n * https://developers.binance.com/docs/zh-CN/sub_account/account-management/Query-Sub-account-List\n */\nexport const getSubAccountList = (\n credential: ICredential,\n params?: {\n email?: string;\n isFreeze?: number;\n page?: number;\n limit?: number;\n },\n): Promise<ISubAccountListResponse | IApiError> =>\n requestPrivate<ISubAccountListResponse | IApiError>(\n credential,\n 'GET',\n 'https://api.binance.com/sapi/v1/sub-account/list',\n params,\n );\n\n/**\n * 提币(USER_DATA)\n *\n * 权重: 600\n *\n * https://developers.binance.com/docs/zh-CN/wallet/capital/withdraw\n */\nexport const postWithdraw = (\n credential: ICredential,\n params: {\n coin: string;\n withdrawOrderId?: string;\n network?: string;\n address: string;\n addressTag?: string;\n amount: number;\n transactionFeeFlag?: boolean;\n name?: string;\n walletType?: number;\n },\n): Promise<{ id: string } | IApiError> =>\n requestPrivate<{ id: string } | IApiError>(\n credential,\n 'POST',\n 'https://api.binance.com/sapi/v1/capital/withdraw/apply',\n params,\n );\n\n/**\n * 获取提币历史(支持多网络)(USER_DATA)\n *\n * 获取提币历史 (支持多网络)\n *\n * 请求权重(IP)#\n * 18000 请求限制: 每秒10次\n *\n * 本接口特别采用每秒UID速率限制,用户的总秒级 UID 速率限制为180000/秒。从该接口收到的响应包含key X-SAPI-USED-UID-WEIGHT-1S,该key定义了当前 UID 使用的权重\n *\n * https://developers.binance.com/docs/zh-CN/wallet/capital/withdraw-history\n */\nexport const getWithdrawHistory = (\n credential: ICredential,\n params?: {\n coin?: string;\n withdrawOrderId?: string;\n status?: number;\n offset?: number;\n limit?: number;\n startTime?: number;\n endTime?: number;\n },\n): Promise<IWithdrawRecord[]> =>\n requestPrivate<IWithdrawRecord[]>(\n credential,\n 'GET',\n 'https://api.binance.com/sapi/v1/capital/withdraw/history',\n params,\n );\n\n/**\n * 获取充值历史(支持多网络)\n *\n * 权重: 1\n *\n * https://developers.binance.com/docs/zh-CN/wallet/capital/deposite-history\n */\nexport const getDepositHistory = (\n credential: ICredential,\n params?: {\n includeSource?: boolean;\n coin?: string;\n status?: number;\n startTime?: number;\n endTime?: number;\n offset?: number;\n limit?: number;\n txId?: string;\n },\n): Promise<IDepositRecord[]> =>\n requestPrivate<IDepositRecord[]>(\n credential,\n 'GET',\n 'https://api.binance.com/sapi/v1/capital/deposit/hisrec',\n params,\n );\n\n/**\n * UM下单(TRADE)\n *\n * 权重: 1\n *\n * https://developers.binance.com/docs/zh-CN/derivatives/portfolio-margin/trade/New-UM-Order\n */\nexport const postUmOrder = (\n credential: ICredential,\n params: {\n symbol: string;\n side: string;\n positionSide?: string;\n type: string;\n timeInForce?: string;\n quantity: number;\n reduceOnly?: string;\n price?: number;\n newClientOrderId?: string;\n newOrderRespType?: string;\n selfTradePreventionMode?: string;\n goodTillDate?: number;\n },\n): Promise<IUnifiedUmOrderResponse | IApiError> =>\n requestPrivate<IUnifiedUmOrderResponse | IApiError>(\n credential,\n 'POST',\n 'https://papi.binance.com/papi/v1/um/order',\n params,\n );\n\nexport const deleteUmOrder = (\n credential: ICredential,\n params: {\n symbol: string;\n orderId?: string | number;\n origClientOrderId?: string;\n },\n): Promise<IUnifiedUmOrderResponse | IApiError> =>\n requestPrivate<IUnifiedUmOrderResponse | IApiError>(\n credential,\n 'DELETE',\n 'https://papi.binance.com/papi/v1/um/order',\n params,\n );\n\n/**\n * 获取UM损益资金流水(USER_DATA)\n *\n * 权重: 30\n *\n * https://developers.binance.com/docs/zh-CN/derivatives/portfolio-margin/account/Get-UM-Income-History\n */\nexport const getUMIncome = (\n credential: ICredential,\n params?: {\n symbol?: string;\n incomeType?: string;\n startTime?: number;\n endTime?: number;\n recvWindow?: number;\n limit?: number;\n timestamp?: number;\n },\n): Promise<IUMIncomeRecord[]> =>\n requestPrivate<IUMIncomeRecord[]>(credential, 'GET', 'https://api.binance.com/papi/v1/um/income', params);\n\n/**\n * Cancel an Existing Order and Send a New Order (TRADE)\n *\n * 权重: 1\n *\n * https://developers.binance.com/docs/zh-CN/binance-spot-api-docs/rest-api/trading-endpoints#%E6%92%A4%E9%94%80%E5%B9%B6%E9%87%8D%E6%96%B0%E4%B8%8B%E5%8D%95-trade\n */\nexport const postSpotOrderCancelReplace = (\n credential: ICredential,\n params: {\n symbol: string;\n side: string;\n type: string;\n cancelReplaceMode: string;\n timeInForce?: string;\n quantity?: number;\n quoteOrderQty?: number;\n price?: number;\n cancelNewClientOrderId?: string;\n cancelOrigClientOrderId?: string;\n cancelOrderId?: number;\n newClientOrderId?: string;\n strategyId?: number;\n strategyType?: number;\n stopPrice?: number;\n trailingDelta?: number;\n icebergQty?: number;\n newOrderRespType?: string;\n selfTradePreventionMode?: string;\n pegPriceType?: string;\n pegOffsetValue?: number;\n pegOffsetType?: string;\n },\n): Promise<ISpotNewOrderResponse | IApiError> =>\n requestPrivate<ISpotNewOrderResponse | IApiError>(\n credential,\n 'POST',\n 'https://api.binance.com/api/v3/order/cancelReplace',\n params,\n );\n\n/**\n * Modify Order (TRADE)\n *\n * 权重: 1\n *\n * https://developers.binance.com/docs/zh-CN/derivatives/portfolio-margin/trade/Modify-UM-Order\n */\nexport const putUmOrder = (\n credential: ICredential,\n params: {\n orderId?: number;\n origClientOrderId?: string;\n symbol: string;\n side: string;\n quantity?: number;\n price?: number;\n priceMatch?: string;\n recvWindow?: number;\n timestamp?: number;\n },\n): Promise<IUnifiedUmOrderResponse | IApiError> =>\n requestPrivate<IUnifiedUmOrderResponse | IApiError>(\n credential,\n 'PUT',\n 'https://papi.binance.com/papi/v1/um/order',\n params,\n );\nexport interface IMarginPair {\n id: string;\n symbol: string;\n base: string;\n quote: string;\n isMarginTrade: boolean;\n isBuyAllowed: boolean;\n isSellAllowed: boolean;\n}\n\n/**\n * 获取所有全仓杠杆交易对(MARKET_DATA)\n *\n * 权重: 1\n *\n * https://developers.binance.com/docs/zh-CN/margin_trading/market-data/Get-All-Cross-Margin-Pairs\n */\nexport const getMarginAllPairs = (params?: { symbol?: string }): Promise<IMarginPair[]> => {\n const credential = getDefaultCredential();\n return requestPrivate<IMarginPair[]>(\n credential,\n 'GET',\n 'https://api.binance.com/sapi/v1/margin/allPairs',\n params,\n );\n};\n\n/**\n * Get a future hourly interest rate\n *\n * https://developers.binance.com/docs/zh-CN/margin_trading/borrow-and-repay/Get-a-future-hourly-interest-rate\n */\nexport const getMarginNextHourlyInterestRate = (params: {\n assets: string;\n isIsolated: boolean;\n}): Promise<\n {\n asset: string;\n nextHourlyInterestRate: string;\n }[]\n> => {\n const credential = getDefaultCredential();\n return requestPrivate<\n {\n asset: string;\n nextHourlyInterestRate: string;\n }[]\n >(credential, 'GET', 'https://api.binance.com/sapi/v1/margin/next-hourly-interest-rate', params);\n};\n\n/**\n * Query Margin Interest Rate History\n *\n * https://developers.binance.com/docs/zh-CN/margin_trading/borrow-and-repay/Query-Margin-Interest-Rate-History\n */\nexport const getMarginInterestRateHistory = (params: {\n asset: string;\n vipLevel?: number;\n startTime?: number;\n endTime?: number;\n limit?: number;\n}): Promise<\n {\n asset: string;\n dailyInterestRate: string;\n timestamp: number;\n vipLevel: number;\n }[]\n> => {\n const credential = getDefaultCredential();\n return requestPrivate<\n {\n asset: string;\n dailyInterestRate: string;\n timestamp: number;\n vipLevel: number;\n }[]\n >(credential, 'GET', 'https://api.binance.com/sapi/v1/margin/interestRateHistory', params);\n};\n\n/**\n *获取用户持仓\n * @param credential\n * https://developers.binance.com/docs/zh-CN/wallet/asset/user-assets#%E8%AF%B7%E6%B1%82%E5%8F%82%E6%95%B0\n * @param params\n * @returns\n */\nexport const getUserAsset = (\n credential: ICredential,\n params: {\n timestamp: number;\n asset?: string;\n needBtcValuation?: boolean;\n recvWindow?: number;\n },\n) => {\n return requestPrivate<\n | {\n asset: string;\n free: string;\n locked: string;\n freeze: string;\n withdrawing: string;\n ipoable: string;\n btcValuation: string;\n }[]\n | IApiError\n >(credential, 'POST', 'https://api.binance.com/sapi/v3/asset/getUserAsset', params);\n};\n\n/**\n * 查询资金账户\n * @param credential\n * https://developers.binance.com/docs/zh-CN/wallet/asset/funding-wallet?utm_source=chatgpt.com\n * @param params\n * @returns\n */\nexport const getFundingAsset = (\n credential: ICredential,\n params: {\n timestamp: number;\n asset?: string;\n needBtcValuation?: boolean;\n recvWindow?: number;\n },\n) => {\n return requestPrivate<\n | {\n asset: string;\n free: string;\n locked: string;\n freeze: string;\n withdrawing: string;\n ipoable: string;\n btcValuation: string;\n }[]\n | IApiError\n >(credential, 'POST', 'https://api.binance.com/sapi/v1/asset/get-funding-asset', params);\n};\n"]}
1
+ {"version":3,"file":"private-api.js","sourceRoot":"","sources":["../../src/api/private-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAExD,OAAO,EAAE,oBAAoB,EAA0B,cAAc,EAAE,MAAM,UAAU,CAAC;AAsOxF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,UAAuB,EAA4C,EAAE;IACzG,MAAM,QAAQ,GAAG,0CAA0C,CAAC;IAC5D,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC9B,MAAM,MAAM,GAAG,EAAE,CAAC;IAClB,UAAU,CACR,wBAAwB,EACxB,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,EAC3F,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E,IAAI,EAAE,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,EAC5F,GAAG,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,CAChD,CAAC;IACF,OAAO,cAAc,CAWnB,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;AAC1C,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,UAAuB,EACvB,MAKC,EACD,EAAE;IACF,MAAM,QAAQ,GAAG,yDAAyD,CAAC;IAC3E,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC9B,MAAM,MAAM,GAAG,CAAC,CAAC;IACjB,UAAU,CACR,wBAAwB,EACxB,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,EAC5F,GAAG,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,CAChD,CAAC;IACF,OAAO,cAAc,CAWnB,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;AAC1C,CAAC,CAAC","sourcesContent":["import { scopeError, tokenBucket } from '@yuants/utils';\n\nimport { getDefaultCredential, IApiError, ICredential, requestPrivate } from './client';\nexport type { ICredential };\n\nexport interface IUnifiedAccountInfo {\n uniMMR: string;\n accountEquity: string;\n actualEquity: string;\n accountInitialMargin: string;\n accountMaintMargin: string;\n accountStatus: string;\n virtualMaxWithdrawAmount: string;\n totalAvailableBalance: string;\n totalMarginOpenLoss: string;\n updateTime: number;\n}\n\nexport interface IUnifiedUmAsset {\n asset: string;\n crossWalletBalance: string;\n crossUnPnl: string;\n maintMargin: string;\n initialMargin: string;\n positionInitialMargin: string;\n openOrderInitialMargin: string;\n updateTime: number;\n}\n\nexport interface IUnifiedUmPosition {\n symbol: string;\n initialMargin: string;\n maintMargin: string;\n unrealizedProfit: string;\n positionInitialMargin: string;\n openOrderInitialMargin: string;\n leverage: string;\n entryPrice: string;\n maxNotional: string;\n bidNotional: string;\n askNotional: string;\n positionSide: string;\n positionAmt: string;\n updateTime: number;\n}\n\nexport interface IUnifiedUmAccount {\n assets: IUnifiedUmAsset[];\n positions: IUnifiedUmPosition[];\n}\n\nexport interface IUnifiedUmOpenOrder {\n avgPrice: string;\n clientOrderId: string;\n cumQuote: string;\n executedQty: string;\n orderId: number;\n origQty: string;\n origType: string;\n price: string;\n reduceOnly: boolean;\n side: string;\n positionSide: string;\n status: string;\n symbol: string;\n time: number;\n timeInForce: string;\n type: string;\n updateTime: number;\n selfTradePreventionMode: string;\n goodTillDate: number;\n}\n\nexport interface IUnifiedAccountBalanceEntry {\n asset: string;\n totalWalletBalance: string;\n crossMarginAsset: string;\n crossMarginBorrowed: string;\n crossMarginFree: string;\n crossMarginInterest: string;\n crossMarginLocked: string;\n umWalletBalance: string;\n umUnrealizedPNL: string;\n cmWalletBalance: string;\n cmUnrealizedPNL: string;\n updateTime: number;\n}\n\nexport interface ISpotAccountInfo {\n makerCommission: number;\n takerCommission: number;\n buyerCommission: number;\n sellerCommission: number;\n commissionRates: {\n maker: string;\n taker: string;\n buyer: string;\n seller: string;\n };\n canTrade: boolean;\n canWithdraw: boolean;\n canDeposit: boolean;\n brokered: boolean;\n requireSelfTradePrevention: boolean;\n preventSor: boolean;\n updateTime: number;\n balances: {\n asset: string;\n free: string;\n locked: string;\n }[];\n permissions: string[];\n uid: number;\n}\n\nexport interface ISpotOrder {\n symbol: string;\n orderId: number;\n orderListId: number;\n clientOrderId: string;\n price: string;\n origQty: string;\n executedQty: string;\n origQuoteOrderQty: string;\n cummulativeQuoteQty: string;\n status: string;\n timeInForce: string;\n type: string;\n side: string;\n stopPrice: string;\n icebergQty: string;\n time: number;\n updateTime: number;\n isWorking: boolean;\n}\n\nexport interface ISpotNewOrderResponse {\n symbol: string;\n orderId: number;\n clientOrderId: string;\n transactTime: number;\n}\n\nexport interface IAssetTransferResponse {\n tranId: number;\n}\n\nexport interface IDepositAddress {\n address: string;\n coin: string;\n tag: string;\n url: string;\n}\n\nexport interface ISubAccountSummary {\n email: string;\n isFreeze: boolean;\n createTime: number;\n isManagedSubAccount: boolean;\n isAssetManagementSubAccount: boolean;\n}\n\nexport interface ISubAccountListResponse {\n subAccounts: ISubAccountSummary[];\n}\n\nexport interface IWithdrawRecord {\n id: string;\n amount: string;\n transactionFee: string;\n coin: string;\n status: number;\n address: string;\n txId: string;\n applyTime: Date;\n network: string;\n transferType: number;\n info: string;\n confirmNo: number;\n walletType: number;\n txKey: string;\n completeTime: Date;\n}\n\nexport interface IDepositRecord {\n id: string;\n amount: string;\n coin: string;\n network: string;\n status: number;\n address: string;\n addressTag: string;\n txId: string;\n insertTime: number;\n transferType: number;\n confirmTimes: string;\n unlockConfirm: number;\n walletType: number;\n}\n\nexport interface IUnifiedUmOrderResponse {\n clientOrderId: string;\n cumQty: string;\n cumQuote: string;\n executedQty: string;\n orderId: number;\n avgPrice: string;\n origQty: string;\n price: string;\n reduceOnly: boolean;\n side: string;\n positionSide: string;\n status: string;\n symbol: string;\n timeInForce: string;\n type: string;\n selfTradePreventionMode: string;\n goodTillDate: number;\n updateTime: number;\n}\n\nexport interface IUMIncomeRecord {\n symbol: string;\n incomeType: string;\n income: string;\n asset: string;\n info: string;\n time: number;\n tranId: string;\n tradeId: string;\n}\n\n/**\n * 查询账户信息(USER_DATA)\n *\n * 查询账户信息\n *\n * 权重: 20\n *\n * https://developers.binance.com/docs/zh-CN/derivatives/portfolio-margin/account/Account-Information\n */\nexport const getUnifiedAccountInfo = (credential: ICredential): Promise<IUnifiedAccountInfo | IApiError> => {\n const endpoint = 'https://papi.binance.com/papi/v1/account';\n const url = new URL(endpoint);\n const weight = 20;\n scopeError(\n 'BINANCE_API_RATE_LIMIT',\n { method: 'GET', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight },\n () => tokenBucket(url.host).acquireSync(weight),\n );\n return requestPrivate<IUnifiedAccountInfo | IApiError>(credential, 'GET', endpoint);\n};\n\n/**\n * 获取UM账户信息\n *\n * 现有UM账户资产和仓位信息\n *\n * 权重: 5\n *\n * https://developers.binance.com/docs/zh-CN/derivatives/portfolio-margin/account/Get-UM-Account-Detail\n */\nexport const getUnifiedUmAccount = (credential: ICredential): Promise<IUnifiedUmAccount | IApiError> => {\n const endpoint = 'https://papi.binance.com/papi/v1/um/account';\n const url = new URL(endpoint);\n const weight = 5;\n scopeError(\n 'BINANCE_API_RATE_LIMIT',\n { method: 'GET', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight },\n () => tokenBucket(url.host).acquireSync(weight),\n );\n return requestPrivate<IUnifiedUmAccount | IApiError>(credential, 'GET', endpoint);\n};\n\n/**\n * 查看当前全部UM挂单(USER_DATA)\n *\n * 查看当前全部UM挂单,请小心使用不带symbol参数的调用\n *\n * 权重: 带symbol 1 - 不带 40\n *\n * https://developers.binance.com/docs/zh-CN/derivatives/portfolio-margin/trade/Query-All-Current-UM-Open-Orders\n */\nexport const getUnifiedUmOpenOrders = (\n credential: ICredential,\n params?: {\n symbol?: string;\n },\n): Promise<IUnifiedUmOpenOrder[]> => {\n const endpoint = 'https://papi.binance.com/papi/v1/um/openOrders';\n const url = new URL(endpoint);\n const weight = params?.symbol ? 1 : 40;\n scopeError(\n 'BINANCE_API_RATE_LIMIT',\n {\n method: 'GET',\n endpoint,\n host: url.host,\n path: url.pathname,\n bucketId: url.host,\n weight,\n hasSymbol: !!params?.symbol,\n },\n () => tokenBucket(url.host).acquireSync(weight),\n );\n return requestPrivate<IUnifiedUmOpenOrder[]>(credential, 'GET', endpoint, params);\n};\n\n/**\n * 查询账户余额(USER_DATA)\n *\n * 查询账户余额\n *\n * 权重: 20\n *\n * https://developers.binance.com/docs/zh-CN/derivatives/portfolio-margin/account/Account-Balance\n */\nexport const getUnifiedAccountBalance = (\n credential: ICredential,\n params?: {\n assets?: string;\n },\n): Promise<IUnifiedAccountBalanceEntry[] | IApiError> => {\n const endpoint = 'https://papi.binance.com/papi/v1/balance';\n const url = new URL(endpoint);\n const weight = 20;\n scopeError(\n 'BINANCE_API_RATE_LIMIT',\n { method: 'GET', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight },\n () => tokenBucket(url.host).acquireSync(weight),\n );\n return requestPrivate<IUnifiedAccountBalanceEntry[] | IApiError>(credential, 'GET', endpoint, params);\n};\n\n/**\n * 账户信息 (USER_DATA)\n *\n * 权重: 20\n *\n * https://developers.binance.com/docs/zh-CN/binance-spot-api-docs/rest-api#%E8%B4%A6%E6%88%B7%E4%BF%A1%E6%81%AF-user_data\n */\nexport const getSpotAccountInfo = (\n credential: ICredential,\n params?: {\n omitZeroBalances?: boolean;\n },\n): Promise<ISpotAccountInfo | IApiError> => {\n const endpoint = 'https://api.binance.com/api/v3/account';\n const url = new URL(endpoint);\n const weight = 20;\n scopeError(\n 'BINANCE_API_RATE_LIMIT',\n { method: 'GET', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight },\n () => tokenBucket(url.host).acquireSync(weight),\n );\n return requestPrivate<ISpotAccountInfo | IApiError>(credential, 'GET', endpoint, params);\n};\n\n/**\n * Current open orders (USER_DATA)\n *\n * 权重: 带symbol: 6 不带: 80\n *\n * https://developers.binance.com/docs/zh-CN/binance-spot-api-docs/rest-api/account-endpoints#%E6%9F%A5%E7%9C%8B%E8%B4%A6%E6%88%B7%E5%BD%93%E5%89%8D%E6%8C%82%E5%8D%95-user_data\n */\nexport const getSpotOpenOrders = (\n credential: ICredential,\n params?: {\n symbol?: string;\n },\n): Promise<ISpotOrder[] | IApiError> => {\n const endpoint = 'https://api.binance.com/api/v3/openOrders';\n const url = new URL(endpoint);\n const weight = params?.symbol ? 6 : 80;\n scopeError(\n 'BINANCE_API_RATE_LIMIT',\n {\n method: 'GET',\n endpoint,\n host: url.host,\n path: url.pathname,\n bucketId: url.host,\n weight,\n hasSymbol: !!params?.symbol,\n },\n () => tokenBucket(url.host).acquireSync(weight),\n );\n return requestPrivate<ISpotOrder[] | IApiError>(credential, 'GET', endpoint, params);\n};\n\n/**\n * New order (TRADE)\n *\n * 权重: 1\n *\n * https://developers.binance.com/docs/zh-CN/binance-spot-api-docs/rest-api/trading-endpoints#%E4%B8%8B%E5%8D%95-trade\n */\nexport const postSpotOrder = (\n credential: ICredential,\n params: {\n symbol: string;\n side: string;\n type: string;\n timeInForce?: string;\n quantity?: number;\n quoteOrderQty?: number;\n price?: number;\n newClientOrderId?: string;\n strategyId?: number;\n strategyType?: number;\n stopPrice?: number;\n trailingDelta?: number;\n icebergQty?: number;\n newOrderRespType?: string;\n selfTradePreventionMode?: string;\n pegPriceType?: string;\n pegOffsetValue?: number;\n pegOffsetType?: string;\n },\n): Promise<ISpotNewOrderResponse | IApiError> => {\n const endpoint = 'https://api.binance.com/api/v3/order';\n const url = new URL(endpoint);\n const weight = 1;\n scopeError(\n 'BINANCE_API_RATE_LIMIT',\n { method: 'POST', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight },\n () => tokenBucket(url.host).acquireSync(weight),\n );\n return requestPrivate<ISpotNewOrderResponse | IApiError>(credential, 'POST', endpoint, params);\n};\n\n/**\n * Cancel order (TRADE)\n *\n * 权重: 1\n *\n * https://developers.binance.com/docs/zh-CN/binance-spot-api-docs/rest-api/trading-endpoints#%E6%92%A4%E9%94%80%E8%AE%A2%E5%8D%95-trade\n */\nexport const deleteSpotOrder = (\n credential: ICredential,\n params: {\n symbol: string;\n orderId?: string | number;\n origClientOrderId?: string;\n newClientOrderId?: string;\n cancelRestrictions?: string;\n },\n): Promise<ISpotOrder | IApiError> => {\n const endpoint = 'https://api.binance.com/api/v3/order';\n const url = new URL(endpoint);\n const weight = 1;\n scopeError(\n 'BINANCE_API_RATE_LIMIT',\n { method: 'DELETE', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight },\n () => tokenBucket(url.host).acquireSync(weight),\n );\n return requestPrivate<ISpotOrder | IApiError>(credential, 'DELETE', endpoint, params);\n};\n\n/**\n * 用户万向划转(USER_DATA)\n *\n * 用户万向划转\n *\n * 您需要开通api key 允许万向划转权限来调用此接口。\n *\n * 权重: 900\n *\n * https://developers.binance.com/docs/zh-CN/wallet/asset/user-universal-transfer\n */\nexport const postAssetTransfer = (\n credential: ICredential,\n params: {\n type: string;\n asset: string;\n amount: number;\n fromSymbol?: string;\n toSymbol?: string;\n },\n): Promise<IAssetTransferResponse | IApiError> => {\n const endpoint = 'https://api.binance.com/sapi/v1/asset/transfer';\n const url = new URL(endpoint);\n const weight = 900;\n scopeError(\n 'BINANCE_API_RATE_LIMIT',\n { method: 'POST', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight },\n () => tokenBucket(url.host).acquireSync(weight),\n );\n return requestPrivate<IAssetTransferResponse | IApiError>(credential, 'POST', endpoint, params);\n};\n\n/**\n * 统一账户资金归集(TRADE)\n *\n * 资金归集到统一账户钱包\n *\n * 权重: 750\n *\n * https://developers.binance.com/docs/zh-CN/derivatives/portfolio-margin/account/Fund-Auto-collection\n *\n * ISSUE(2024-07-18): 目前这是唯一能够将资金从原 U 本位合约账户转入统一账户的接口。\n */\nexport const postUnifiedAccountAutoCollection = (credential: ICredential): Promise<{ msg: string }> => {\n const endpoint = 'https://papi.binance.com/papi/v1/auto-collection';\n const url = new URL(endpoint);\n const weight = 750;\n scopeError(\n 'BINANCE_API_RATE_LIMIT',\n { method: 'POST', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight },\n () => tokenBucket(url.host).acquireSync(weight),\n );\n return requestPrivate<{ msg: string }>(credential, 'POST', endpoint);\n};\n\n/**\n * 获取充值地址(支持多网络)(USER_DATA)\n *\n * 获取充值地址\n *\n * 权重: 10\n *\n * https://developers.binance.com/docs/zh-CN/wallet/capital/deposite-address\n */\nexport const getDepositAddress = (\n credential: ICredential,\n params: {\n coin: string;\n network?: string;\n amount?: number;\n },\n): Promise<IDepositAddress> => {\n const endpoint = 'https://api.binance.com/sapi/v1/capital/deposit/address';\n const url = new URL(endpoint);\n const weight = 10;\n scopeError(\n 'BINANCE_API_RATE_LIMIT',\n { method: 'GET', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight },\n () => tokenBucket(url.host).acquireSync(weight),\n );\n return requestPrivate<IDepositAddress>(credential, 'GET', endpoint, params);\n};\n\n/**\n * 查询子账户列表(适用主账户)\n *\n * 权重: 1\n *\n * https://developers.binance.com/docs/zh-CN/sub_account/account-management/Query-Sub-account-List\n */\nexport const getSubAccountList = (\n credential: ICredential,\n params?: {\n email?: string;\n isFreeze?: number;\n page?: number;\n limit?: number;\n },\n): Promise<ISubAccountListResponse | IApiError> => {\n const endpoint = 'https://api.binance.com/sapi/v1/sub-account/list';\n const url = new URL(endpoint);\n const weight = 1;\n scopeError(\n 'BINANCE_API_RATE_LIMIT',\n { method: 'GET', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight },\n () => tokenBucket(url.host).acquireSync(weight),\n );\n return requestPrivate<ISubAccountListResponse | IApiError>(credential, 'GET', endpoint, params);\n};\n\n/**\n * 提币(USER_DATA)\n *\n * 权重: 600\n *\n * https://developers.binance.com/docs/zh-CN/wallet/capital/withdraw\n */\nexport const postWithdraw = (\n credential: ICredential,\n params: {\n coin: string;\n withdrawOrderId?: string;\n network?: string;\n address: string;\n addressTag?: string;\n amount: number;\n transactionFeeFlag?: boolean;\n name?: string;\n walletType?: number;\n },\n): Promise<{ id: string } | IApiError> => {\n const endpoint = 'https://api.binance.com/sapi/v1/capital/withdraw/apply';\n const url = new URL(endpoint);\n const weight = 600;\n scopeError(\n 'BINANCE_API_RATE_LIMIT',\n { method: 'POST', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight },\n () => tokenBucket(url.host).acquireSync(weight),\n );\n return requestPrivate<{ id: string } | IApiError>(credential, 'POST', endpoint, params);\n};\n\n/**\n * 获取提币历史(支持多网络)(USER_DATA)\n *\n * 获取提币历史 (支持多网络)\n *\n * 请求权重(IP)#\n * 18000 请求限制: 每秒10次\n *\n * 本接口特别采用每秒UID速率限制,用户的总秒级 UID 速率限制为180000/秒。从该接口收到的响应包含key X-SAPI-USED-UID-WEIGHT-1S,该key定义了当前 UID 使用的权重\n *\n * https://developers.binance.com/docs/zh-CN/wallet/capital/withdraw-history\n */\nexport const getWithdrawHistory = (\n credential: ICredential,\n params?: {\n coin?: string;\n withdrawOrderId?: string;\n status?: number;\n offset?: number;\n limit?: number;\n startTime?: number;\n endTime?: number;\n },\n): Promise<IWithdrawRecord[]> => {\n const endpoint = 'https://api.binance.com/sapi/v1/capital/withdraw/history';\n const url = new URL(endpoint);\n const weight = 1;\n scopeError(\n 'BINANCE_API_RATE_LIMIT',\n { method: 'GET', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight },\n () => tokenBucket(url.host).acquireSync(weight),\n );\n return requestPrivate<IWithdrawRecord[]>(credential, 'GET', endpoint, params);\n};\n\n/**\n * 获取充值历史(支持多网络)\n *\n * 权重: 1\n *\n * https://developers.binance.com/docs/zh-CN/wallet/capital/deposite-history\n */\nexport const getDepositHistory = (\n credential: ICredential,\n params?: {\n includeSource?: boolean;\n coin?: string;\n status?: number;\n startTime?: number;\n endTime?: number;\n offset?: number;\n limit?: number;\n txId?: string;\n },\n): Promise<IDepositRecord[]> => {\n const endpoint = 'https://api.binance.com/sapi/v1/capital/deposit/hisrec';\n const url = new URL(endpoint);\n const weight = 1;\n scopeError(\n 'BINANCE_API_RATE_LIMIT',\n { method: 'GET', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight },\n () => tokenBucket(url.host).acquireSync(weight),\n );\n return requestPrivate<IDepositRecord[]>(credential, 'GET', endpoint, params);\n};\n\n/**\n * UM下单(TRADE)\n *\n * 权重: 1\n *\n * https://developers.binance.com/docs/zh-CN/derivatives/portfolio-margin/trade/New-UM-Order\n */\nexport const postUmOrder = (\n credential: ICredential,\n params: {\n symbol: string;\n side: string;\n positionSide?: string;\n type: string;\n timeInForce?: string;\n quantity: number;\n reduceOnly?: string;\n price?: number;\n newClientOrderId?: string;\n newOrderRespType?: string;\n selfTradePreventionMode?: string;\n goodTillDate?: number;\n },\n): Promise<IUnifiedUmOrderResponse | IApiError> => {\n const endpoint = 'https://papi.binance.com/papi/v1/um/order';\n const url = new URL(endpoint);\n const weight = 1;\n scopeError(\n 'BINANCE_UNIFIED_ORDER_API_RATE_LIMIT',\n { method: 'POST', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight },\n () => tokenBucket('order/unified/minute').acquireSync(weight),\n );\n return requestPrivate<IUnifiedUmOrderResponse | IApiError>(credential, 'POST', endpoint, params);\n};\n\nexport const deleteUmOrder = (\n credential: ICredential,\n params: {\n symbol: string;\n orderId?: string | number;\n origClientOrderId?: string;\n },\n): Promise<IUnifiedUmOrderResponse | IApiError> => {\n const endpoint = 'https://papi.binance.com/papi/v1/um/order';\n const url = new URL(endpoint);\n const weight = 1;\n scopeError(\n 'BINANCE_UNIFIED_ORDER_API_RATE_LIMIT',\n { method: 'DELETE', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight },\n () => tokenBucket('order/unified/minute').acquireSync(weight),\n );\n return requestPrivate<IUnifiedUmOrderResponse | IApiError>(credential, 'DELETE', endpoint, params);\n};\n\n/**\n * 获取UM损益资金流水(USER_DATA)\n *\n * 权重: 30\n *\n * https://developers.binance.com/docs/zh-CN/derivatives/portfolio-margin/account/Get-UM-Income-History\n */\nexport const getUMIncome = (\n credential: ICredential,\n params?: {\n symbol?: string;\n incomeType?: string;\n startTime?: number;\n endTime?: number;\n recvWindow?: number;\n limit?: number;\n timestamp?: number;\n },\n): Promise<IUMIncomeRecord[]> => {\n const endpoint = 'https://papi.binance.com/papi/v1/um/income';\n const url = new URL(endpoint);\n const weight = 30;\n scopeError(\n 'BINANCE_API_RATE_LIMIT',\n { method: 'GET', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight },\n () => tokenBucket(url.host).acquireSync(weight),\n );\n return requestPrivate<IUMIncomeRecord[]>(credential, 'GET', endpoint, params);\n};\n\n/**\n * Cancel an Existing Order and Send a New Order (TRADE)\n *\n * 权重: 1\n *\n * https://developers.binance.com/docs/zh-CN/binance-spot-api-docs/rest-api/trading-endpoints#%E6%92%A4%E9%94%80%E5%B9%B6%E9%87%8D%E6%96%B0%E4%B8%8B%E5%8D%95-trade\n */\nexport const postSpotOrderCancelReplace = (\n credential: ICredential,\n params: {\n symbol: string;\n side: string;\n type: string;\n cancelReplaceMode: string;\n timeInForce?: string;\n quantity?: number;\n quoteOrderQty?: number;\n price?: number;\n cancelNewClientOrderId?: string;\n cancelOrigClientOrderId?: string;\n cancelOrderId?: number;\n newClientOrderId?: string;\n strategyId?: number;\n strategyType?: number;\n stopPrice?: number;\n trailingDelta?: number;\n icebergQty?: number;\n newOrderRespType?: string;\n selfTradePreventionMode?: string;\n pegPriceType?: string;\n pegOffsetValue?: number;\n pegOffsetType?: string;\n },\n): Promise<ISpotNewOrderResponse | IApiError> => {\n const endpoint = 'https://api.binance.com/api/v3/order/cancelReplace';\n const url = new URL(endpoint);\n const weight = 1;\n scopeError(\n 'BINANCE_API_RATE_LIMIT',\n { method: 'POST', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight },\n () => tokenBucket(url.host).acquireSync(weight),\n );\n return requestPrivate<ISpotNewOrderResponse | IApiError>(credential, 'POST', endpoint, params);\n};\n\n/**\n * Modify Order (TRADE)\n *\n * 权重: 1\n *\n * https://developers.binance.com/docs/zh-CN/derivatives/portfolio-margin/trade/Modify-UM-Order\n */\nexport const putUmOrder = (\n credential: ICredential,\n params: {\n orderId?: number;\n origClientOrderId?: string;\n symbol: string;\n side: string;\n quantity?: number;\n price?: number;\n priceMatch?: string;\n recvWindow?: number;\n timestamp?: number;\n },\n): Promise<IUnifiedUmOrderResponse | IApiError> => {\n const endpoint = 'https://papi.binance.com/papi/v1/um/order';\n const url = new URL(endpoint);\n const weight = 1;\n scopeError(\n 'BINANCE_API_RATE_LIMIT',\n { method: 'PUT', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight },\n () => tokenBucket(url.host).acquireSync(weight),\n );\n return requestPrivate<IUnifiedUmOrderResponse | IApiError>(credential, 'PUT', endpoint, params);\n};\nexport interface IMarginPair {\n id: string;\n symbol: string;\n base: string;\n quote: string;\n isMarginTrade: boolean;\n isBuyAllowed: boolean;\n isSellAllowed: boolean;\n}\n\n/**\n * 获取所有全仓杠杆交易对(MARKET_DATA)\n *\n * 权重: 1\n *\n * https://developers.binance.com/docs/zh-CN/margin_trading/market-data/Get-All-Cross-Margin-Pairs\n */\nexport const getMarginAllPairs = (params?: { symbol?: string }): Promise<IMarginPair[]> => {\n const credential = getDefaultCredential();\n const endpoint = 'https://api.binance.com/sapi/v1/margin/allPairs';\n const url = new URL(endpoint);\n const weight = 1;\n scopeError(\n 'BINANCE_API_RATE_LIMIT',\n { method: 'GET', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight },\n () => tokenBucket(url.host).acquireSync(weight),\n );\n return requestPrivate<IMarginPair[]>(credential, 'GET', endpoint, params);\n};\n\n/**\n * Get a future hourly interest rate\n *\n * https://developers.binance.com/docs/zh-CN/margin_trading/borrow-and-repay/Get-a-future-hourly-interest-rate\n */\nexport const getMarginNextHourlyInterestRate = (params: {\n assets: string;\n isIsolated: boolean;\n}): Promise<\n {\n asset: string;\n nextHourlyInterestRate: string;\n }[]\n> => {\n const credential = getDefaultCredential();\n const endpoint = 'https://api.binance.com/sapi/v1/margin/next-hourly-interest-rate';\n const url = new URL(endpoint);\n const weight = 1;\n scopeError(\n 'BINANCE_API_RATE_LIMIT',\n { method: 'GET', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight },\n () => tokenBucket(url.host).acquireSync(weight),\n );\n return requestPrivate<\n {\n asset: string;\n nextHourlyInterestRate: string;\n }[]\n >(credential, 'GET', endpoint, params);\n};\n\n/**\n * Query Margin Interest Rate History\n *\n * https://developers.binance.com/docs/zh-CN/margin_trading/borrow-and-repay/Query-Margin-Interest-Rate-History\n */\nexport const getMarginInterestRateHistory = (params: {\n asset: string;\n vipLevel?: number;\n startTime?: number;\n endTime?: number;\n limit?: number;\n}): Promise<\n {\n asset: string;\n dailyInterestRate: string;\n timestamp: number;\n vipLevel: number;\n }[]\n> => {\n const credential = getDefaultCredential();\n const endpoint = 'https://api.binance.com/sapi/v1/margin/interestRateHistory';\n const url = new URL(endpoint);\n const weight = 1;\n scopeError(\n 'BINANCE_API_RATE_LIMIT',\n { method: 'GET', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight },\n () => tokenBucket(url.host).acquireSync(weight),\n );\n return requestPrivate<\n {\n asset: string;\n dailyInterestRate: string;\n timestamp: number;\n vipLevel: number;\n }[]\n >(credential, 'GET', endpoint, params);\n};\n\n/**\n *获取用户持仓\n * @param credential\n * https://developers.binance.com/docs/zh-CN/wallet/asset/user-assets#%E8%AF%B7%E6%B1%82%E5%8F%82%E6%95%B0\n * @param params\n * @returns\n */\nexport const getUserAsset = (\n credential: ICredential,\n params: {\n timestamp: number;\n asset?: string;\n needBtcValuation?: boolean;\n recvWindow?: number;\n },\n) => {\n const endpoint = 'https://api.binance.com/sapi/v3/asset/getUserAsset';\n const url = new URL(endpoint);\n const weight = 1;\n scopeError(\n 'BINANCE_API_RATE_LIMIT',\n { method: 'POST', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight },\n () => tokenBucket(url.host).acquireSync(weight),\n );\n return requestPrivate<\n | {\n asset: string;\n free: string;\n locked: string;\n freeze: string;\n withdrawing: string;\n ipoable: string;\n btcValuation: string;\n }[]\n | IApiError\n >(credential, 'POST', endpoint, params);\n};\n\n/**\n * 查询资金账户\n * @param credential\n * https://developers.binance.com/docs/zh-CN/wallet/asset/funding-wallet?utm_source=chatgpt.com\n * @param params\n * @returns\n */\nexport const getFundingAsset = (\n credential: ICredential,\n params: {\n timestamp: number;\n asset?: string;\n needBtcValuation?: boolean;\n recvWindow?: number;\n },\n) => {\n const endpoint = 'https://api.binance.com/sapi/v1/asset/get-funding-asset';\n const url = new URL(endpoint);\n const weight = 1;\n scopeError(\n 'BINANCE_API_RATE_LIMIT',\n { method: 'POST', endpoint, host: url.host, path: url.pathname, bucketId: url.host, weight },\n () => tokenBucket(url.host).acquireSync(weight),\n );\n return requestPrivate<\n | {\n asset: string;\n free: string;\n locked: string;\n freeze: string;\n withdrawing: string;\n ipoable: string;\n btcValuation: string;\n }[]\n | IApiError\n >(credential, 'POST', endpoint, params);\n};\n"]}