@reyaxyz/api-sdk 0.6.3

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.
Files changed (53) hide show
  1. package/LICENSE.md +1 -0
  2. package/README.md +18 -0
  3. package/dist/clients/api-client.js +51 -0
  4. package/dist/clients/api-client.js.map +1 -0
  5. package/dist/clients/helpers/constants.js +13 -0
  6. package/dist/clients/helpers/constants.js.map +1 -0
  7. package/dist/clients/helpers/query-helper.js +21 -0
  8. package/dist/clients/helpers/query-helper.js.map +1 -0
  9. package/dist/clients/lib/axios.js +69 -0
  10. package/dist/clients/lib/axios.js.map +1 -0
  11. package/dist/clients/modules/account.js +122 -0
  12. package/dist/clients/modules/account.js.map +1 -0
  13. package/dist/clients/modules/markets.js +135 -0
  14. package/dist/clients/modules/markets.js.map +1 -0
  15. package/dist/clients/modules/rest.js +77 -0
  16. package/dist/clients/modules/rest.js.map +1 -0
  17. package/dist/clients/socket-client.js +2 -0
  18. package/dist/clients/socket-client.js.map +1 -0
  19. package/dist/clients/types.js +14 -0
  20. package/dist/clients/types.js.map +1 -0
  21. package/dist/index.js +6 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/types/clients/api-client.d.ts +30 -0
  24. package/dist/types/clients/api-client.d.ts.map +1 -0
  25. package/dist/types/clients/helpers/constants.d.ts +7 -0
  26. package/dist/types/clients/helpers/constants.d.ts.map +1 -0
  27. package/dist/types/clients/helpers/query-helper.d.ts +2 -0
  28. package/dist/types/clients/helpers/query-helper.d.ts.map +1 -0
  29. package/dist/types/clients/lib/axios.d.ts +14 -0
  30. package/dist/types/clients/lib/axios.d.ts.map +1 -0
  31. package/dist/types/clients/modules/account.d.ts +45 -0
  32. package/dist/types/clients/modules/account.d.ts.map +1 -0
  33. package/dist/types/clients/modules/markets.d.ts +43 -0
  34. package/dist/types/clients/modules/markets.d.ts.map +1 -0
  35. package/dist/types/clients/modules/rest.d.ts +9 -0
  36. package/dist/types/clients/modules/rest.d.ts.map +1 -0
  37. package/dist/types/clients/socket-client.d.ts +1 -0
  38. package/dist/types/clients/socket-client.d.ts.map +1 -0
  39. package/dist/types/clients/types.d.ts +106 -0
  40. package/dist/types/clients/types.d.ts.map +1 -0
  41. package/dist/types/index.d.ts +2 -0
  42. package/dist/types/index.d.ts.map +1 -0
  43. package/package.json +40 -0
  44. package/src/clients/api-client.ts +43 -0
  45. package/src/clients/helpers/constants.ts +11 -0
  46. package/src/clients/helpers/query-helper.ts +17 -0
  47. package/src/clients/lib/axios.ts +34 -0
  48. package/src/clients/modules/account.ts +63 -0
  49. package/src/clients/modules/markets.ts +77 -0
  50. package/src/clients/modules/rest.ts +31 -0
  51. package/src/clients/socket-client.ts +0 -0
  52. package/src/clients/types.ts +122 -0
  53. package/src/index.ts +1 -0
