@reyaxyz/api-sdk 0.26.0 → 0.28.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.
Files changed (95) hide show
  1. package/dist/clients/api-client.js +19 -0
  2. package/dist/clients/api-client.js.map +1 -1
  3. package/dist/clients/modules/{account.js → account/index.js} +2 -2
  4. package/dist/clients/modules/account/index.js.map +1 -0
  5. package/dist/clients/{helpers/trade.simulation.types.js → modules/account/types.js} +1 -1
  6. package/dist/clients/modules/account/types.js.map +1 -0
  7. package/dist/clients/modules/{lp.js → lp/index.js} +2 -2
  8. package/dist/clients/modules/lp/index.js.map +1 -0
  9. package/dist/clients/modules/lp/types.js +13 -0
  10. package/dist/clients/modules/lp/types.js.map +1 -0
  11. package/dist/clients/modules/{markets.js → markets/index.js} +2 -2
  12. package/dist/clients/modules/markets/index.js.map +1 -0
  13. package/dist/clients/modules/markets/types.js +3 -0
  14. package/dist/clients/modules/markets/types.js.map +1 -0
  15. package/dist/clients/modules/{rest.js → rest/index.js} +4 -4
  16. package/dist/clients/modules/rest/index.js.map +1 -0
  17. package/dist/clients/modules/tokens/index.js +75 -0
  18. package/dist/clients/modules/tokens/index.js.map +1 -0
  19. package/dist/clients/modules/tokens/types.js +3 -0
  20. package/dist/clients/modules/tokens/types.js.map +1 -0
  21. package/dist/clients/modules/{trade.simulation.js → trade.simulation/index.js} +10 -10
  22. package/dist/clients/modules/trade.simulation/index.js.map +1 -0
  23. package/dist/clients/modules/trade.simulation/types.js +3 -0
  24. package/dist/clients/modules/trade.simulation/types.js.map +1 -0
  25. package/dist/clients/types.js +4 -36
  26. package/dist/clients/types.js.map +1 -1
  27. package/dist/index.js +0 -2
  28. package/dist/index.js.map +1 -1
  29. package/dist/types/clients/api-client.d.ts +13 -0
  30. package/dist/types/clients/api-client.d.ts.map +1 -1
  31. package/dist/types/clients/modules/{account.d.ts → account/index.d.ts} +4 -4
  32. package/dist/types/clients/modules/account/index.d.ts.map +1 -0
  33. package/dist/types/clients/modules/account/types.d.ts +47 -0
  34. package/dist/types/clients/modules/account/types.d.ts.map +1 -0
  35. package/dist/types/clients/modules/{lp.d.ts → lp/index.d.ts} +4 -3
  36. package/dist/types/clients/modules/lp/index.d.ts.map +1 -0
  37. package/dist/types/clients/modules/lp/types.d.ts +46 -0
  38. package/dist/types/clients/modules/lp/types.d.ts.map +1 -0
  39. package/dist/types/clients/modules/{markets.d.ts → markets/index.d.ts} +3 -3
  40. package/dist/types/clients/modules/markets/index.d.ts.map +1 -0
  41. package/dist/types/clients/modules/markets/types.d.ts +23 -0
  42. package/dist/types/clients/modules/markets/types.d.ts.map +1 -0
  43. package/dist/types/clients/modules/{rest.d.ts → rest/index.d.ts} +2 -2
  44. package/dist/types/clients/modules/rest/index.d.ts.map +1 -0
  45. package/dist/types/clients/modules/tokens/index.d.ts +6 -0
  46. package/dist/types/clients/modules/tokens/index.d.ts.map +1 -0
  47. package/dist/types/clients/modules/tokens/types.d.ts +8 -0
  48. package/dist/types/clients/modules/tokens/types.d.ts.map +1 -0
  49. package/dist/types/clients/modules/{trade.simulation.d.ts → trade.simulation/index.d.ts} +3 -3
  50. package/dist/types/clients/modules/trade.simulation/index.d.ts.map +1 -0
  51. package/dist/types/clients/modules/trade.simulation/types.d.ts +19 -0
  52. package/dist/types/clients/modules/trade.simulation/types.d.ts.map +1 -0
  53. package/dist/types/clients/types.d.ts +1 -300
  54. package/dist/types/clients/types.d.ts.map +1 -1
  55. package/dist/types/index.d.ts +0 -2
  56. package/dist/types/index.d.ts.map +1 -1
  57. package/package.json +6 -7
  58. package/src/clients/api-client.ts +17 -0
  59. package/src/clients/modules/{account.ts → account/index.ts} +3 -3
  60. package/src/clients/modules/account/types.ts +74 -0
  61. package/src/clients/modules/{lp.ts → lp/index.ts} +5 -3
  62. package/src/clients/modules/lp/types.ts +62 -0
  63. package/src/clients/modules/{markets.ts → markets/index.ts} +2 -2
  64. package/src/clients/modules/markets/types.ts +33 -0
  65. package/src/clients/modules/{rest.ts → rest/index.ts} +8 -3
  66. package/src/clients/modules/tokens/index.ts +11 -0
  67. package/src/clients/modules/tokens/types.ts +9 -0
  68. package/src/clients/modules/{trade.simulation.ts → trade.simulation/index.ts} +3 -4
  69. package/src/clients/modules/trade.simulation/types.ts +21 -0
  70. package/src/clients/types.ts +16 -388
  71. package/src/index.ts +0 -2
  72. package/dist/clients/helpers/exposure.calculator.js +0 -448
  73. package/dist/clients/helpers/exposure.calculator.js.map +0 -1
  74. package/dist/clients/helpers/number.js +0 -13
  75. package/dist/clients/helpers/number.js.map +0 -1
  76. package/dist/clients/helpers/trade.simulation.types.js.map +0 -1
  77. package/dist/clients/modules/account.js.map +0 -1
  78. package/dist/clients/modules/lp.js.map +0 -1
  79. package/dist/clients/modules/markets.js.map +0 -1
  80. package/dist/clients/modules/rest.js.map +0 -1
  81. package/dist/clients/modules/trade.simulation.js.map +0 -1
  82. package/dist/types/clients/helpers/exposure.calculator.d.ts +0 -58
  83. package/dist/types/clients/helpers/exposure.calculator.d.ts.map +0 -1
  84. package/dist/types/clients/helpers/number.d.ts +0 -3
  85. package/dist/types/clients/helpers/number.d.ts.map +0 -1
  86. package/dist/types/clients/helpers/trade.simulation.types.d.ts +0 -113
  87. package/dist/types/clients/helpers/trade.simulation.types.d.ts.map +0 -1
  88. package/dist/types/clients/modules/account.d.ts.map +0 -1
  89. package/dist/types/clients/modules/lp.d.ts.map +0 -1
  90. package/dist/types/clients/modules/markets.d.ts.map +0 -1
  91. package/dist/types/clients/modules/rest.d.ts.map +0 -1
  92. package/dist/types/clients/modules/trade.simulation.d.ts.map +0 -1
  93. package/src/clients/helpers/exposure.calculator.ts +0 -799
  94. package/src/clients/helpers/number.ts +0 -8
  95. package/src/clients/helpers/trade.simulation.types.ts +0 -125
