@reyaxyz/api-sdk 0.141.10 → 0.142.0
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/README.md +1 -1
- package/dist/clients/modules/binance/index.js +104 -0
- package/dist/clients/modules/binance/index.js.map +1 -0
- package/dist/clients/modules/binance/types.js +3 -0
- package/dist/clients/modules/binance/types.js.map +1 -0
- package/dist/types/clients/modules/binance/index.d.ts +7 -0
- package/dist/types/clients/modules/binance/index.d.ts.map +1 -0
- package/dist/types/clients/modules/binance/types.d.ts +10 -0
- package/dist/types/clients/modules/binance/types.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/clients/modules/binance/index.ts +50 -0
- package/src/clients/modules/binance/types.ts +25 -0
package/README.md
CHANGED
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
|
|
7
7
|
| Statements | Branches | Functions | Lines |
|
|
8
8
|
| --------------------------- | ----------------------- | ------------------------- | ----------------- |
|
|
9
|
-
|  |  |  |  |
|
|
10
10
|
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
33
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.BinanceFuturesClient = void 0;
|
|
55
|
+
var common_1 = require("@reyaxyz/common");
|
|
56
|
+
// docs: https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api
|
|
57
|
+
var BinanceFuturesClient = /** @class */ (function (_super) {
|
|
58
|
+
__extends(BinanceFuturesClient, _super);
|
|
59
|
+
function BinanceFuturesClient() {
|
|
60
|
+
return _super.call(this, 'https://fapi.binance.com/fapi/v1/', 10000) || this;
|
|
61
|
+
}
|
|
62
|
+
BinanceFuturesClient.prototype.getCandles = function (symbol, interval, startTimeMS, endTimeMS) {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
64
|
+
var timeMS, response, batchAPI, batch;
|
|
65
|
+
return __generator(this, function (_a) {
|
|
66
|
+
switch (_a.label) {
|
|
67
|
+
case 0:
|
|
68
|
+
timeMS = startTimeMS;
|
|
69
|
+
response = [];
|
|
70
|
+
_a.label = 1;
|
|
71
|
+
case 1:
|
|
72
|
+
if (!(timeMS < endTimeMS)) return [3 /*break*/, 3];
|
|
73
|
+
return [4 /*yield*/, this.get("markPriceKlines", {
|
|
74
|
+
symbol: symbol,
|
|
75
|
+
interval: interval,
|
|
76
|
+
startTime: timeMS,
|
|
77
|
+
endTime: endTimeMS - 1,
|
|
78
|
+
limit: 1500,
|
|
79
|
+
})];
|
|
80
|
+
case 2:
|
|
81
|
+
batchAPI = _a.sent();
|
|
82
|
+
if (batchAPI.length === 0) {
|
|
83
|
+
return [3 /*break*/, 3];
|
|
84
|
+
}
|
|
85
|
+
batch = batchAPI.map(function (e) { return ({
|
|
86
|
+
openTimeMS: Number(e[0]),
|
|
87
|
+
open: Number(e[1]),
|
|
88
|
+
high: Number(e[2]),
|
|
89
|
+
low: Number(e[3]),
|
|
90
|
+
close: Number(e[4]),
|
|
91
|
+
closeTimeMS: Number(e[6]),
|
|
92
|
+
}); });
|
|
93
|
+
response.push.apply(response, batch);
|
|
94
|
+
timeMS = batch[batch.length - 1].closeTimeMS + 1;
|
|
95
|
+
return [3 /*break*/, 1];
|
|
96
|
+
case 3: return [2 /*return*/, response];
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
return BinanceFuturesClient;
|
|
102
|
+
}(common_1.RestClient));
|
|
103
|
+
exports.BinanceFuturesClient = BinanceFuturesClient;
|
|
104
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["clients/modules/binance/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAA6C;AAG7C,mGAAmG;AAEnG;IAA0C,wCAAU;IAClD;QACE,OAAA,MAAK,YAAC,mCAAmC,EAAE,KAAM,CAAC,SAAC;IACrD,CAAC;IAEK,yCAAU,GAAhB,UACE,MAAc,EACd,QAA+B,EAC/B,WAAmB,EACnB,SAAiB;;;;;;wBAEb,MAAM,GAAG,WAAW,CAAC;wBACnB,QAAQ,GAAoB,EAAE,CAAC;;;6BAE9B,CAAA,MAAM,GAAG,SAAS,CAAA;wBACN,qBAAM,IAAI,CAAC,GAAG,CAAa,iBAAiB,EAAE;gCAC7D,MAAM,QAAA;gCACN,QAAQ,UAAA;gCACR,SAAS,EAAE,MAAM;gCACjB,OAAO,EAAE,SAAS,GAAG,CAAC;gCACtB,KAAK,EAAE,IAAI;6BACZ,CAAC,EAAA;;wBANI,QAAQ,GAAG,SAMf;wBAEF,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;4BAC1B,wBAAM;wBACR,CAAC;wBAEK,KAAK,GAAG,QAAQ,CAAC,GAAG,CACxB,UAAC,CAAC,IAAoB,OAAA,CAAC;4BACrB,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;4BACxB,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;4BAClB,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;4BAClB,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;4BACjB,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;4BACnB,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;yBAC1B,CAAC,EAPoB,CAOpB,CACH,CAAC;wBAEF,QAAQ,CAAC,IAAI,OAAb,QAAQ,EAAS,KAAK,EAAE;wBACxB,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,WAAW,GAAG,CAAC,CAAC;;4BAGnD,sBAAO,QAAQ,EAAC;;;;KACjB;IACH,2BAAC;AAAD,CAAC,AA5CD,CAA0C,mBAAU,GA4CnD;AA5CY,oDAAoB","sourcesContent":["import { RestClient } from '@reyaxyz/common';\nimport { BinanceCandle, BinanceCandleInterval } from './types';\n\n// docs: https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api\n\nexport class BinanceFuturesClient extends RestClient {\n constructor() {\n super('https://fapi.binance.com/fapi/v1/', 10_000);\n }\n\n async getCandles(\n symbol: string,\n interval: BinanceCandleInterval,\n startTimeMS: number,\n endTimeMS: number,\n ): Promise<BinanceCandle[]> {\n let timeMS = startTimeMS;\n const response: BinanceCandle[] = [];\n\n while (timeMS < endTimeMS) {\n const batchAPI = await this.get<number[][]>(`markPriceKlines`, {\n symbol,\n interval,\n startTime: timeMS,\n endTime: endTimeMS - 1,\n limit: 1500,\n });\n\n if (batchAPI.length === 0) {\n break;\n }\n\n const batch = batchAPI.map(\n (e): BinanceCandle => ({\n openTimeMS: Number(e[0]),\n open: Number(e[1]),\n high: Number(e[2]),\n low: Number(e[3]),\n close: Number(e[4]),\n closeTimeMS: Number(e[6]),\n }),\n );\n\n response.push(...batch);\n timeMS = batch[batch.length - 1].closeTimeMS + 1;\n }\n\n return response;\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"/","sources":["clients/modules/binance/types.ts"],"names":[],"mappings":"","sourcesContent":["export type BinanceCandle = {\n openTimeMS: number;\n open: number;\n high: number;\n low: number;\n close: number;\n closeTimeMS: number;\n};\n\nexport type BinanceCandleInterval =\n | '1m'\n | '3m'\n | '5m'\n | '15m'\n | '30m'\n | '1h'\n | '2h'\n | '4h'\n | '6h'\n | '8h'\n | '12h'\n | '1d'\n | '3d'\n | '1w'\n | '1M';\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { RestClient } from '@reyaxyz/common';
|
|
2
|
+
import { BinanceCandle, BinanceCandleInterval } from './types';
|
|
3
|
+
export declare class BinanceFuturesClient extends RestClient {
|
|
4
|
+
constructor();
|
|
5
|
+
getCandles(symbol: string, interval: BinanceCandleInterval, startTimeMS: number, endTimeMS: number): Promise<BinanceCandle[]>;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["clients/modules/binance/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAI/D,qBAAa,oBAAqB,SAAQ,UAAU;;IAK5C,UAAU,CACd,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,qBAAqB,EAC/B,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,aAAa,EAAE,CAAC;CAkC5B"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type BinanceCandle = {
|
|
2
|
+
openTimeMS: number;
|
|
3
|
+
open: number;
|
|
4
|
+
high: number;
|
|
5
|
+
low: number;
|
|
6
|
+
close: number;
|
|
7
|
+
closeTimeMS: number;
|
|
8
|
+
};
|
|
9
|
+
export type BinanceCandleInterval = '1m' | '3m' | '5m' | '15m' | '30m' | '1h' | '2h' | '4h' | '6h' | '8h' | '12h' | '1d' | '3d' | '1w' | '1M';
|
|
10
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["clients/modules/binance/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAC7B,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,KAAK,GACL,KAAK,GACL,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,KAAK,GACL,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reyaxyz/api-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.142.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"ws": "^8.16.0"
|
|
43
43
|
},
|
|
44
44
|
"packageManager": "pnpm@8.3.1",
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "be4484eed692d0bf0718ce9321af3218f981c33f",
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/ws": "8.5.10"
|
|
48
48
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { RestClient } from '@reyaxyz/common';
|
|
2
|
+
import { BinanceCandle, BinanceCandleInterval } from './types';
|
|
3
|
+
|
|
4
|
+
// docs: https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api
|
|
5
|
+
|
|
6
|
+
export class BinanceFuturesClient extends RestClient {
|
|
7
|
+
constructor() {
|
|
8
|
+
super('https://fapi.binance.com/fapi/v1/', 10_000);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async getCandles(
|
|
12
|
+
symbol: string,
|
|
13
|
+
interval: BinanceCandleInterval,
|
|
14
|
+
startTimeMS: number,
|
|
15
|
+
endTimeMS: number,
|
|
16
|
+
): Promise<BinanceCandle[]> {
|
|
17
|
+
let timeMS = startTimeMS;
|
|
18
|
+
const response: BinanceCandle[] = [];
|
|
19
|
+
|
|
20
|
+
while (timeMS < endTimeMS) {
|
|
21
|
+
const batchAPI = await this.get<number[][]>(`markPriceKlines`, {
|
|
22
|
+
symbol,
|
|
23
|
+
interval,
|
|
24
|
+
startTime: timeMS,
|
|
25
|
+
endTime: endTimeMS - 1,
|
|
26
|
+
limit: 1500,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
if (batchAPI.length === 0) {
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const batch = batchAPI.map(
|
|
34
|
+
(e): BinanceCandle => ({
|
|
35
|
+
openTimeMS: Number(e[0]),
|
|
36
|
+
open: Number(e[1]),
|
|
37
|
+
high: Number(e[2]),
|
|
38
|
+
low: Number(e[3]),
|
|
39
|
+
close: Number(e[4]),
|
|
40
|
+
closeTimeMS: Number(e[6]),
|
|
41
|
+
}),
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
response.push(...batch);
|
|
45
|
+
timeMS = batch[batch.length - 1].closeTimeMS + 1;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return response;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type BinanceCandle = {
|
|
2
|
+
openTimeMS: number;
|
|
3
|
+
open: number;
|
|
4
|
+
high: number;
|
|
5
|
+
low: number;
|
|
6
|
+
close: number;
|
|
7
|
+
closeTimeMS: number;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type BinanceCandleInterval =
|
|
11
|
+
| '1m'
|
|
12
|
+
| '3m'
|
|
13
|
+
| '5m'
|
|
14
|
+
| '15m'
|
|
15
|
+
| '30m'
|
|
16
|
+
| '1h'
|
|
17
|
+
| '2h'
|
|
18
|
+
| '4h'
|
|
19
|
+
| '6h'
|
|
20
|
+
| '8h'
|
|
21
|
+
| '12h'
|
|
22
|
+
| '1d'
|
|
23
|
+
| '3d'
|
|
24
|
+
| '1w'
|
|
25
|
+
| '1M';
|