@reyaxyz/api-sdk 0.13.0 → 0.14.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.
@@ -18,6 +18,7 @@ exports.ApiClient = void 0;
18
18
  var constants_1 = require("./helpers/constants");
19
19
  var markets_1 = __importDefault(require("./modules/markets"));
20
20
  var account_1 = __importDefault(require("./modules/account"));
21
+ var trade_simulation_1 = __importDefault(require("./modules/trade.simulation"));
21
22
  /**
22
23
  * @description Client for API
23
24
  */
@@ -27,6 +28,7 @@ var ApiClient = /** @class */ (function () {
27
28
  ApiClient.config = __assign(__assign({}, ApiClient.config), config);
28
29
  this._markets = new markets_1.default(this.apiEndpoint);
29
30
  this._account = new account_1.default(this.apiEndpoint);
31
+ this._trade_simulation = new trade_simulation_1.default();
30
32
  }
31
33
  ApiClient.configure = function (config) {
32
34
  ApiClient.config = config;
@@ -66,6 +68,26 @@ var ApiClient = /** @class */ (function () {
66
68
  enumerable: false,
67
69
  configurable: true
68
70
  });
71
+ Object.defineProperty(ApiClient, "tradeSimulation", {
72
+ /**
73
+ * Provides access to the TradeSimulationClient instance.
74
+ * This getter allows for interacting with trade simulation functionalities.
75
+ * It ensures a singleton pattern by fetching the instance from the ApiClient's
76
+ * private `_trade_simulation` property, ensuring that trade simulation operations
77
+ * use a consistent client configuration and state.
78
+ *
79
+ * @returns {TradeSimulationClient} An instance of TradeSimulationClient for trade simulation operations.
80
+ * @memberof ApiClient
81
+ * @example
82
+ * // Access the trade simulation client from the ApiClient
83
+ * const tradeSimulationClient = ApiClient.tradeSimulation;
84
+ */
85
+ get: function () {
86
+ return ApiClient.getInstance()._trade_simulation;
87
+ },
88
+ enumerable: false,
89
+ configurable: true
90
+ });
69
91
  ApiClient.config = {
70
92
  production: true, // default value
71
93
  timeout: constants_1.API_TIMEOUT, // default value, e.g., 5000 milliseconds
@@ -1 +1 @@
1
- {"version":3,"file":"api-client.js","sourceRoot":"/","sources":["clients/api-client.ts"],"names":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\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
+ {"version":3,"file":"api-client.js","sourceRoot":"/","sources":["clients/api-client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,iDAK6B;AAC7B,8DAA8C;AAC9C,8DAA8C;AAC9C,gFAA+D;AAE/D;;GAEG;AACH;IAWE,mBAAoB,MAAqB;QACvC,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,0BAAc,CAAC,CAAC,CAAC,uBAAW,CAAC;QACpE,SAAS,C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} from './helpers/constants';\nimport MarketsClient from './modules/markets';\nimport AccountClient from './modules/account';\nimport TradeSimulationClient from './modules/trade.simulation';\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 private readonly _trade_simulation: TradeSimulationClient;\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 this._trade_simulation = new TradeSimulationClient();\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 /**\n * Provides access to the TradeSimulationClient instance.\n * This getter allows for interacting with trade simulation functionalities.\n * It ensures a singleton pattern by fetching the instance from the ApiClient's\n * private `_trade_simulation` property, ensuring that trade simulation operations\n * use a consistent client configuration and state.\n *\n * @returns {TradeSimulationClient} An instance of TradeSimulationClient for trade simulation operations.\n * @memberof ApiClient\n * @example\n * // Access the trade simulation client from the ApiClient\n * const tradeSimulationClient = ApiClient.tradeSimulation;\n */\n\n public static get tradeSimulation(): TradeSimulationClient {\n return ApiClient.getInstance()._trade_simulation;\n }\n}\n"]}
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ 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;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ // The maximum is inclusive and the minimum is inclusive
40
+ function getRandomIntInclusive(min, max) {
41
+ min = Math.ceil(min);
42
+ max = Math.floor(max);
43
+ return Math.floor(Math.random() * (max - min + 1) + min);
44
+ }
45
+ var randomHealth = function () {
46
+ return Math.random() * 100 > 50
47
+ ? 'healthy'
48
+ : Math.random() * 100 > 50
49
+ ? 'danger'
50
+ : 'warning';
51
+ };
52
+ function getRandomFloat(min, max) {
53
+ return Math.random() * (max - min) + min;
54
+ }
55
+ var TradeSimulationClient = /** @class */ (function () {
56
+ function TradeSimulationClient() {
57
+ this.marketId = null;
58
+ this.accountId = null;
59
+ this.loadedData = null;
60
+ }
61
+ // Method to asynchronously load data based on marketId and accountId
62
+ TradeSimulationClient.prototype.loadData = function (params) {
63
+ return __awaiter(this, void 0, void 0, function () {
64
+ var marketData;
65
+ return __generator(this, function (_a) {
66
+ switch (_a.label) {
67
+ case 0:
68
+ this.marketId = params.market_id;
69
+ this.accountId = params.marginAccountId;
70
+ return [4 /*yield*/, this.fetchMarketData(this.marketId, this.accountId)];
71
+ case 1:
72
+ marketData = _a.sent();
73
+ // Store the loaded data
74
+ this.loadedData = { marketData: marketData };
75
+ return [2 /*return*/];
76
+ }
77
+ });
78
+ });
79
+ };
80
+ TradeSimulationClient.prototype.fetchMarketData = function (marketId, accountId) {
81
+ return __awaiter(this, void 0, void 0, function () {
82
+ return __generator(this, function (_a) {
83
+ switch (_a.label) {
84
+ case 0: return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 500); })];
85
+ case 1:
86
+ _a.sent(); // wait for 500ms
87
+ return [2 /*return*/, 1 + marketId + accountId];
88
+ }
89
+ });
90
+ });
91
+ };
92
+ // Synchronous method to simulate operations based on an amount
93
+ TradeSimulationClient.prototype.simulate = function (params) {
94
+ if (!this.loadedData) {
95
+ throw new Error('Data not loaded. Call loadData() first.');
96
+ }
97
+ // @todo perform simulation
98
+ return {
99
+ estimatedPrice: getRandomIntInclusive(1000, 100000) + params.amount,
100
+ estimatedSlippage: getRandomFloat(0.00001, 0.05),
101
+ fees: getRandomIntInclusive(1000, 100000),
102
+ impliedLeverage: getRandomIntInclusive(20, 50),
103
+ imr: getRandomIntInclusive(1000, 100000),
104
+ liquidationPrice: getRandomIntInclusive(1000, 100000),
105
+ marginRatio: getRandomIntInclusive(0, 100),
106
+ marginRatioHealth: randomHealth(),
107
+ };
108
+ };
109
+ return TradeSimulationClient;
110
+ }());
111
+ exports.default = TradeSimulationClient;
112
+ //# sourceMappingURL=trade.simulation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trade.simulation.js","sourceRoot":"/","sources":["clients/modules/trade.simulation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,wDAAwD;AACxD,SAAS,qBAAqB,CAAC,GAAW,EAAE,GAAW;IACrD,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACrB,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACtB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC;AAC3D,CAAC;AAED,IAAM,YAAY,GAAG;IACnB,OAAO,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,GAAG,EAAE;QAC7B,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,IAAI,CAAC,MAAM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AC,IAAI,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM;YACnE,iBAAiB,EAAE,cAAc,CAAC,OAAO,EAAE,IAAI,CAAC;YAChD,IAAI,EAAE,qBAAqB,CAAC,IAAI,EAAE,MAAM,CAAC;YACzC,eAAe,EAAE,qBAAqB,CAAC,EAAE,EAAE,EAAE,CAAC;YAC9C,GAAG,EAAE,qBAAqB,CAAC,IAAI,EAAE,MAAM,CAAC;YACxC,gBAAgB,EAAE,qBAAqB,CAAC,IAAI,EAAE,MAAM,CAAC;YACrD,WAAW,EAAE,qBAAqB,CAAC,CAAC,EAAE,GAAG,CAAC;YAC1C,iBAAiB,EAAE,YAAY,EAAE;SACX,CAAC;IAC3B,CAAC;IACH,4BAAC;AAAD,CAAC,AA/CD,IA+CC","sourcesContent":["import {\n SimulateTradeEntity,\n TradeSimulationLoadDataParams,\n TradeSimulationSimulateParams,\n} from '../types';\n\ntype LoadedData = {\n marketData: number;\n};\n\n// The maximum is inclusive and the minimum is inclusive\nfunction getRandomIntInclusive(min: number, max: number) {\n min = Math.ceil(min);\n max = Math.floor(max);\n return Math.floor(Math.random() * (max - min + 1) + min);\n}\n\nconst randomHealth = () => {\n return Math.random() * 100 > 50\n ? 'healthy'\n : Math.random() * 100 > 50\n ? 'danger'\n : 'warning';\n};\n\nfunction getRandomFloat(min: number, max: number): number {\n return Math.random() * (max - min) + min;\n}\n\nexport default class TradeSimulationClient {\n private marketId: number | null = null;\n private accountId: number | null = null;\n private loadedData: LoadedData | null = null;\n\n // Method to asynchronously load data based on marketId and accountId\n async loadData(params: TradeSimulationLoadDataParams): Promise<void> {\n this.marketId = params.market_id;\n this.accountId = params.marginAccountId;\n\n // Simulate fetching data (@todo replace this with actual data fetching logic)\n const marketData = await this.fetchMarketData(\n this.marketId,\n this.accountId,\n );\n\n // Store the loaded data\n this.loadedData = { marketData };\n }\n\n private async fetchMarketData(\n marketId: number,\n accountId: number,\n ): Promise<number> {\n await new Promise((resolve) => setTimeout(resolve, 500)); // wait for 500ms\n return 1 + marketId + accountId;\n }\n\n // Synchronous method to simulate operations based on an amount\n simulate(params: TradeSimulationSimulateParams): SimulateTradeEntity {\n if (!this.loadedData) {\n throw new Error('Data not loaded. Call loadData() first.');\n }\n\n // @todo perform simulation\n\n return {\n estimatedPrice: getRandomIntInclusive(1000, 100000) + params.amount,\n estimatedSlippage: getRandomFloat(0.00001, 0.05),\n fees: getRandomIntInclusive(1000, 100000),\n impliedLeverage: getRandomIntInclusive(20, 50),\n imr: getRandomIntInclusive(1000, 100000),\n liquidationPrice: getRandomIntInclusive(1000, 100000),\n marginRatio: getRandomIntInclusive(0, 100),\n marginRatioHealth: randomHealth(),\n } as SimulateTradeEntity;\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"/","sources":["clients/types.ts"],"names":[],"mappings":";;;AAAA,IAAY,iBAQX;AARD,WAAY,iBAAiB;IAC3B,wCAAmB,CAAA;IACnB,2CAAsB,CAAA;IACtB,+CAA0B,CAAA;IAC1B,8CAAyB,CAAA;IACzB,uCAAkB,CAAA;IAClB,0CAAqB,CAAA;IACrB,qCAAgB,CAAA;AAClB,CAAC,EARW,iBAAiB,iCAAjB,iBAAiB,QAQ5B","sourcesContent":["export enum CandlesResolution {\n ONE_MINUTE = '1MIN',\n FIVE_MINUTES = '5MINS',\n FIFTEEN_MINUTES = '15MINS',\n THIRTY_MINUTES = '30MINS',\n ONE_HOUR = '1HOUR',\n FOUR_HOURS = '4HOURS',\n ONE_DAY = '1DAY',\n}\n\n// -- Candles --\nexport interface Candle {\n startedAt: string;\n ticker: string;\n resolution: CandlesResolution;\n low: string;\n high: string;\n open: string;\n close: string;\n baseTokenVolume: string;\n usdVolume: string;\n trades: number;\n startingOpenInterest: string;\n id: string;\n}\n\nexport interface MarketCandlesResponse {\n candles: Candle[];\n}\n\n// -- Markets --\n\nexport type MarketOrderInfo = {\n counterpartyAccountIds: number[];\n exchangeId: number;\n};\n\nexport type MarketEntity = {\n id: number;\n ticker: string;\n underlyingAsset: string;\n quoteToken: string;\n markPrice: number;\n isActive: boolean;\n maxLeverage: number;\n volume24H: number;\n priceChange24H: number;\n priceChange24HPercentage: number;\n openInterest: number;\n fundingRate: number;\n description: string;\n orderInfo: MarketOrderInfo;\n tickSizeDecimals: number;\n};\n\nexport type GetMarketsResult = MarketEntity[];\n\nexport type GetMarketResult = MarketEntity;\n\nexport type GetMarketParams = {\n id: MarketEntity['id'];\n};\n\nexport type GetCandlesParams = {\n marketId: MarketEntity['id'];\n resolution: CandlesResolution;\n fromISO?: string | null;\n toISO?: string | null;\n limit?: number | null;\n};\n\n// -- Account --\n\nexport type Status = 'OPEN' | 'CLOSED' | 'LIQUIDATED' | 'FILLED';\nexport type Side = 'LONG' | 'SHORT';\n\nexport type GetMarginAccountsParams = {\n address: string;\n limit?: number;\n};\n\nexport type GetMarginAccountParams = {\n address: string;\n marginAccountId: MarginAccountEntity['id'];\n};\n\nexport type GetPositionsForMarginAccountParams = {\n address: string;\n marginAccountId: MarginAccountEntity['id'];\n limit?: number;\n};\n\nexport type MarginAccountEntity = {\n id: number;\n name: string;\n marginRatioHealth: 'danger' | 'healthy' | 'warning';\n marginRatioPercentage: number;\n totalBalance: number;\n totalBalanceUnderlyingAsset: string;\n collaterals: {\n token: string;\n percentage: number;\n balance: number;\n balanceRUSD: number;\n }[];\n};\n\nexport type GetMarginAccountsResult = MarginAccountEntity[];\nexport type GetMarginAccountResult = MarginAccountEntity;\n\nexport type PositionEntity = {\n id: number;\n side: Side;\n size: number;\n base: number;\n price: number;\n markPrice: number;\n orderStatus: Status;\n realisedPnl?: number | null;\n unrealisedPnl?: number | null;\n liquidationPrice: number;\n fundingRate: number;\n market: MarketEntity;\n date: Date;\n};\n\nexport type GetPositionsForMarginAccountResult = {\n positions: PositionEntity[];\n totalUnrealizedPNL: number;\n};\n\n// --- Trading History ----\n\nexport type GetMarketTradingHistoryParams = {\n marketId: number;\n limit?: number;\n};\n\nexport type TradingHistoryEntity = {\n id: number;\n price: number;\n priceUnderlyingToken: string;\n size: number;\n sizeUnderlyingToken: string;\n timestampMillisecondsUTC: number;\n};\n\nexport type GetTradingHistoryResult = TradingHistoryEntity[];\n\n// --- Position History ---\n\nexport type GetPositionsHistoryForMarginAccountParams = {\n address: string;\n marginAccountId: MarginAccountEntity['id'];\n limit?: number;\n};\n\nexport type OrderType = 'market';\n\nexport type PositionHistoryType =\n | 'long-trade'\n | 'short-trade'\n | 'long-liquidation'\n | 'short-liquidation';\n\nexport type PositionHistoryEntity = {\n id: number;\n action: PositionHistoryType;\n orderType: OrderType;\n size: number;\n executionPrice: number;\n realisedPnl?: number | null;\n fees: number;\n timestamp: number;\n market: MarketEntity;\n};\n\nexport type GetPositionsHistoryForMarginAccountResult = PositionHistoryEntity[];\n\n// -- Max Order Size --\n\nexport type GetMaxOrderSizeAvailableParams = {\n marketId: MarketEntity['id'];\n marginAccountId: MarginAccountEntity['id'];\n direction: 'long' | 'short';\n};\n\nexport type GetMaxOrderSizeAvailableResult = number;\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"/","sources":["clients/types.ts"],"names":[],"mappings":";;;AAAA,IAAY,iBAQX;AARD,WAAY,iBAAiB;IAC3B,wCAAmB,CAAA;IACnB,2CAAsB,CAAA;IACtB,+CAA0B,CAAA;IAC1B,8CAAyB,CAAA;IACzB,uCAAkB,CAAA;IAClB,0CAAqB,CAAA;IACrB,qCAAgB,CAAA;AAClB,CAAC,EARW,iBAAiB,iCAAjB,iBAAiB,QAQ5B","sourcesContent":["export enum CandlesResolution {\n ONE_MINUTE = '1MIN',\n FIVE_MINUTES = '5MINS',\n FIFTEEN_MINUTES = '15MINS',\n THIRTY_MINUTES = '30MINS',\n ONE_HOUR = '1HOUR',\n FOUR_HOURS = '4HOURS',\n ONE_DAY = '1DAY',\n}\n\n// -- Candles --\nexport interface Candle {\n startedAt: string;\n ticker: string;\n resolution: CandlesResolution;\n low: string;\n high: string;\n open: string;\n close: string;\n baseTokenVolume: string;\n usdVolume: string;\n trades: number;\n startingOpenInterest: string;\n id: string;\n}\n\nexport interface MarketCandlesResponse {\n candles: Candle[];\n}\n\n// -- Markets --\n\nexport type MarketOrderInfo = {\n counterpartyAccountIds: number[];\n exchangeId: number;\n};\n\nexport type MarketEntity = {\n id: number;\n ticker: string;\n underlyingAsset: string;\n quoteToken: string;\n markPrice: number;\n isActive: boolean;\n maxLeverage: number;\n volume24H: number;\n priceChange24H: number;\n priceChange24HPercentage: number;\n openInterest: number;\n fundingRate: number;\n description: string;\n orderInfo: MarketOrderInfo;\n tickSizeDecimals: number;\n};\n\nexport type GetMarketsResult = MarketEntity[];\n\nexport type GetMarketResult = MarketEntity;\n\nexport type GetMarketParams = {\n id: MarketEntity['id'];\n};\n\nexport type GetCandlesParams = {\n marketId: MarketEntity['id'];\n resolution: CandlesResolution;\n fromISO?: string | null;\n toISO?: string | null;\n limit?: number | null;\n};\n\n// -- Account --\n\nexport type Status = 'OPEN' | 'CLOSED' | 'LIQUIDATED' | 'FILLED';\nexport type Side = 'LONG' | 'SHORT';\n\nexport type GetMarginAccountsParams = {\n address: string;\n limit?: number;\n};\n\nexport type GetMarginAccountParams = {\n address: string;\n marginAccountId: MarginAccountEntity['id'];\n};\n\nexport type GetPositionsForMarginAccountParams = {\n address: string;\n marginAccountId: MarginAccountEntity['id'];\n limit?: number;\n};\n\nexport type MarginAccountEntity = {\n id: number;\n name: string;\n marginRatioHealth: 'danger' | 'healthy' | 'warning';\n marginRatioPercentage: number;\n totalBalance: number;\n totalBalanceUnderlyingAsset: string;\n collaterals: {\n token: string;\n percentage: number;\n balance: number;\n balanceRUSD: number;\n }[];\n};\n\nexport type GetMarginAccountsResult = MarginAccountEntity[];\nexport type GetMarginAccountResult = MarginAccountEntity;\n\nexport type PositionEntity = {\n id: number;\n side: Side;\n size: number;\n base: number;\n price: number;\n markPrice: number;\n orderStatus: Status;\n realisedPnl?: number | null;\n unrealisedPnl?: number | null;\n liquidationPrice: number;\n fundingRate: number;\n market: MarketEntity;\n date: Date;\n};\n\nexport type GetPositionsForMarginAccountResult = {\n positions: PositionEntity[];\n totalUnrealizedPNL: number;\n};\n\n// --- Trading History ----\n\nexport type GetMarketTradingHistoryParams = {\n marketId: number;\n limit?: number;\n};\n\nexport type TradingHistoryEntity = {\n id: number;\n price: number;\n priceUnderlyingToken: string;\n size: number;\n sizeUnderlyingToken: string;\n timestampMillisecondsUTC: number;\n};\n\nexport type GetTradingHistoryResult = TradingHistoryEntity[];\n\n// --- Position History ---\n\nexport type GetPositionsHistoryForMarginAccountParams = {\n address: string;\n marginAccountId: MarginAccountEntity['id'];\n limit?: number;\n};\n\nexport type OrderType = 'market';\n\nexport type PositionHistoryType =\n | 'long-trade'\n | 'short-trade'\n | 'long-liquidation'\n | 'short-liquidation';\n\nexport type PositionHistoryEntity = {\n id: number;\n action: PositionHistoryType;\n orderType: OrderType;\n size: number;\n executionPrice: number;\n realisedPnl?: number | null;\n fees: number;\n timestamp: number;\n market: MarketEntity;\n};\n\nexport type GetPositionsHistoryForMarginAccountResult = PositionHistoryEntity[];\n\n// -- Max Order Size --\n\nexport type GetMaxOrderSizeAvailableParams = {\n marketId: MarketEntity['id'];\n marginAccountId: MarginAccountEntity['id'];\n direction: 'long' | 'short';\n};\n\nexport type GetMaxOrderSizeAvailableResult = number;\n\n// --- Trade Simulation ----\n\nexport type SimulateTradeEntity = {\n liquidationPrice: number;\n fees: number;\n estimatedPrice: number;\n estimatedSlippage: number;\n imr: number;\n impliedLeverage: number;\n marginRatio: MarginAccountEntity['marginRatioPercentage'];\n marginRatioHealth: MarginAccountEntity['marginRatioHealth'];\n};\n\nexport type TradeSimulationLoadDataParams = {\n market_id: MarketEntity['id'];\n marginAccountId: MarginAccountEntity['id'];\n};\n\nexport type TradeSimulationSimulateParams = {\n amount: number; // position size, + for long | - for short\n};\n"]}
@@ -1,6 +1,7 @@
1
1
  import { ServiceConfig } from './helpers/constants';