@@ -8,6 +8,7 @@ import MarketsClient from './modules/markets';
8
8
  import AccountClient from './modules/account';
9
9
  import TradeSimulationClient from './modules/trade.simulation';
10
10
  import LpClient from './modules/lp';
11
+ import TokensClient from './modules/tokens';
11
12
 
12
13
  /**
13
14
  * @description Client for API
@@ -23,6 +24,7 @@ export class ApiClient {
23
24
  private readonly _account: AccountClient;
24
25
  private readonly _lp: LpClient;
25
26
  private readonly _trade_simulation: TradeSimulationClient;
27
+ private readonly _tokens: TokensClient;
26
28
 
27
29
  private constructor(config: ServiceConfig) {
28
30
  this.apiEndpoint = config.production ? API_PRODUCTION : API_TESTNET;
@@ -31,6 +33,7 @@ export class ApiClient {
31
33
  this._account = new AccountClient(this.apiEndpoint);
32
34
  this._lp = new LpClient(this.apiEndpoint);
33
35
  this._trade_simulation = new TradeSimulationClient(this._account);
36
+ this._tokens = new TokensClient(this.apiEndpoint);
34
37
  }
35
38
 
36
39
  public static configure(config: ServiceConfig): void {
@@ -100,4 +103,18 @@ export class ApiClient {
100
103
  public static get lp(): LpClient {
101
104
  return ApiClient.getInstance()._lp;
102
105
  }
106
+
107
+ /**
108
+ * Gets the current instance of the TokensClient from the ApiClient.
109
+ *
110
+ * This static getter allows access to the Tokensclient instance managed within the ApiClient's singleton instance. It is a convenience method for retrieving the TokensClient directly, bypassing the need to manually access the internal `_tokens` property of the ApiClient instance.
111
+ *
112
+ * @returns {TokensClient} The TokensClient instance currently held by the ApiClient.
113
+ * @example
114
+ * // Assuming ApiClient and TokensClient are properly set up
115
+ * const tokensClient = ApiClient.tokens;
116
+ */
117
+ public static get tokens(): TokensClient {
118
+ return ApiClient.getInstance()._tokens;
119
+ }
103
120
  }
