@reyaxyz/api-sdk 0.8.0 → 0.10.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.
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
15
  };
@@ -11,13 +22,23 @@ var account_1 = __importDefault(require("./modules/account"));
11
22
  * @description Client for API
12
23
  */
13
24
  var ApiClient = /** @class */ (function () {
14
- function ApiClient(config, apiTimeout) {
15
- this.config = config;
16
- this.apiTimeout = apiTimeout !== null && apiTimeout !== void 0 ? apiTimeout : constants_1.API_TIMEOUT;
17
- this._markets = new markets_1.default(config.restEndpoint);
18
- this._account = new account_1.default(config.restEndpoint);
25
+ function ApiClient(config) {
26
+ this.apiEndpoint = config.production ? constants_1.API_PRODUCTION : constants_1.API_TESTNET;
27
+ ApiClient.config = __assign(__assign({}, ApiClient.config), config);
28
+ this._markets = new markets_1.default(this.apiEndpoint);
29
+ this._account = new account_1.default(this.apiEndpoint);
19
30
  }
20
- Object.defineProperty(ApiClient.prototype, "markets", {
31
+ ApiClient.configure = function (config) {
32
+ ApiClient.config = config;
33
+ ApiClient.instance = new ApiClient(config);
34
+ };
35
+ ApiClient.getInstance = function () {
36
+ if (!ApiClient.instance) {
37
+ throw new Error('ApiClient is not configured. Please configure it before using.');
38
+ }
39
+ return ApiClient.instance;
40
+ };
41
+ Object.defineProperty(ApiClient, "markets", {
21
42
  /**
22
43
  * Provides access to the MarketsClient instance.
23
44
  * This getter allows for interacting with market-related API functionalities.
@@ -26,12 +47,12 @@ var ApiClient = /** @class */ (function () {
26
47
  * @memberof ApiClient
27
48
  */
28
49
  get: function () {
29
- return this._markets;
50
+ return ApiClient.getInstance()._markets;
30
51
  },
31
52
  enumerable: false,
32
53
  configurable: true
33
54
  });
34
- Object.defineProperty(ApiClient.prototype, "account", {
55
+ Object.defineProperty(ApiClient, "account", {
35
56
  /**
36
57
  * Provides access to the AccountClient instance.
37
58
  * This getter allows for interacting with account-related API functionalities.
@@ -40,11 +61,15 @@ var ApiClient = /** @class */ (function () {
40
61
  * @memberof ApiClient
41
62
  */
42
63
  get: function () {
43
- return this._account;
64
+ return ApiClient.getInstance()._account;
44
65
  },
45
66
  enumerable: false,
46
67
  configurable: true
47
68
  });
69
+ ApiClient.config = {
70
+ production: true, // default value
71
+ timeout: constants_1.API_TIMEOUT, // default value, e.g., 5000 milliseconds
72
+ };
48
73
  return ApiClient;
49
74
  }());
50
75
  exports.ApiClient = ApiClient;
@@ -1 +1 @@
1
- {"version":3,"file":"api-client.js","sourceRoot":"/","sources":["clients/api-client.ts"],"names":[],"mappings":";;;;;;AAAA,iDAAiE;AACjE,8DAA8C;AAC9C,8DAA8C;AAE9C;;GAEG;AACH;IAME,mBAAY,MAAqB,EAAE,UAAmB;QACpD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,uBAAW,CAAC;QAE5C,IAAI,CAAC,QAAQ,GAAG,IAAI,iBAAa,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;QACvD,IAAI,CAAC,QAAQ,GAAG,IAAI,iBAAa,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IACzD,CAAC;IASD,sBAAI,8BAAO;QAPX;;;;;;WAMG;aACH;YACE,OAAO,IAAI,CAAC,QAAQ,CAAC;QACvB,CAAC;;;OAAA;IASD,sBAAI,8BAAO;QAPX;;;;;;WAMG;aACH;YACE,OAAO,IAAI,CAAC,QAAQ,CAAC;QACvB,CAAC;;;OAAA;IACH,gBAAC;AAAD,CAAC,AAnCD,IAmCC;AAnCY,8BAAS","sourcesContent":["import { ServiceConfig, API_TIMEOUT } from './helpers/constants';\nimport MarketsClient from './modules/markets';\nimport AccountClient from './modules/account';\n\n/**\n * @description Client for API\n */\nexport class ApiClient {\n public readonly config: ServiceConfig;\n readonly apiTimeout: number;\n readonly _markets: MarketsClient;\n readonly _account: AccountClient;\n\n constructor(config: ServiceConfig, apiTimeout?: number) {\n this.config = config;\n this.apiTimeout = apiTimeout ?? API_TIMEOUT;\n\n this._markets = new MarketsClient(config.restEndpoint);\n this._account = new AccountClient(config.restEndpoint);\n }\n\n /**\n * Provides access to the MarketsClient instance.\n * This getter allows for interacting with market-related API functionalities.\n *\n * @returns {MarketsClient} An instance of MarketsClient for market-related operations.\n * @memberof ApiClient\n */\n get markets(): MarketsClient {\n return this._markets;\n }\n\n /**\n * Provides access to the AccountClient instance.\n * This getter allows for interacting with account-related API functionalities.\n *\n * @returns {AccountClient} An instance of AccountClient for account-related operations.\n * @memberof ApiClient\n */\n get account(): AccountClient {\n return this._account;\n }\n}\n"]}
1
+ {"version":3,"file":"api-client.js","sourceRoot":"/","sources":["clients/api-client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,iDAK6B;AAC7B,8DAA8C;AAC9C,8DAA8C;AAE9C;;GAEG;AACH;IAUE,mBAAoB,MAAqB;QACvC,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,0BAAc,CAAC,CAAC,CAAC,uBAAW,CAAC;QACpE,SAAS,CAAC,MAAM,yBAAQ,SAAS,CAAC,MAAM,GAAK,MAAM,CAAE,CAAC;QACtD,IAAI,CAAC,QAAQ,GAAG,IAAI,iBAAa,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QACpD,IAAI,CAAC,QAAQ,GAAG,IAAI,iBAAa,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACtD,CAAC;IAEa,mBAAS,GAAvB,UAAwB,MAAqB;QAC3C,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC;QAC1B,SAAS,CAAC,QAAQ,GAAG,IAAI,SAAS,CAAC,MAAM,CAAC,CAAC;IAC7C,CAAC;IAEc,qBAAW,GAA1B;QACE,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CACb,gEAAgE,CACjE,CAAC;QACJ,CAAC;QACD,OAAO,SAAS,CAAC,QAAQ,CAAC;IAC5B,CAAC;IASD,sBAAkB,oBAAO;QAPzB;;;;;;WAMG;aACH;YACE,OAAO,SAAS,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC;QAC1C,CAAC;;;OAAA;IASD,sBAAkB,oBAAO;QAPzB;;;;;;WAMG;aACH;YACE,OAAO,SAAS,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC;QAC1C,CAAC;;;OAAA;IAjDc,gBAAM,GAAkB;QACrC,UAAU,EAAE,IAAI,EAAE,gBAAgB;QAClC,OAAO,EAAE,uBAAW,EAAE,yCAAyC;KAChE,CAAC;IA+CJ,gBAAC;CAAA,AApDD,IAoDC;AApDY,8BAAS","sourcesContent":["import {\n ServiceConfig,\n API_TIMEOUT,\n API_TESTNET,\n API_PRODUCTION,\n} from './helpers/constants';\nimport MarketsClient from './modules/markets';\nimport AccountClient from './modules/account';\n\n/**\n * @description Client for API\n */\nexport class ApiClient {\n private static instance: ApiClient;\n private static config: ServiceConfig = {\n production: true, // default value\n timeout: API_TIMEOUT, // default value, e.g., 5000 milliseconds\n };\n private readonly apiEndpoint: string;\n private readonly _markets: MarketsClient;\n private readonly _account: AccountClient;\n\n private constructor(config: ServiceConfig) {\n this.apiEndpoint = config.production ? API_PRODUCTION : API_TESTNET;\n ApiClient.config = { ...ApiClient.config, ...config };\n this._markets = new MarketsClient(this.apiEndpoint);\n this._account = new AccountClient(this.apiEndpoint);\n }\n\n public static configure(config: ServiceConfig): void {\n ApiClient.config = config;\n ApiClient.instance = new ApiClient(config);\n }\n\n private static getInstance(): ApiClient {\n if (!ApiClient.instance) {\n throw new Error(\n 'ApiClient is not configured. Please configure it before using.',\n );\n }\n return ApiClient.instance;\n }\n\n /**\n * Provides access to the MarketsClient instance.\n * This getter allows for interacting with market-related API functionalities.\n *\n * @returns {MarketsClient} An instance of MarketsClient for market-related operations.\n * @memberof ApiClient\n */\n public static get markets(): MarketsClient {\n return ApiClient.getInstance()._markets;\n }\n\n /**\n * Provides access to the AccountClient instance.\n * This getter allows for interacting with account-related API functionalities.\n *\n * @returns {AccountClient} An instance of AccountClient for account-related operations.\n * @memberof ApiClient\n */\n public static get account(): AccountClient {\n return ApiClient.getInstance()._account;\n }\n}\n"]}
@@ -1,13 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ServiceConfig = exports.API_TIMEOUT = void 0;
3
+ exports.API_TESTNET = exports.API_PRODUCTION = exports.API_TIMEOUT = void 0;
4
4
  exports.API_TIMEOUT = 2500;
5
- var ServiceConfig = /** @class */ (function () {
6
- function ServiceConfig(restEndpoint, websocketEndpoint) {
7
- this.restEndpoint = restEndpoint;
8
- this.websocketEndpoint = websocketEndpoint;
9
- }
10
- return ServiceConfig;
11
- }());
12
- exports.ServiceConfig = ServiceConfig;
5
+ exports.API_PRODUCTION = 'https://m8mjgmqmte.eu-central-1.awsapprunner.com';
6
+ exports.API_TESTNET = 'https://m8mjgmqmte.eu-central-1.awsapprunner.com';
13
7
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"/","sources":["clients/helpers/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,WAAW,GAAW,IAAI,CAAC;AAExC;IAIE,uBAAY,YAAoB,EAAE,iBAAyB;QACzD,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;IAC7C,CAAC;IACH,oBAAC;AAAD,CAAC,AARD,IAQC;AARY,sCAAa","sourcesContent":["export const API_TIMEOUT: number = 2500;\n\nexport class ServiceConfig {\n public restEndpoint: string;\n public websocketEndpoint: string;\n\n constructor(restEndpoint: string, websocketEndpoint: string) {\n this.restEndpoint = restEndpoint;\n this.websocketEndpoint = websocketEndpoint;\n }\n}\n"]}
1
+ {"version":3,"file":"constants.js","sourceRoot":"/","sources":["clients/helpers/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,WAAW,GAAW,IAAI,CAAC;AAO3B,QAAA,cAAc,GACzB,kDAAkD,CAAC;AAExC,QAAA,WAAW,GACtB,kDAAkD,CAAC","sourcesContent":["export const API_TIMEOUT: number = 2500;\n\nexport interface ServiceConfig {\n production?: boolean; // Base URL for the REST API\n timeout?: number; // Optional timeout for API requests\n}\n\nexport const API_PRODUCTION: string =\n 'https://m8mjgmqmte.eu-central-1.awsapprunner.com';\n\nexport const API_TESTNET: string =\n 'https://m8mjgmqmte.eu-central-1.awsapprunner.com';\n"]}
@@ -83,7 +83,7 @@ var MarketsClient = /** @class */ (function (_super) {
83
83
  var uri;
84
84
  return __generator(this, function (_a) {
85
85
  uri = '/api/markets';
86
- return [2 /*return*/, this.get(uri, { id: params.id })];
86
+ return [2 /*return*/, this.get(uri, { id: params === null || params === void 0 ? void 0 : params.id })];
87
87
  });
88
88
  });
89
89
  };
@@ -1 +1 @@
1
- {"version":3,"file":"markets.js","sourceRoot":"/","sources":["clients/modules/markets.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,gDAAgC;AAEhC;IAA2C,iCAAU;IAArD;;IAoEA,CAAC;IAnEC;;;;;;;;;;;;;;;;;OAiBG;IAEG,kCAAU,GAAhB,UAAiB,MAAwB;;;;gBACjC,GAAG,GAAG,cAAc,CAAC;gBAC3B,sBAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,EAAC;;;KACzC;IAED;;;;;;;;;;;;;;;;OAgBG;IAEG,wCAAgB,GAAtB,UACE,QAA4B,EAC5B,UAA6B,EAC7B,OAAuB,EACvB,KAAqB,EACrB,KAAqB;;;;gBAEf,GAAG,GAAG,+BAAwB,QAAQ,CAAE,CAAC;gBAC/C,sBAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE;wBACnB,UAAU,YAAA;wBACV,OAAO,SAAA;wBACP,KAAK,OAAA;wBACL,KAAK,OAAA;qBACN,CAAC,EAAC;;;KACJ;IAEK,gDAAwB,GAA9B,UACE,QAAgB,EAChB,KAAqB;;;;gBAEf,GAAG,GAAG,sBAAe,QAAQ,CAAE,CAAC;gBACtC,sBAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE;wBACnB,KAAK,OAAA;qBACN,CAAC,EAAC;;;KACJ;IACH,oBAAC;AAAD,CAAC,AApED,CAA2C,cAAU,GAoEpD","sourcesContent":["import {\n CandlesResolution,\n GetMarketsParams,\n MarketCandlesResponse,\n MarketEntity,\n TradesResponse,\n} from '../types';\nimport RestClient from './rest';\n\nexport default class MarketsClient extends RestClient {\n /**\n * Asynchronously retrieves market data from the API.\n *\n * This method makes a request to the API to fetch data for markets. If a specific market is provided as a parameter,\n * it fetches data for that particular market; otherwise, it fetches data for all available markets.\n *\n * @param {GetMarketsParams} [params] - The specific market ticker identifier for which data is requested. This parameter is optional.\n * @returns {Promise<MarketEntity[]>} A promise that resolves to the response containing market data.\n * @memberof MarketsClient\n *\n * @example\n * // Fetch data for all markets\n * const allMarketsData = await market.getMarkets();\n *\n * @example\n * // Fetch data for a specific market\n * const specificMarketData = await market.getMarkets('ETH-USDC');\n */\n\n async getMarkets(params: GetMarketsParams): Promise<MarketEntity[]> {\n const uri = '/api/markets';\n return this.get(uri, { id: params.id });\n }\n\n /**\n * Retrieves candlestick data for a specified market.\n *\n * This method fetches historical candlestick (or OHLC - Open, High, Low, Close) data for a given market.\n * The data can be filtered by time range (fromISO and toISO) and resolution.\n *\n * @param {number} marketId - The market identifier for which candlestick data is to be retrieved.\n * @param {CandlesResolution} resolution - The granularity of the candlestick data (e.g., '1MIN', '5MIN', '1HR').\n * @param {string|null} [fromISO] - The start time for the range of candlestick data in ISO 8601 format. Optional.\n * @param {string|null} [toISO] - The end time for the range of candlestick data in ISO 8601 format. Optional.\n * @param {number|null} [limit] - The maximum number of candlestick data points to retrieve. Optional.\n * @returns {Promise<MarketCandlesResponse>} A promise that resolves to the market candlestick data.\n * @memberof MarketsClient\n *\n * @example\n * const marketCandles = await market.getMarketCandles('BTC-USD', '1HR', '2023-01-01T00:00:00Z', '2023-01-02T00:00:00Z');\n */\n\n async getMarketCandles(\n marketId: MarketEntity['id'],\n resolution: CandlesResolution,\n fromISO?: string | null,\n toISO?: string | null,\n limit?: number | null,\n ): Promise<MarketCandlesResponse> {\n const uri = `/api/markets/candles/${marketId}`;\n return this.get(uri, {\n resolution,\n fromISO,\n toISO,\n limit,\n });\n }\n\n async getPerpetualMarketTrades(\n marketId: number,\n limit?: number | null,\n ): Promise<TradesResponse> {\n const uri = `/api/trades/${marketId}`;\n return this.get(uri, {\n limit,\n });\n }\n}\n"]}
1
+ {"version":3,"file":"markets.js","sourceRoot":"/","sources":["clients/modules/markets.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,gDAAgC;AAEhC;IAA2C,iCAAU;IAArD;;IAoEA,CAAC;IAnEC;;;;;;;;;;;;;;;;;OAiBG;IAEG,kCAAU,GAAhB,UAAiB,MAAyB;;;;gBAClC,GAAG,GAAG,cAAc,CAAC;gBAC3B,sBAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,EAAE,EAAE,CAAC,EAAC;;;KAC1C;IAED;;;;;;;;;;;;;;;;OAgBG;IAEG,wCAAgB,GAAtB,UACE,QAA4B,EAC5B,UAA6B,EAC7B,OAAuB,EACvB,KAAqB,EACrB,KAAqB;;;;gBAEf,GAAG,GAAG,+BAAwB,QAAQ,CAAE,CAAC;gBAC/C,sBAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE;wBACnB,UAAU,YAAA;wBACV,OAAO,SAAA;wBACP,KAAK,OAAA;wBACL,KAAK,OAAA;qBACN,CAAC,EAAC;;;KACJ;IAEK,gDAAwB,GAA9B,UACE,QAAgB,EAChB,KAAqB;;;;gBAEf,GAAG,GAAG,sBAAe,QAAQ,CAAE,CAAC;gBACtC,sBAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE;wBACnB,KAAK,OAAA;qBACN,CAAC,EAAC;;;KACJ;IACH,oBAAC;AAAD,CAAC,AApED,CAA2C,cAAU,GAoEpD","sourcesContent":["import {\n CandlesResolution,\n GetMarketsParams,\n MarketCandlesResponse,\n MarketEntity,\n TradesResponse,\n} from '../types';\nimport RestClient from './rest';\n\nexport default class MarketsClient extends RestClient {\n /**\n * Asynchronously retrieves market data from the API.\n *\n * This method makes a request to the API to fetch data for markets. If a specific market is provided as a parameter,\n * it fetches data for that particular market; otherwise, it fetches data for all available markets.\n *\n * @param {GetMarketsParams} [params] - The specific market ticker identifier for which data is requested. This parameter is optional.\n * @returns {Promise<MarketEntity[]>} A promise that resolves to the response containing market data.\n * @memberof MarketsClient\n *\n * @example\n * // Fetch data for all markets\n * const allMarketsData = await market.getMarkets();\n *\n * @example\n * // Fetch data for a specific market\n * const specificMarketData = await market.getMarkets('ETH-USDC');\n */\n\n async getMarkets(params?: GetMarketsParams): Promise<MarketEntity[]> {\n const uri = '/api/markets';\n return this.get(uri, { id: params?.id });\n }\n\n /**\n * Retrieves candlestick data for a specified market.\n *\n * This method fetches historical candlestick (or OHLC - Open, High, Low, Close) data for a given market.\n * The data can be filtered by time range (fromISO and toISO) and resolution.\n *\n * @param {number} marketId - The market identifier for which candlestick data is to be retrieved.\n * @param {CandlesResolution} resolution - The granularity of the candlestick data (e.g., '1MIN', '5MIN', '1HR').\n * @param {string|null} [fromISO] - The start time for the range of candlestick data in ISO 8601 format. Optional.\n * @param {string|null} [toISO] - The end time for the range of candlestick data in ISO 8601 format. Optional.\n * @param {number|null} [limit] - The maximum number of candlestick data points to retrieve. Optional.\n * @returns {Promise<MarketCandlesResponse>} A promise that resolves to the market candlestick data.\n * @memberof MarketsClient\n *\n * @example\n * const marketCandles = await market.getMarketCandles('BTC-USD', '1HR', '2023-01-01T00:00:00Z', '2023-01-02T00:00:00Z');\n */\n\n async getMarketCandles(\n marketId: MarketEntity['id'],\n resolution: CandlesResolution,\n fromISO?: string | null,\n toISO?: string | null,\n limit?: number | null,\n ): Promise<MarketCandlesResponse> {\n const uri = `/api/markets/candles/${marketId}`;\n return this.get(uri, {\n resolution,\n fromISO,\n toISO,\n limit,\n });\n }\n\n async getPerpetualMarketTrades(\n marketId: number,\n limit?: number | null,\n ): Promise<TradesResponse> {\n const uri = `/api/trades/${marketId}`;\n return this.get(uri, {\n limit,\n });\n }\n}\n"]}
package/dist/index.js CHANGED
@@ -1,6 +1,21 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
17
  exports.ApiClient = void 0;
4
18
  var api_client_1 = require("./clients/api-client");
5
19
  Object.defineProperty(exports, "ApiClient", { enumerable: true, get: function () { return api_client_1.ApiClient; } });
20
+ __exportStar(require("./clients/types"), exports);
6
21
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":";;;AAAA,mDAAiD;AAAxC,uGAAA,SAAS,OAAA","sourcesContent":["export { ApiClient } from './clients/api-client';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,mDAAiD;AAAxC,uGAAA,SAAS,OAAA;AAClB,kDAAgC","sourcesContent":["export { ApiClient } from './clients/api-client';\nexport * from './clients/types';\n"]}
@@ -5,11 +5,14 @@ import AccountClient from './modules/account';
5
5
  * @description Client for API
6
6
  */
7
7
  export declare class ApiClient {
8
- readonly config: ServiceConfig;
9
- readonly apiTimeout: number;
10
- readonly _markets: MarketsClient;
11
- readonly _account: AccountClient;
12
- constructor(config: ServiceConfig, apiTimeout?: number);
8
+ private static instance;
9
+ private static config;
10
+ private readonly apiEndpoint;
11
+ private readonly _markets;
12
+ private readonly _account;
13
+ private constructor();
14
+ static configure(config: ServiceConfig): void;
15
+ private static getInstance;
13
16
  /**
14
17
  * Provides access to the MarketsClient instance.
15
18
  * This getter allows for interacting with market-related API functionalities.
@@ -17,7 +20,7 @@ export declare class ApiClient {
17
20
  * @returns {MarketsClient} An instance of MarketsClient for market-related operations.
18
21
  * @memberof ApiClient
19
22
  */
20
- get markets(): MarketsClient;
23
+ static get markets(): MarketsClient;
21
24
  /**
22
25
  * Provides access to the AccountClient instance.
23
26
  * This getter allows for interacting with account-related API functionalities.
@@ -25,6 +28,6 @@ export declare class ApiClient {
25
28
  * @returns {AccountClient} An instance of AccountClient for account-related operations.
26
29
  * @memberof ApiClient
27
30
  */
28
- get account(): AccountClient;
31
+ static get account(): AccountClient;
29
32
  }
30
33
  //# sourceMappingURL=api-client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"api-client.d.ts","sourceRoot":"/","sources":["clients/api-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAe,MAAM,qBAAqB,CAAC;AACjE,OAAO,aAAa,MAAM,mBAAmB,CAAC;AAC9C,OAAO,aAAa,MAAM,mBAAmB,CAAC;AAE9C;;GAEG;AACH,qBAAa,SAAS;IACpB,SAAgB,MAAM,EAAE,aAAa,CAAC;IACtC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC;IACjC,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC;gBAErB,MAAM,EAAE,aAAa,EAAE,UAAU,CAAC,EAAE,MAAM;IAQtD;;;;;;OAMG;IACH,IAAI,OAAO,IAAI,aAAa,CAE3B;IAED;;;;;;OAMG;IACH,IAAI,OAAO,IAAI,aAAa,CAE3B;CACF"}
1
+ {"version":3,"file":"api-client.d.ts","sourceRoot":"/","sources":["clients/api-client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAId,MAAM,qBAAqB,CAAC;AAC7B,OAAO,aAAa,MAAM,mBAAmB,CAAC;AAC9C,OAAO,aAAa,MAAM,mBAAmB,CAAC;AAE9C;;GAEG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAY;IACnC,OAAO,CAAC,MAAM,CAAC,MAAM,CAGnB;IACF,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAgB;IACzC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAgB;IAEzC,OAAO;WAOO,SAAS,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI;IAKpD,OAAO,CAAC,MAAM,CAAC,WAAW;IAS1B;;;;;;OAMG;IACH,WAAkB,OAAO,IAAI,aAAa,CAEzC;IAED;;;;;;OAMG;IACH,WAAkB,OAAO,IAAI,aAAa,CAEzC;CACF"}
@@ -1,7 +1,8 @@
1
1
  export declare const API_TIMEOUT: number;
2
- export declare class ServiceConfig {
3
- restEndpoint: string;
4
- websocketEndpoint: string;
5
- constructor(restEndpoint: string, websocketEndpoint: string);
2
+ export interface ServiceConfig {
3
+ production?: boolean;
4
+ timeout?: number;
6
5
  }
6
+ export declare const API_PRODUCTION: string;
7
+ export declare const API_TESTNET: string;
7
8
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"/","sources":["clients/helpers/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,EAAE,MAAa,CAAC;AAExC,qBAAa,aAAa;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,iBAAiB,EAAE,MAAM,CAAC;gBAErB,YAAY,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM;CAI5D"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"/","sources":["clients/helpers/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,EAAE,MAAa,CAAC;AAExC,MAAM,WAAW,aAAa;IAC5B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,eAAO,MAAM,cAAc,EAAE,MACuB,CAAC;AAErD,eAAO,MAAM,WAAW,EAAE,MAC0B,CAAC"}
@@ -19,7 +19,7 @@ export default class MarketsClient extends RestClient {
19
19
  * // Fetch data for a specific market
20
20
  * const specificMarketData = await market.getMarkets('ETH-USDC');
21
21
  */
22
- getMarkets(params: GetMarketsParams): Promise<MarketEntity[]>;
22
+ getMarkets(params?: GetMarketsParams): Promise<MarketEntity[]>;
23
23
  /**
24
24
  * Retrieves candlestick data for a specified market.
25
25
  *
@@ -1 +1 @@
1
- {"version":3,"file":"markets.d.ts","sourceRoot":"/","sources":["clients/modules/markets.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,qBAAqB,EACrB,YAAY,EACZ,cAAc,EACf,MAAM,UAAU,CAAC;AAClB,OAAO,UAAU,MAAM,QAAQ,CAAC;AAEhC,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,UAAU;IACnD;;;;;;;;;;;;;;;;;OAiBG;IAEG,UAAU,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IAKnE;;;;;;;;;;;;;;;;OAgBG;IAEG,gBAAgB,CACpB,QAAQ,EAAE,YAAY,CAAC,IAAI,CAAC,EAC5B,UAAU,EAAE,iBAAiB,EAC7B,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,EACvB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,EACrB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GACpB,OAAO,CAAC,qBAAqB,CAAC;IAU3B,wBAAwB,CAC5B,QAAQ,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GACpB,OAAO,CAAC,cAAc,CAAC;CAM3B"}
1
+ {"version":3,"file":"markets.d.ts","sourceRoot":"/","sources":["clients/modules/markets.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,qBAAqB,EACrB,YAAY,EACZ,cAAc,EACf,MAAM,UAAU,CAAC;AAClB,OAAO,UAAU,MAAM,QAAQ,CAAC;AAEhC,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,UAAU;IACnD;;;;;;;;;;;;;;;;;OAiBG;IAEG,UAAU,CAAC,MAAM,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IAKpE;;;;;;;;;;;;;;;;OAgBG;IAEG,gBAAgB,CACpB,QAAQ,EAAE,YAAY,CAAC,IAAI,CAAC,EAC5B,UAAU,EAAE,iBAAiB,EAC7B,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,EACvB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,EACrB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GACpB,OAAO,CAAC,qBAAqB,CAAC;IAU3B,wBAAwB,CAC5B,QAAQ,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GACpB,OAAO,CAAC,cAAc,CAAC;CAM3B"}
@@ -1,2 +1,3 @@
1
1
  export { ApiClient } from './clients/api-client';
2
+ export * from './clients/types';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,cAAc,iBAAiB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reyaxyz/api-sdk",
3
- "version": "0.8.0",
3
+ "version": "0.10.0",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org"
@@ -36,5 +36,5 @@
36
36
  "axios": "^1.6.2"
37
37
  },
38
38
  "packageManager": "pnpm@8.10.4",
39
- "gitHead": "f762d6bc89fe5866fc0f22e21c4c804dc6147f08"
39
+ "gitHead": "faa38b7af7e74b04a98215efadbef38fab902665"
40
40
  }
@@ -1,4 +1,9 @@
1
- import { ServiceConfig, API_TIMEOUT } from './helpers/constants';
1
+ import {
2
+ ServiceConfig,
3
+ API_TIMEOUT,
4
+ API_TESTNET,
5
+ API_PRODUCTION,
6
+ } from './helpers/constants';
2
7
  import MarketsClient from './modules/markets';
3
8
  import AccountClient from './modules/account';
4
9
 
@@ -6,17 +11,34 @@ import AccountClient from './modules/account';
6
11
  * @description Client for API
7
12
  */
8
13
  export class ApiClient {
9
- public readonly config: ServiceConfig;
10
- readonly apiTimeout: number;
11
- readonly _markets: MarketsClient;
12
- readonly _account: AccountClient;
14
+ private static instance: ApiClient;
15
+ private static config: ServiceConfig = {
16
+ production: true, // default value
17
+ timeout: API_TIMEOUT, // default value, e.g., 5000 milliseconds
18
+ };
19
+ private readonly apiEndpoint: string;
20
+ private readonly _markets: MarketsClient;
21
+ private readonly _account: AccountClient;
13
22
 
14
- constructor(config: ServiceConfig, apiTimeout?: number) {
15
- this.config = config;
16
- this.apiTimeout = apiTimeout ?? API_TIMEOUT;
23
+ private constructor(config: ServiceConfig) {
24
+ this.apiEndpoint = config.production ? API_PRODUCTION : API_TESTNET;
25
+ ApiClient.config = { ...ApiClient.config, ...config };
26
+ this._markets = new MarketsClient(this.apiEndpoint);
27
+ this._account = new AccountClient(this.apiEndpoint);
28
+ }
29
+
30
+ public static configure(config: ServiceConfig): void {
31
+ ApiClient.config = config;
32
+ ApiClient.instance = new ApiClient(config);
33
+ }
17
34
 
18
- this._markets = new MarketsClient(config.restEndpoint);
19
- this._account = new AccountClient(config.restEndpoint);
35
+ private static getInstance(): ApiClient {
36
+ if (!ApiClient.instance) {
37
+ throw new Error(
38
+ 'ApiClient is not configured. Please configure it before using.',
39
+ );
40
+ }
41
+ return ApiClient.instance;
20
42
  }
21
43
 
22
44
  /**
@@ -26,8 +48,8 @@ export class ApiClient {
26
48
  * @returns {MarketsClient} An instance of MarketsClient for market-related operations.
27
49
  * @memberof ApiClient
28
50
  */
29
- get markets(): MarketsClient {
30
- return this._markets;
51
+ public static get markets(): MarketsClient {
52
+ return ApiClient.getInstance()._markets;
31
53
  }
32
54
 
33
55
  /**
@@ -37,7 +59,7 @@ export class ApiClient {
37
59
  * @returns {AccountClient} An instance of AccountClient for account-related operations.
38
60
  * @memberof ApiClient
39
61
  */
40
- get account(): AccountClient {
41
- return this._account;
62
+ public static get account(): AccountClient {
63
+ return ApiClient.getInstance()._account;
42
64
  }
43
65
  }
@@ -1,11 +1,12 @@
1
1
  export const API_TIMEOUT: number = 2500;
2
2
 
3
- export class ServiceConfig {
4
- public restEndpoint: string;
5
- public websocketEndpoint: string;
6
-
7
- constructor(restEndpoint: string, websocketEndpoint: string) {
8
- this.restEndpoint = restEndpoint;
9
- this.websocketEndpoint = websocketEndpoint;
10
- }
3
+ export interface ServiceConfig {
4
+ production?: boolean; // Base URL for the REST API
5
+ timeout?: number; // Optional timeout for API requests
11
6
  }
7
+
8
+ export const API_PRODUCTION: string =
9
+ 'https://m8mjgmqmte.eu-central-1.awsapprunner.com';
10
+
11
+ export const API_TESTNET: string =
12
+ 'https://m8mjgmqmte.eu-central-1.awsapprunner.com';
@@ -27,9 +27,9 @@ export default class MarketsClient extends RestClient {
27
27
  * const specificMarketData = await market.getMarkets('ETH-USDC');
28
28
  */
29
29
 
30
- async getMarkets(params: GetMarketsParams): Promise<MarketEntity[]> {
30
+ async getMarkets(params?: GetMarketsParams): Promise<MarketEntity[]> {
31
31
  const uri = '/api/markets';
32
- return this.get(uri, { id: params.id });
32
+ return this.get(uri, { id: params?.id });
33
33
  }
34
34
 
35
35
  /**
package/src/index.ts CHANGED
@@ -1 +1,2 @@
1
1
  export { ApiClient } from './clients/api-client';
2
+ export * from './clients/types';