@@ -0,0 +1,30 @@
1
+ import { ServiceConfig } from './helpers/constants';
2
+ import MarketsClient from './modules/markets';
3
+ import AccountClient from './modules/account';
4
+ /**
5
+ * @description Client for API
6
+ */
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);
13
+ /**
14
+ * Provides access to the MarketsClient instance.
15
+ * This getter allows for interacting with market-related API functionalities.
16
+ *
17
+ * @returns {MarketsClient} An instance of MarketsClient for market-related operations.
18
+ * @memberof ApiClient
19
+ */
20
+ get markets(): MarketsClient;
21
+ /**
22
+ * Provides access to the AccountClient instance.
23
+ * This getter allows for interacting with account-related API functionalities.
24
+ *
25
+ * @returns {AccountClient} An instance of AccountClient for account-related operations.
26
+ * @memberof ApiClient
27
+ */
28
+ get account(): AccountClient;
29
+ }
30
+ //# sourceMappingURL=api-client.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,7 @@
1
+ export declare const API_TIMEOUT: number;
2
+ export declare class ServiceConfig {
3
+ restEndpoint: string;
4
+ websocketEndpoint: string;
5
+ constructor(restEndpoint: string, websocketEndpoint: string);
6
+ }
7
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,2 @@
1
+ export declare function generateQueryPath(url: string, params: NonNullable<unknown>): string;
2
+ //# sourceMappingURL=query-helper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query-helper.d.ts","sourceRoot":"/","sources":["clients/helpers/query-helper.ts"],"names":[],"mappings":"AAAA,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,GAC3B,MAAM,CAaR"}
@@ -0,0 +1,14 @@
1
+ export declare enum RequestMethod {
2
+ POST = "POST",
3
+ PUT = "PUT",
4
+ GET = "GET",
5
+ DELETE = "DELETE"
6
+ }
7
+ export type ResponseData = never;
8
+ export interface Response {
9
+ status: number;
10
+ data: ResponseData;
11
+ headers: NonNullable<unknown>;
12
+ }
13
+ export declare function request(url: string, method?: RequestMethod, body?: unknown | null, headers?: NonNullable<unknown>): Promise<Response>;
14
+ //# sourceMappingURL=axios.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"axios.d.ts","sourceRoot":"/","sources":["clients/lib/axios.ts"],"names":[],"mappings":"AAEA,oBAAY,aAAa;IACvB,IAAI,SAAS;IACb,GAAG,QAAQ;IACX,GAAG,QAAQ;IACX,MAAM,WAAW;CAClB;AAED,MAAM,MAAM,YAAY,GAAG,KAAK,CAAC;AAEjC,MAAM,WAAW,QAAQ;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,YAAY,CAAC;IACnB,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;CAC/B;AAMD,wBAAgB,OAAO,CACrB,GAAG,EAAE,MAAM,EACX,MAAM,GAAE,aAAiC,EACzC,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,EACrB,OAAO,GAAE,WAAW,CAAC,OAAO,CAAM,GACjC,OAAO,CAAC,QAAQ,CAAC,CAOnB"}
@@ -0,0 +1,45 @@
1
+ import { CollateralAccountListResponse, CollateralAccountResponse } from '../types';
2
+ import RestClient from './rest';
3
+ export default class AccountClient extends RestClient {
4
+ /**
5
+ * Asynchronously retrieves a list of collateral accounts associated with a specific address.
6
+ *
7
+ * This method makes a request to the API endpoint to fetch collateral account data. The data is filtered
8
+ * based on the provided Ethereum address. An optional limit can be specified to control the number of
9
+ * collateral accounts returned in the response.
10
+ *
11
+ * @param {string} address - The Ethereum address for which collateral account data is being requested.
12
+ * @param {number} [limit] - An optional limit on the number of collateral accounts to retrieve. If not specified,
13
+ * all available collateral accounts for the address will be returned.
14
+ * @returns {Promise<CollateralAccountListResponse>} A promise that resolves to the response containing the collateral
15
+ * account data.
16
+ * @memberof account
17
+ *
18
+ * @example
19
+ * // Fetch all collateral accounts for a specific address
20
+ * const accounts = await account.getCollateralAccounts('0x123...');
21
+ *
22
+ * @example
23
+ * // Fetch a limited number of collateral accounts for a specific address
24
+ * const limitedAccounts = await account.getCollateralAccounts('0x123...', 5);
25
+ */
26
+ getCollateralAccounts(address: string, limit?: number): Promise<CollateralAccountListResponse>;
27
+ /**
28
+ * Asynchronously retrieves details of a specific collateral account for a given Ethereum address.
29
+ *
30
+ * This method sends a request to the API to obtain detailed information about a specific collateral account
31
+ * associated with the provided Ethereum address. The account is identified using the collateral account number.
32
+ *
33
+ * @param {string} address - The Ethereum address associated with the collateral account.
34
+ * @param {number} collateralAccountNumber - The number identifying the specific collateral account.
35
+ * @returns {Promise<CollateralAccountResponse>} A promise that resolves to the response containing the detailed
36
+ * information of the specified collateral account.
37
+ * @memberof account
38
+ *
39
+ * @example
40
+ * // Fetch details of a specific collateral account by its number for a given address
41
+ * const accountDetails = await account.getCollateralAccount('0x123...', 1);
42
+ */
43
+ getCollateralAccount(address: string, collateralAccountNumber: number): Promise<CollateralAccountResponse>;
44
+ }
45
+ //# sourceMappingURL=account.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account.d.ts","sourceRoot":"/","sources":["clients/modules/account.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,6BAA6B,EAC7B,yBAAyB,EAC1B,MAAM,UAAU,CAAC;AAClB,OAAO,UAAU,MAAM,QAAQ,CAAC;AAEhC,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,UAAU;IACnD;;;;;;;;;;;;;;;;;;;;;OAqBG;IAEG,qBAAqB,CACzB,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,6BAA6B,CAAC;IAKzC;;;;;;;;;;;;;;;OAeG;IAEG,oBAAoB,CACxB,OAAO,EAAE,MAAM,EACf,uBAAuB,EAAE,MAAM,GAC9B,OAAO,CAAC,yBAAyB,CAAC;CAItC"}
@@ -0,0 +1,43 @@
1
+ import { CandlesResolution, MarketCandlesResponse, MarketListResponse, TradesResponse } from '../types';
2
+ import RestClient from './rest';
3
+ export default class MarketsClient extends RestClient {
4
+ /**
5
+ * Asynchronously retrieves market data from the API.
6
+ *
7
+ * This method makes a request to the API to fetch data for markets. If a specific market is provided as a parameter,
8
+ * it fetches data for that particular market; otherwise, it fetches data for all available markets.
9
+ *
10
+ * @param {string} [market] - The specific market ticker identifier for which data is requested. This parameter is optional.
11
+ * @returns {Promise<MarketListResponse>} A promise that resolves to the response containing market data.
12
+ * @memberof MarketsClient
13
+ *
14
+ * @example
15
+ * // Fetch data for all markets
16
+ * const allMarketsData = await market.getMarkets();
17
+ *
18
+ * @example
19
+ * // Fetch data for a specific market
20
+ * const specificMarketData = await market.getMarkets('ETH-USDC');
21
+ */
22
+ getMarkets(market?: string): Promise<MarketListResponse>;
23
+ /**
24
+ * Retrieves candlestick data for a specified market.
25
+ *
26
+ * This method fetches historical candlestick (or OHLC - Open, High, Low, Close) data for a given market.
27
+ * The data can be filtered by time range (fromISO and toISO) and resolution.
28
+ *
29
+ * @param {string} market - The market identifier for which candlestick data is to be retrieved.
30
+ * @param {CandlesResolution} resolution - The granularity of the candlestick data (e.g., '1MIN', '5MIN', '1HR').
31
+ * @param {string|null} [fromISO] - The start time for the range of candlestick data in ISO 8601 format. Optional.
32
+ * @param {string|null} [toISO] - The end time for the range of candlestick data in ISO 8601 format. Optional.
33
+ * @param {number|null} [limit] - The maximum number of candlestick data points to retrieve. Optional.
34
+ * @returns {Promise<MarketCandlesResponse>} A promise that resolves to the market candlestick data.
35
+ * @memberof MarketsClient
36
+ *
37
+ * @example
38
+ * const marketCandles = await market.getMarketCandles('BTC-USD', '1HR', '2023-01-01T00:00:00Z', '2023-01-02T00:00:00Z');
39
+ */
40
+ getMarketCandles(market: string, resolution: CandlesResolution, fromISO?: string | null, toISO?: string | null, limit?: number | null): Promise<MarketCandlesResponse>;
41
+ getPerpetualMarketTrades(market: string, limit?: number | null): Promise<TradesResponse>;
42
+ }
43
+ //# sourceMappingURL=markets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markets.d.ts","sourceRoot":"/","sources":["clients/modules/markets.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,EAClB,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,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAK9D;;;;;;;;;;;;;;;;OAgBG;IAEG,gBAAgB,CACpB,MAAM,EAAE,MAAM,EACd,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,MAAM,EAAE,MAAM,EACd,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GACpB,OAAO,CAAC,cAAc,CAAC;CAM3B"}
@@ -0,0 +1,9 @@
1
+ import { Response, ResponseData } from '../lib/axios';
2
+ export default class RestClient {
3
+ readonly host: string;
4
+ readonly apiTimeout: number;
5
+ constructor(host: string, apiTimeout?: number | null);
6
+ get(requestPath: string, params?: NonNullable<unknown>): Promise<ResponseData>;
7
+ post(requestPath: string, params?: NonNullable<unknown>, body?: unknown | null, headers?: NonNullable<unknown>): Promise<Response>;
8
+ }
9
+ //# sourceMappingURL=rest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rest.d.ts","sourceRoot":"/","sources":["clients/modules/rest.ts"],"names":[],"mappings":"AAEA,OAAO,EAAiB,QAAQ,EAAW,YAAY,EAAE,MAAM,cAAc,CAAC;AAC9E,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;gBAEhB,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI;IAK9C,GAAG,CACP,WAAW,EAAE,MAAM,EACnB,MAAM,GAAE,WAAW,CAAC,OAAO,CAAM,GAChC,OAAO,CAAC,YAAY,CAAC;IAMlB,IAAI,CACR,WAAW,EAAE,MAAM,EACnB,MAAM,GAAE,WAAW,CAAC,OAAO,CAAM,EACjC,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,EACrB,OAAO,GAAE,WAAW,CAAC,OAAO,CAAM,GACjC,OAAO,CAAC,QAAQ,CAAC;CAIrB"}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=socket-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"socket-client.d.ts","sourceRoot":"/","sources":["clients/socket-client.ts"],"names":[],"mappings":""}
@@ -0,0 +1,106 @@
1
+ export declare enum CandlesResolution {
2
+ ONE_MINUTE = "1MIN",
3
+ FIVE_MINUTES = "5MINS",
4
+ FIFTEEN_MINUTES = "15MINS",
5
+ THIRTY_MINUTES = "30MINS",
6
+ ONE_HOUR = "1HOUR",
7
+ FOUR_HOURS = "4HOURS",
8
+ ONE_DAY = "1DAY"
9
+ }
10
+ export interface Candle {
11
+ startedAt: string;
12
+ ticker: string;
13
+ resolution: CandlesResolution;
14
+ low: string;
15
+ high: string;
16
+ open: string;
17
+ close: string;
18
+ baseTokenVolume: string;
19
+ usdVolume: string;
20
+ trades: number;
21
+ startingOpenInterest: string;
22
+ id: string;
23
+ }
24
+ export interface MarketCandlesResponse {
25
+ candles: Candle[];
26
+ }
27
+ export interface MarketEntry {
28
+ id: number;
29
+ ticker: string;
30
+ instrumentName: string;
31
+ instrumentType: string;
32
+ underlyingAsset: string;
33
+ quoteAsset: string;
34
+ markPrice: number;
35
+ indexPrice: number;
36
+ isActive: boolean;
37
+ maxLeverage: number;
38
+ volume24H: number;
39
+ priceChange24H: number;
40
+ priceChange24HPercentage: string;
41
+ openInterest: string;
42
+ fundingRate: string;
43
+ priceStep: number;
44
+ amountStep: number;
45
+ minOrderValue: number;
46
+ }
47
+ export interface MarketListResponse {
48
+ [key: string]: MarketEntry;
49
+ }
50
+ export interface CollateralAccount {
51
+ id: number;
52
+ name: string;
53
+ equity: number;
54
+ balance: number;
55
+ marginRatio: string;
56
+ collaterals: Collateral[];
57
+ positions: Position[];
58
+ }
59
+ export interface Collateral {
60
+ collateralAsset: string;
61
+ balance: number;
62
+ availableBalance: number;
63
+ withdrawableBalance: number;
64
+ collateralValue: number;
65
+ }
66
+ export type Status = 'OPEN' | 'CLOSED' | 'LIQUIDATED' | 'FILLED';
67
+ export type Side = 'LONG' | 'SHORT';
68
+ export interface Position {
69
+ id: number;
70
+ symbol: string;
71
+ side: Side;
72
+ size: number;
73
+ price: number;
74
+ orderStatus: Status;
75
+ markPrice: number;
76
+ unrealisedPnl: number;
77
+ realisedPnl: number;
78
+ liquidationPrice: number;
79
+ fundingRate: string;
80
+ date: string;
81
+ }
82
+ export interface CollateralAccountListResponse {
83
+ address: string;
84
+ collateralAccounts: CollateralAccount[];
85
+ }
86
+ export interface CollateralAccountResponse {
87
+ address: string;
88
+ id: number;
89
+ name: string;
90
+ equity: number;
91
+ balance: number;
92
+ marginRatio: string;
93
+ collaterals: Collateral[];
94
+ positions: Position[];
95
+ }
96
+ export type Trade = {
97
+ id: number;
98
+ side: Side;
99
+ size: string;
100
+ price: number;
101
+ date: string;
102
+ };
103
+ export type TradesResponse = {
104
+ trades: Trade[];
105
+ };
106
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["clients/types.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C;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,SAAS,EAAE,QAAQ,EAAE,CAAC;CACvB;AAED,MAAM,MAAM,KAAK,GAAG;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,IAAI,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,EAAE,KAAK,EAAE,CAAC;CACjB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { ApiClient } from './clients/api-client';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@reyaxyz/api-sdk",
3
+ "version": "0.6.3",
4
+ "publishConfig": {
5
+ "access": "public",
6
+ "registry": "https://registry.npmjs.org"
7
+ },
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/Voltz-Protocol/reya-off-chain-monorepo.git"
11
+ },
12
+ "main": "dist/index.js",
13
+ "types": "dist/types",
14
+ "license": "MIT",
15
+ "files": [
16
+ "src/**/*.*",
17
+ "dist/**/*.*",
18
+ "README.md"
19
+ ],
20
+ "scripts": {
21
+ "prebuild": "rm -rf node_modules && rm -rf dist",
22
+ "build": "tsc -p tsconfig.build.json",
23
+ "ts:check-types": "npx tsc --noEmit",
24
+ "ts:circular-check": "dpdm --no-output --no-tree --no-warning --exit-code circular:1 -T src/index.ts",
25
+ "ts:check": "pnpm ts:check-types && pnpm ts:circular-check",
26
+ "lint:check": "eslint '{src,demo,tests}/**/*.{ts,tsx}'",
27
+ "prettier:check": "npx prettier --loglevel silent --check './{src,demo,tests}/**/*.{ts,tsx}'",
28
+ "code-quality:check": "npx concurrently 'pnpm ts:check' 'pnpm prettier:check' 'pnpm lint:check --quiet'",
29
+ "lint:fix": "npx eslint --fix '{src,demo,tests}/**/*.{ts,tsx}'",
30
+ "prettier:fix": "npx prettier --loglevel silent --write './{src,demo,tests}/**/*.{ts,tsx}'",
31
+ "test": "npx jest --silent",
32
+ "test:coverage": "npx jest test --coverage",
33
+ "generate:coverage-badges": "npx istanbul-badges-readme --silent"
34
+ },
35
+ "dependencies": {
36
+ "axios": "^1.6.2"
37
+ },
38
+ "packageManager": "pnpm@8.10.4",
39
+ "gitHead": "12b257e116bed35f8bb69fcd44e5619715228906"
40
+ }
@@ -0,0 +1,43 @@
1
+ import { ServiceConfig, API_TIMEOUT } from './helpers/constants';
2
+ import MarketsClient from './modules/markets';
3
+ import AccountClient from './modules/account';
4
+
5
+ /**
6
+ * @description Client for API
7
+ */
8
+ export class ApiClient {
9
+ public readonly config: ServiceConfig;
10
+ readonly apiTimeout: number;
11
+ readonly _markets: MarketsClient;
12
+ readonly _account: AccountClient;
13
+
14
+ constructor(config: ServiceConfig, apiTimeout?: number) {
15
+ this.config = config;
16
+ this.apiTimeout = apiTimeout ?? API_TIMEOUT;
17
+
18
+ this._markets = new MarketsClient(config.restEndpoint);
19
+ this._account = new AccountClient(config.restEndpoint);
20
+ }
21
+
22
+ /**
23
+ * Provides access to the MarketsClient instance.
24
+ * This getter allows for interacting with market-related API functionalities.
25
+ *
26
+ * @returns {MarketsClient} An instance of MarketsClient for market-related operations.
27
+ * @memberof ApiClient
28
+ */
29
+ get markets(): MarketsClient {
30
+ return this._markets;
31
+ }
32
+
33
+ /**
34
+ * Provides access to the AccountClient instance.
35
+ * This getter allows for interacting with account-related API functionalities.
36
+ *
37
+ * @returns {AccountClient} An instance of AccountClient for account-related operations.
38
+ * @memberof ApiClient
39
+ */
40
+ get account(): AccountClient {
41
+ return this._account;
42
+ }
43
+ }
@@ -0,0 +1,11 @@
1
+ export const API_TIMEOUT: number = 2500;
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
+ }
11
+ }
@@ -0,0 +1,17 @@
1
+ export function generateQueryPath(
2
+ url: string,
3
+ params: NonNullable<unknown>,
4
+ ): string {
5
+ const definedEntries = Object.entries(params).filter(
6
+ ([, value]: [string, unknown]) => value !== undefined,
7
+ );
8
+
9
+ if (!definedEntries.length) {
10
+ return url;
11
+ }
12
+
13
+ const paramsString = definedEntries
14
+ .map(([key, value]: [string, unknown]) => `${key}=${value}`)
15
+ .join('&');
16
+ return `${url}?${paramsString}`;
17
+ }
@@ -0,0 +1,34 @@
1
+ import axios, { AxiosRequestConfig } from 'axios';
2
+
3
+ export enum RequestMethod {
4
+ POST = 'POST',
5
+ PUT = 'PUT',
6
+ GET = 'GET',
7
+ DELETE = 'DELETE',
8
+ }
9
+
10
+ export type ResponseData = never;
11
+
12
+ export interface Response {
13
+ status: number;
14
+ data: ResponseData;
15
+ headers: NonNullable<unknown>;
16
+ }
17
+
18
+ async function axiosRequest(options: AxiosRequestConfig): Promise<Response> {
19
+ return axios(options);
20
+ }
21
+
22
+ export function request(
23
+ url: string,
24
+ method: RequestMethod = RequestMethod.GET,
25
+ body?: unknown | null,
26
+ headers: NonNullable<unknown> = {},
27
+ ): Promise<Response> {
28
+ return axiosRequest({
29
+ url,
30
+ method,
31
+ data: body,
32
+ headers,
33
+ });
34
+ }
@@ -0,0 +1,63 @@
1
+ import {
2
+ CollateralAccountListResponse,
3
+ CollateralAccountResponse,
4
+ } from '../types';
5
+ import RestClient from './rest';
6
+
7
+ export default class AccountClient extends RestClient {
8
+ /**
9
+ * Asynchronously retrieves a list of collateral accounts associated with a specific address.
10
+ *
11
+ * This method makes a request to the API endpoint to fetch collateral account data. The data is filtered
12
+ * based on the provided Ethereum address. An optional limit can be specified to control the number of
13
+ * collateral accounts returned in the response.
14
+ *
15
+ * @param {string} address - The Ethereum address for which collateral account data is being requested.
16
+ * @param {number} [limit] - An optional limit on the number of collateral accounts to retrieve. If not specified,
17
+ * all available collateral accounts for the address will be returned.
18
+ * @returns {Promise<CollateralAccountListResponse>} A promise that resolves to the response containing the collateral
19
+ * account data.
20
+ * @memberof account
21
+ *
22
+ * @example
23
+ * // Fetch all collateral accounts for a specific address
24
+ * const accounts = await account.getCollateralAccounts('0x123...');
25
+ *
26
+ * @example
27
+ * // Fetch a limited number of collateral accounts for a specific address
28
+ * const limitedAccounts = await account.getCollateralAccounts('0x123...', 5);
29
+ */
30
+
31
+ async getCollateralAccounts(
32
+ address: string,
33
+ limit?: number,
34
+ ): Promise<CollateralAccountListResponse> {
35
+ const uri = `/api/accounts/${address}`;
36
+ return this.get(uri, { limit });
37
+ }
38
+
39
+ /**
40
+ * Asynchronously retrieves details of a specific collateral account for a given Ethereum address.
41
+ *
42
+ * This method sends a request to the API to obtain detailed information about a specific collateral account
43
+ * associated with the provided Ethereum address. The account is identified using the collateral account number.
44
+ *
45
+ * @param {string} address - The Ethereum address associated with the collateral account.
46
+ * @param {number} collateralAccountNumber - The number identifying the specific collateral account.
47
+ * @returns {Promise<CollateralAccountResponse>} A promise that resolves to the response containing the detailed
48
+ * information of the specified collateral account.
49
+ * @memberof account
50
+ *
51
+ * @example
52
+ * // Fetch details of a specific collateral account by its number for a given address
53
+ * const accountDetails = await account.getCollateralAccount('0x123...', 1);
54
+ */
55
+
56
+ async getCollateralAccount(
57
+ address: string,
58
+ collateralAccountNumber: number,
59
+ ): Promise<CollateralAccountResponse> {
60
+ const uri = `/api/accounts/${address}/collateralAccount/${collateralAccountNumber}`;
61
+ return this.get(uri);
62
+ }
63
+ }
@@ -0,0 +1,77 @@
1
+ import {
2
+ CandlesResolution,
3
+ MarketCandlesResponse,
4
+ MarketListResponse,
5
+ TradesResponse,
6
+ } from '../types';
7
+ import RestClient from './rest';
8
+
9
+ export default class MarketsClient extends RestClient {
10
+ /**
11
+ * Asynchronously retrieves market data from the API.
12
+ *
13
+ * This method makes a request to the API to fetch data for markets. If a specific market is provided as a parameter,
14
+ * it fetches data for that particular market; otherwise, it fetches data for all available markets.
15
+ *
16
+ * @param {string} [market] - The specific market ticker identifier for which data is requested. This parameter is optional.
17
+ * @returns {Promise<MarketListResponse>} A promise that resolves to the response containing market data.
18
+ * @memberof MarketsClient
19
+ *
20
+ * @example
21
+ * // Fetch data for all markets
22
+ * const allMarketsData = await market.getMarkets();
23
+ *
24
+ * @example
25
+ * // Fetch data for a specific market
26
+ * const specificMarketData = await market.getMarkets('ETH-USDC');
27
+ */
28
+
29
+ async getMarkets(market?: string): Promise<MarketListResponse> {
30
+ const uri = '/api/markets';
31
+ return this.get(uri, { ticker: market });
32
+ }
33
+
34
+ /**
35
+ * Retrieves candlestick data for a specified market.
36
+ *
37
+ * This method fetches historical candlestick (or OHLC - Open, High, Low, Close) data for a given market.
38
+ * The data can be filtered by time range (fromISO and toISO) and resolution.
39
+ *
40
+ * @param {string} market - The market identifier for which candlestick data is to be retrieved.
41
+ * @param {CandlesResolution} resolution - The granularity of the candlestick data (e.g., '1MIN', '5MIN', '1HR').
42
+ * @param {string|null} [fromISO] - The start time for the range of candlestick data in ISO 8601 format. Optional.
43
+ * @param {string|null} [toISO] - The end time for the range of candlestick data in ISO 8601 format. Optional.
44
+ * @param {number|null} [limit] - The maximum number of candlestick data points to retrieve. Optional.
45
+ * @returns {Promise<MarketCandlesResponse>} A promise that resolves to the market candlestick data.
46
+ * @memberof MarketsClient
47
+ *
48
+ * @example
49
+ * const marketCandles = await market.getMarketCandles('BTC-USD', '1HR', '2023-01-01T00:00:00Z', '2023-01-02T00:00:00Z');
50
+ */
51
+
52
+ async getMarketCandles(
53
+ market: string,
54
+ resolution: CandlesResolution,
55
+ fromISO?: string | null,
56
+ toISO?: string | null,
57
+ limit?: number | null,
58
+ ): Promise<MarketCandlesResponse> {
59
+ const uri = `/api/markets/candles/${market}`;
60
+ return this.get(uri, {
61
+ resolution,
62
+ fromISO,
63
+ toISO,
64
+ limit,
65
+ });
66
+ }
67
+
68
+ async getPerpetualMarketTrades(
69
+ market: string,
70
+ limit?: number | null,
71
+ ): Promise<TradesResponse> {
72
+ const uri = `/api/trades/${market}`;
73
+ return this.get(uri, {
74
+ limit,
75
+ });
76
+ }
77
+ }
@@ -0,0 +1,31 @@
1
+ import { API_TIMEOUT } from '../helpers/constants';
2
+ import { generateQueryPath } from '../helpers/query-helper';
3
+ import { RequestMethod, Response, request, ResponseData } from '../lib/axios';
4
+ export default class RestClient {
5
+ readonly host: string;
6
+ readonly apiTimeout: number;
7
+
8
+ constructor(host: string, apiTimeout?: number | null) {
9
+ this.host = host;
10
+ this.apiTimeout = apiTimeout || API_TIMEOUT;
11
+ }
12
+
13
+ async get(
14
+ requestPath: string,
15
+ params: NonNullable<unknown> = {},
16
+ ): Promise<ResponseData> {
17
+ const url = `${this.host}${generateQueryPath(requestPath, params)}`;
18
+ const response = await request(url);
19
+ return response.data;
20
+ }
21
+
22
+ async post(
23
+ requestPath: string,
24
+ params: NonNullable<unknown> = {},
25
+ body?: unknown | null,
26
+ headers: NonNullable<unknown> = {},
27
+ ): Promise<Response> {
28
+ const url = `${this.host}${generateQueryPath(requestPath, params)}`;
29
+ return request(url, RequestMethod.POST, body, headers);
30
+ }
31
+ }
File without changes