@@ -14,9 +14,9 @@ import {
14
14
  GetPositionsHistoryForMarginAccountParams,
15
15
  GetPositionsHistoryForMarginAccountResult,
16
16
  GetTransactionSimulationInitialDataParams,
17
- } from '../types';
18
- import RestClient from './rest';
19
- import { TradeSimulationState } from '../helpers/trade.simulation.types';
17
+ } from './types';
18
+ import RestClient from '../rest';
19
+ import { TradeSimulationState } from '@reyaxyz/common';
20
20
 
21
21
  export default class AccountClient extends RestClient {
22
22
  /**
@@ -0,0 +1,74 @@
1
+ import {
2
+ MarginAccountEntity,
3
+ MarginAccountTransactionHistoryEntity,
4
+ MarketEntity,
5
+ PositionEntity,
6
+ PositionHistoryEntity,
7
+ } from '@reyaxyz/common';
8
+
9
+ export type GetMarginAccountsParams = {
10
+ address: string;
11
+ limit?: number;
12
+ };
13
+
14
+ export type GetMarginAccountParams = {
15
+ address: string;
16
+ marginAccountId: MarginAccountEntity['id'];
17
+ };
18
+
19
+ export type GetPositionsForMarginAccountParams = {
20
+ address: string;
21
+ marginAccountId: MarginAccountEntity['id'];
22
+ limit?: number;
23
+ };
24
+
25
+ export type GetMarginAccountsResult = MarginAccountEntity[];
26
+
27
+ export type GetMarginAccountResult = MarginAccountEntity;
28
+
29
+ // ---- Transaction History
30
+ export type GetMarginAccountTransactionHistoryParams = {
31
+ marginAccountId: MarginAccountEntity['id'];
32
+ limit?: number;
33
+ };
34
+
35
+ export type GetMarginAccountTransactionHistoryResult =
36
+ MarginAccountTransactionHistoryEntity[];
37
+ // -- Max Order Size --
38
+
39
+ export type GetMaxOrderSizeAvailableParams = {
40
+ marketId: MarketEntity['id'];
41
+ marginAccountId: MarginAccountEntity['id'];
42
+ direction: 'long' | 'short';
43
+ };
44
+
45
+ export type GetMaxOrderSizeAvailableResult = number;
46
+
47
+ // --- Max Withdraw Balance for Margin Account ---
48
+ export type GetMaxWithdrawBalanceForAccountParams = {
49
+ marginAccountId: MarginAccountEntity['id'];
50
+ tokenAddress: string;
51
+ };
52
+
53
+ export type GetMaxWithdrawBalanceForAccountResult = number;
54
+
55
+ export type GetPositionsForMarginAccountResult = {
56
+ positions: PositionEntity[];
57
+ totalUnrealizedPNL: number;
58
+ };
59
+
60
+ // --- Position History ---
61
+
62
+ export type GetPositionsHistoryForMarginAccountParams = {
63
+ address: string;
64
+ marginAccountId: MarginAccountEntity['id'];
65
+ limit?: number;
66
+ };
67
+ export type GetPositionsHistoryForMarginAccountResult = PositionHistoryEntity[];
68
+
69
+ // ---- Transaction Simulation ----
70
+
71
+ export type GetTransactionSimulationInitialDataParams = {
72
+ marketId: MarketEntity['id'];
73
+ marginAccountId: MarginAccountEntity['id'];
74
+ };
@@ -9,11 +9,13 @@ import {
9
9
  GetLpPoolWithdrawBalanceParams,
10
10
  GetLpPoolWithdrawBalanceResult,
11
11
  GetLpPoolBalanceChartDataParams,
12
- GetLpPoolBalanceChartDataResult,
13
12
  GetLpPoolPerformanceChartDataParams,
13
+ } from './types';
14
+ import {
14
15
  GetLpPoolPerformanceChartDataResult,
15
- } from '../types';
16
- import RestClient from './rest';
16
+ GetLpPoolBalanceChartDataResult,
17
+ } from '@reyaxyz/common';
18
+ import RestClient from '../rest';
17
19
 
18
20
  export default class LpClient extends RestClient {
19
21
  async getLpPools(): Promise<GetLpPoolsResult> {
@@ -0,0 +1,62 @@
1
+ import {
2
+ LpPoolEntity,
3
+ LpPositionEntity,
4
+ LpTransactionHistoryEntity,
5
+ BalanceGranularity,
6
+ } from '@reyaxyz/common';
7
+
8
+ export type GetLpPoolsResult = LpPoolEntity[];
9
+
10
+ export type GetLpPoolResult = LpPoolEntity;
11
+
12
+ export type GetLpPoolParams = {
13
+ id: LpPoolEntity['id'];
14
+ };
15
+
16
+ export type GetLpPoolTransactionHistoryResult = LpTransactionHistoryEntity[];
17
+
18
+ export type GetLpPositionsParams = {
19
+ id: LpPoolEntity['id'];
20
+ address: string; // wallet address
21
+ };
22
+
23
+ export type GetLpPositionsResult = LpPositionEntity[];
24
+
25
+ export type GetLpPoolWithdrawBalanceParams = {
26
+ id: LpPoolEntity['id'];
27
+ address: string; // wallet address
28
+ };
29
+
30
+ export type GetLpPoolWithdrawBalanceResult = number;
31
+
32
+ export type GetLpPoolTransactionHistoryParams = {
33
+ id: LpPoolEntity['id'];
34
+ address: string; // wallet address
35
+ limit?: number;
36
+ };
37
+
38
+ export type GetLpPoolBalanceChartDataParams = {
39
+ poolId: LpPoolEntity['id'];
40
+ filters: {
41
+ timeframeMs: number;
42
+ granularity: BalanceGranularity;
43
+ };
44
+ };
45
+
46
+ export enum PerformanceGranularity {
47
+ ONE_MINUTE = 60 * 1000,
48
+ ONE_HOUR = 60 * 60 * 1000,
49
+ ONE_DAY = 24 * 60 * 60 * 1000,
50
+ ONE_WEEK = 7 * 24 * 60 * 60 * 1000,
51
+ ONE_MONTH = 30 * 24 * 60 * 60 * 1000,
52
+ ONE_YEAR = 365 * 24 * 60 * 60 * 1000,
53
+ }
54
+
55
+ export type GetLpPoolPerformanceChartDataParams = {
56
+ poolId: LpPoolEntity['id'];
57
+ address: string; // wallet address
58
+ filters: {
59
+ timeframeMs: number;
60
+ granularity: PerformanceGranularity;
61
+ };
62
+ };
@@ -6,8 +6,8 @@ import {
6
6
  GetMarketTradingHistoryParams,
7
7
  GetTradingHistoryResult,
8
8
  MarketCandlesResponse,
9
- } from '../types';
10
- import RestClient from './rest';
9
+ } from './types';
10
+ import RestClient from '../rest';
11
11
 
12
12
  export default class MarketsClient extends RestClient {
13
13
  /**
@@ -0,0 +1,33 @@
1
+ import {
2
+ CandlesResolution,
3
+ MarketEntity,
4
+ TradingHistoryEntity,
5
+ Candle,
6
+ } from '@reyaxyz/common';
7
+
8
+ export type GetMarketsResult = MarketEntity[];
9
+
10
+ export type GetMarketResult = MarketEntity;
11
+
12
+ export type GetMarketParams = {
13
+ id: MarketEntity['id'];
14
+ };
15
+
16
+ export type GetCandlesParams = {
17
+ marketId: MarketEntity['id'];
18
+ resolution: CandlesResolution;
19
+ fromISO?: string | null;
20
+ toISO?: string | null;
21
+ limit?: number | null;
22
+ };
23
+
24
+ export type GetMarketTradingHistoryParams = {
25
+ marketId: number;
26
+ limit?: number;
27
+ fromTimestampMillisecondsUTC?: number;
28
+ };
29
+ export type GetTradingHistoryResult = TradingHistoryEntity[];
30
+
31
+ export interface MarketCandlesResponse {
32
+ candles: Candle[];
33
+ }
@@ -1,6 +1,11 @@
1
- import { API_TIMEOUT } from '../helpers/constants';
2
- import { generateQueryPath } from '../helpers/query-helper';
3
- import { RequestMethod, Response, request, ResponseData } from '../lib/axios';
1
+ import { API_TIMEOUT } from '../../helpers/constants';
2
+ import { generateQueryPath } from '../../helpers/query-helper';
3
+ import {
4
+ RequestMethod,
5
+ Response,
6
+ request,
7
+ ResponseData,
8
+ } from '../../lib/axios';
4
9
  export default class RestClient {
5
10
  readonly host: string;
6
11
  readonly apiTimeout: number;
@@ -0,0 +1,11 @@
1
+ import { GetAllowedTokensParams, GetAllowedTokenResult } from './types';
2
+ import RestClient from '../rest';
3
+
4
+ export default class TokensClient extends RestClient {
5
+ async getAllowedTokens(
6
+ params: GetAllowedTokensParams,
7
+ ): Promise<GetAllowedTokenResult> {
8
+ const uri = `/api/tokens/${params.chainId}`;
9
+ return this.get(uri);
10
+ }
11
+ }
@@ -0,0 +1,9 @@
1
+ import { SupportedChainId, TokenEntity } from '@reyaxyz/common';
2
+
3
+ export type GetAllowedTokensParams = {
4
+ chainId: SupportedChainId;
5
+ };
6
+
7
+ export type GetAllowedTokenResult = {
8
+ tokens: TokenEntity[];
9
+ };
@@ -2,10 +2,9 @@ import {
2
2
  SimulateTradeEntity,
3
3
  TradeSimulationLoadDataParams,
4
4
  TradeSimulationSimulateParams,
5
- } from '../types';
6
- import AccountClient from './account';
7
- import { TradeSimulationState } from '../helpers/trade.simulation.types';
8
- import { ExposureCommand } from '../helpers/exposure.calculator';
5
+ } from './types';
6
+ import AccountClient from '../account';
7
+ import { ExposureCommand, TradeSimulationState } from '@reyaxyz/common';
9
8
  import BigNumber from 'bignumber.js';
10
9
 
11
10
  export default class TradeSimulationClient {
@@ -0,0 +1,21 @@
1
+ import { MarginAccountEntity, MarketEntity } from '@reyaxyz/common';
2
+
3
+ export type TradeSimulationLoadDataParams = {
4
+ marketId: MarketEntity['id'];
5
+ marginAccountId: MarginAccountEntity['id'];
6
+ };
7
+
8
+ export type TradeSimulationSimulateParams = {
9
+ amount: number; // position size, + for long | - for short
10
+ };
11
+
12
+ export type SimulateTradeEntity = {
13
+ liquidationPrice: number;
14
+ fees: number;
15
+ estimatedPrice: number;
16
+ estimatedSlippage: number;
17
+ imr: number;
18
+ impliedLeverage: number;
19
+ marginRatio: MarginAccountEntity['marginRatioPercentage'];
20
+ marginRatioHealth: MarginAccountEntity['marginRatioHealth'];
21
+ };