2
2
  import MarketsClient from './modules/markets';
3
3
  import AccountClient from './modules/account';
4
+ import TradeSimulationClient from './modules/trade.simulation';
4
5
  /**
5
6
  * @description Client for API
6
7
  */
@@ -10,6 +11,7 @@ export declare class ApiClient {
10
11
  private readonly apiEndpoint;
11
12
  private readonly _markets;
12
13
  private readonly _account;
14
+ private readonly _trade_simulation;
13
15
  private constructor();
14
16
  static configure(config: ServiceConfig): void;
15
17
  private static getInstance;
@@ -29,5 +31,19 @@ export declare class ApiClient {
29
31
  * @memberof ApiClient
30
32
  */
31
33
  static get account(): AccountClient;
34
+ /**
35
+ * Provides access to the TradeSimulationClient instance.
36
+ * This getter allows for interacting with trade simulation functionalities.
37
+ * It ensures a singleton pattern by fetching the instance from the ApiClient's
38
+ * private `_trade_simulation` property, ensuring that trade simulation operations
39
+ * use a consistent client configuration and state.
40
+ *
41
+ * @returns {TradeSimulationClient} An instance of TradeSimulationClient for trade simulation operations.
42
+ * @memberof ApiClient
43
+ * @example
44
+ * // Access the trade simulation client from the ApiClient
45
+ * const tradeSimulationClient = ApiClient.tradeSimulation;
46
+ */
47
+ static get tradeSimulation(): TradeSimulationClient;
32
48
  }
33
49
  //# 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,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
+ {"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;AAC9C,OAAO,qBAAqB,MAAM,4BAA4B,CAAC;AAE/D;;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;IACzC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAwB;IAE1D,OAAO;WAQO,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;IAED;;;;;;;;;;;;OAYG;IAEH,WAAkB,eAAe,IAAI,qBAAqB,CAEzD;CACF"}
@@ -0,0 +1,10 @@
1
+ import { SimulateTradeEntity, TradeSimulationLoadDataParams, TradeSimulationSimulateParams } from '../types';
2
+ export default class TradeSimulationClient {
3
+ private marketId;
4
+ private accountId;
5
+ private loadedData;
6
+ loadData(params: TradeSimulationLoadDataParams): Promise<void>;
7
+ private fetchMarketData;
8
+ simulate(params: TradeSimulationSimulateParams): SimulateTradeEntity;
9
+ }
10
+ //# sourceMappingURL=trade.simulation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trade.simulation.d.ts","sourceRoot":"/","sources":["clients/modules/trade.simulation.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,6BAA6B,EAC7B,6BAA6B,EAC9B,MAAM,UAAU,CAAC;AAyBlB,MAAM,CAAC,OAAO,OAAO,qBAAqB;IACxC,OAAO,CAAC,QAAQ,CAAuB;IACvC,OAAO,CAAC,SAAS,CAAuB;IACxC,OAAO,CAAC,UAAU,CAA2B;IAGvC,QAAQ,CAAC,MAAM,EAAE,6BAA6B,GAAG,OAAO,CAAC,IAAI,CAAC;YActD,eAAe;IAS7B,QAAQ,CAAC,MAAM,EAAE,6BAA6B,GAAG,mBAAmB;CAkBrE"}
@@ -145,4 +145,21 @@ export type GetMaxOrderSizeAvailableParams = {
145
145
  direction: 'long' | 'short';
146
146
  };
147
147
  export type GetMaxOrderSizeAvailableResult = number;
148
+ export type SimulateTradeEntity = {
149
+ liquidationPrice: number;
150
+ fees: number;
151
+ estimatedPrice: number;
152
+ estimatedSlippage: number;
153
+ imr: number;
154
+ impliedLeverage: number;
155
+ marginRatio: MarginAccountEntity['marginRatioPercentage'];
156
+ marginRatioHealth: MarginAccountEntity['marginRatioHealth'];
157
+ };
158
+ export type TradeSimulationLoadDataParams = {
159
+ market_id: MarketEntity['id'];
160
+ marginAccountId: MarginAccountEntity['id'];
161
+ };
162
+ export type TradeSimulationSimulateParams = {
163
+ amount: number;
164
+ };
148
165
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["clients/types.ts"],"names":[],"mappings":"AAAA,oBAAY,iBAAiB;IAC3B,UAAU,SAAS;IACnB,YAAY,UAAU;IACtB,eAAe,WAAW;IAC1B,cAAc,WAAW;IACzB,QAAQ,UAAU;IAClB,UAAU,WAAW;IACrB,OAAO,SAAS;CACjB;AAGD,MAAM,WAA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
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": "87e449e615b82a9bcd2e38296f2c2c0daa09a61b"
39
+ "gitHead": "4d95847e468540e2377e3c45f67f8635f1143a08"
40
40
  }
@@ -6,6 +6,7 @@ import {
6
6
  } from './helpers/constants';
7
7
  import MarketsClient from './modules/markets';
8
8
  import AccountClient from './modules/account';
9
+ import TradeSimulationClient from './modules/trade.simulation';
9
10
 
10
11
  /**
11
12
  * @description Client for API
@@ -19,12 +20,14 @@ export class ApiClient {
19
20
  private readonly apiEndpoint: string;
20
21
  private readonly _markets: MarketsClient;
21
22
  private readonly _account: AccountClient;
23
+ private readonly _trade_simulation: TradeSimulationClient;
22
24
 
23
25
  private constructor(config: ServiceConfig) {
24
26
  this.apiEndpoint = config.production ? API_PRODUCTION : API_TESTNET;
25
27
  ApiClient.config = { ...ApiClient.config, ...config };
26
28
  this._markets = new MarketsClient(this.apiEndpoint);
27
29
  this._account = new AccountClient(this.apiEndpoint);
30
+ this._trade_simulation = new TradeSimulationClient();
28
31
  }
29
32
 
30
33
  public static configure(config: ServiceConfig): void {
@@ -62,4 +65,22 @@ export class ApiClient {
62
65
  public static get account(): AccountClient {
63
66
  return ApiClient.getInstance()._account;
64
67
  }
68
+
69
+ /**
70
+ * Provides access to the TradeSimulationClient instance.
71
+ * This getter allows for interacting with trade simulation functionalities.
72
+ * It ensures a singleton pattern by fetching the instance from the ApiClient's
73
+ * private `_trade_simulation` property, ensuring that trade simulation operations
74
+ * use a consistent client configuration and state.
75
+ *
76
+ * @returns {TradeSimulationClient} An instance of TradeSimulationClient for trade simulation operations.
77
+ * @memberof ApiClient
78
+ * @example
79
+ * // Access the trade simulation client from the ApiClient
80
+ * const tradeSimulationClient = ApiClient.tradeSimulation;
81
+ */
82
+
83
+ public static get tradeSimulation(): TradeSimulationClient {
84
+ return ApiClient.getInstance()._trade_simulation;
85
+ }
65
86
  }
@@ -0,0 +1,77 @@
1
+ import {
2
+ SimulateTradeEntity,
3
+ TradeSimulationLoadDataParams,
4
+ TradeSimulationSimulateParams,
5
+ } from '../types';
6
+
7
+ type LoadedData = {
8
+ marketData: number;
9
+ };
10
+
11
+ // The maximum is inclusive and the minimum is inclusive
12
+ function getRandomIntInclusive(min: number, max: number) {
13
+ min = Math.ceil(min);
14
+ max = Math.floor(max);
15
+ return Math.floor(Math.random() * (max - min + 1) + min);
16
+ }
17
+
18
+ const randomHealth = () => {
19
+ return Math.random() * 100 > 50
20
+ ? 'healthy'
21
+ : Math.random() * 100 > 50
22
+ ? 'danger'
23
+ : 'warning';
24
+ };
25
+
26
+ function getRandomFloat(min: number, max: number): number {
27
+ return Math.random() * (max - min) + min;
28
+ }
29
+
30
+ export default class TradeSimulationClient {
31
+ private marketId: number | null = null;
32
+ private accountId: number | null = null;
33
+ private loadedData: LoadedData | null = null;
34
+
35
+ // Method to asynchronously load data based on marketId and accountId
36
+ async loadData(params: TradeSimulationLoadDataParams): Promise<void> {
37
+ this.marketId = params.market_id;
38
+ this.accountId = params.marginAccountId;
39
+
40
+ // Simulate fetching data (@todo replace this with actual data fetching logic)
41
+ const marketData = await this.fetchMarketData(
42
+ this.marketId,
43
+ this.accountId,
44
+ );
45
+
46
+ // Store the loaded data
47
+ this.loadedData = { marketData };
48
+ }
49
+
50
+ private async fetchMarketData(
51
+ marketId: number,
52
+ accountId: number,
53
+ ): Promise<number> {
54
+ await new Promise((resolve) => setTimeout(resolve, 500)); // wait for 500ms
55
+ return 1 + marketId + accountId;
56
+ }
57
+
58
+ // Synchronous method to simulate operations based on an amount
59
+ simulate(params: TradeSimulationSimulateParams): SimulateTradeEntity {
60
+ if (!this.loadedData) {
61
+ throw new Error('Data not loaded. Call loadData() first.');
62
+ }
63
+
64
+ // @todo perform simulation
65
+
66
+ return {
67
+ estimatedPrice: getRandomIntInclusive(1000, 100000) + params.amount,
68
+ estimatedSlippage: getRandomFloat(0.00001, 0.05),
69
+ fees: getRandomIntInclusive(1000, 100000),
70
+ impliedLeverage: getRandomIntInclusive(20, 50),
71
+ imr: getRandomIntInclusive(1000, 100000),
72
+ liquidationPrice: getRandomIntInclusive(1000, 100000),
73
+ marginRatio: getRandomIntInclusive(0, 100),
74
+ marginRatioHealth: randomHealth(),
75
+ } as SimulateTradeEntity;
76
+ }
77
+ }
@@ -186,3 +186,25 @@ export type GetMaxOrderSizeAvailableParams = {
186
186
  };
187
187
 
188
188
  export type GetMaxOrderSizeAvailableResult = number;
189
+
190
+ // --- Trade Simulation ----
191
+
192
+ export type SimulateTradeEntity = {
193
+ liquidationPrice: number;
194
+ fees: number;
195
+ estimatedPrice: number;
196
+ estimatedSlippage: number;
197
+ imr: number;
198
+ impliedLeverage: number;
199
+ marginRatio: MarginAccountEntity['marginRatioPercentage'];
200
+ marginRatioHealth: MarginAccountEntity['marginRatioHealth'];
201
+ };
202
+
203
+ export type TradeSimulationLoadDataParams = {
204
+ market_id: MarketEntity['id'];
205
+ marginAccountId: MarginAccountEntity['id'];
206
+ };
207
+
208
+ export type TradeSimulationSimulateParams = {
209
+ amount: number; // position size, + for long | - for short
210
+ };