@reyaxyz/api-sdk 0.6.3 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -9
- package/dist/clients/modules/account.js +11 -26
- package/dist/clients/modules/account.js.map +1 -1
- package/dist/clients/modules/markets.js +9 -9
- package/dist/clients/modules/markets.js.map +1 -1
- package/dist/clients/types.js.map +1 -1
- package/dist/types/clients/modules/account.d.ts +9 -24
- package/dist/types/clients/modules/account.d.ts.map +1 -1
- package/dist/types/clients/modules/markets.d.ts +7 -7
- package/dist/types/clients/modules/markets.d.ts.map +1 -1
- package/dist/types/clients/types.d.ts +34 -45
- package/dist/types/clients/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/clients/modules/account.ts +16 -32
- package/src/clients/modules/markets.ts +13 -10
- package/src/clients/types.ts +37 -50
package/README.md
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
# @
|
|
2
|
-
|
|
3
|
-
<p align="center">
|
|
4
|
-
<a href="https://app.voltz.xyz/">
|
|
5
|
-
<picture>
|
|
6
|
-
<img src="./assets/voltz-background.jpeg" alt="Voltz" width="512" />
|
|
7
|
-
</picture>
|
|
8
|
-
</a>
|
|
9
|
-
</p>
|
|
1
|
+
# @reyaxyz/api-sdk
|
|
10
2
|
|
|
11
3
|
<p align="center"> API sdk for the Reya Network </p>
|
|
12
4
|
|
|
@@ -67,27 +67,17 @@ var AccountClient = /** @class */ (function (_super) {
|
|
|
67
67
|
* based on the provided Ethereum address. An optional limit can be specified to control the number of
|
|
68
68
|
* collateral accounts returned in the response.
|
|
69
69
|
*
|
|
70
|
-
* @param {
|
|
71
|
-
* @
|
|
72
|
-
* all available collateral accounts for the address will be returned.
|
|
73
|
-
* @returns {Promise<CollateralAccountListResponse>} A promise that resolves to the response containing the collateral
|
|
70
|
+
* @param {GetMarginAccountsParams} getMarginAccountsParams
|
|
71
|
+
* @returns {Promise<MarginAccountEntity[]>} A promise that resolves to the response containing the margin
|
|
74
72
|
* account data.
|
|
75
73
|
* @memberof account
|
|
76
|
-
*
|
|
77
|
-
|
|
78
|
-
* // Fetch all collateral accounts for a specific address
|
|
79
|
-
* const accounts = await account.getCollateralAccounts('0x123...');
|
|
80
|
-
*
|
|
81
|
-
* @example
|
|
82
|
-
* // Fetch a limited number of collateral accounts for a specific address
|
|
83
|
-
* const limitedAccounts = await account.getCollateralAccounts('0x123...', 5);
|
|
84
|
-
*/
|
|
85
|
-
AccountClient.prototype.getCollateralAccounts = function (address, limit) {
|
|
74
|
+
* */
|
|
75
|
+
AccountClient.prototype.getCollateralAccounts = function (getMarginAccountsParams) {
|
|
86
76
|
return __awaiter(this, void 0, void 0, function () {
|
|
87
77
|
var uri;
|
|
88
78
|
return __generator(this, function (_a) {
|
|
89
|
-
uri = "/api/accounts/".concat(address);
|
|
90
|
-
return [2 /*return*/, this.get(uri, { limit: limit })];
|
|
79
|
+
uri = "/api/accounts/".concat(getMarginAccountsParams.address);
|
|
80
|
+
return [2 /*return*/, this.get(uri, { limit: getMarginAccountsParams.limit })];
|
|
91
81
|
});
|
|
92
82
|
});
|
|
93
83
|
};
|
|
@@ -97,21 +87,16 @@ var AccountClient = /** @class */ (function (_super) {
|
|
|
97
87
|
* This method sends a request to the API to obtain detailed information about a specific collateral account
|
|
98
88
|
* associated with the provided Ethereum address. The account is identified using the collateral account number.
|
|
99
89
|
*
|
|
100
|
-
* @param {
|
|
101
|
-
* @
|
|
102
|
-
*
|
|
103
|
-
* information of the specified collateral account.
|
|
90
|
+
* @param {GetMarginAccountParams} getMarginAccountParams
|
|
91
|
+
* @returns {Promise<MarginAccountEntity>} A promise that resolves to the response containing the detailed
|
|
92
|
+
* information of the specified margin account.
|
|
104
93
|
* @memberof account
|
|
105
|
-
*
|
|
106
|
-
* @example
|
|
107
|
-
* // Fetch details of a specific collateral account by its number for a given address
|
|
108
|
-
* const accountDetails = await account.getCollateralAccount('0x123...', 1);
|
|
109
94
|
*/
|
|
110
|
-
AccountClient.prototype.getCollateralAccount = function (
|
|
95
|
+
AccountClient.prototype.getCollateralAccount = function (getMarginAccountParams) {
|
|
111
96
|
return __awaiter(this, void 0, void 0, function () {
|
|
112
97
|
var uri;
|
|
113
98
|
return __generator(this, function (_a) {
|
|
114
|
-
uri = "/api/accounts/".concat(address, "/collateralAccount/").concat(
|
|
99
|
+
uri = "/api/accounts/".concat(getMarginAccountParams.address, "/collateralAccount/").concat(getMarginAccountParams.marginAccountNumber);
|
|
115
100
|
return [2 /*return*/, this.get(uri)];
|
|
116
101
|
});
|
|
117
102
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account.js","sourceRoot":"/","sources":["clients/modules/account.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"account.js","sourceRoot":"/","sources":["clients/modules/account.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,gDAAgC;AAEhC;IAA2C,iCAAU;IAArD;;IAuCA,CAAC;IAtCC;;;;;;;;;;;SAWK;IAEC,6CAAqB,GAA3B,UACE,uBAAgD;;;;gBAE1C,GAAG,GAAG,wBAAiB,uBAAuB,CAAC,OAAO,CAAE,CAAC;gBAC/D,sBAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,uBAAuB,CAAC,KAAK,EAAE,CAAC,EAAC;;;KAChE;IAED;;;;;;;;;;OAUG;IAEG,4CAAoB,GAA1B,UACE,sBAA8C;;;;gBAExC,GAAG,GAAG,wBAAiB,sBAAsB,CAAC,OAAO,gCAAsB,sBAAsB,CAAC,mBAAmB,CAAE,CAAC;gBAC9H,sBAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAC;;;KACtB;IACH,oBAAC;AAAD,CAAC,AAvCD,CAA2C,cAAU,GAuCpD","sourcesContent":["import {\n GetMarginAccountParams,\n GetMarginAccountsParams,\n MarginAccountEntity,\n} from '../types';\nimport RestClient from './rest';\n\nexport default class AccountClient extends RestClient {\n /**\n * Asynchronously retrieves a list of collateral accounts associated with a specific address.\n *\n * This method makes a request to the API endpoint to fetch collateral account data. The data is filtered\n * based on the provided Ethereum address. An optional limit can be specified to control the number of\n * collateral accounts returned in the response.\n *\n * @param {GetMarginAccountsParams} getMarginAccountsParams\n * @returns {Promise<MarginAccountEntity[]>} A promise that resolves to the response containing the margin\n * account data.\n * @memberof account\n * */\n\n async getCollateralAccounts(\n getMarginAccountsParams: GetMarginAccountsParams,\n ): Promise<MarginAccountEntity[]> {\n const uri = `/api/accounts/${getMarginAccountsParams.address}`;\n return this.get(uri, { limit: getMarginAccountsParams.limit });\n }\n\n /**\n * Asynchronously retrieves details of a specific collateral account for a given Ethereum address.\n *\n * This method sends a request to the API to obtain detailed information about a specific collateral account\n * associated with the provided Ethereum address. The account is identified using the collateral account number.\n *\n * @param {GetMarginAccountParams} getMarginAccountParams\n * @returns {Promise<MarginAccountEntity>} A promise that resolves to the response containing the detailed\n * information of the specified margin account.\n * @memberof account\n */\n\n async getCollateralAccount(\n getMarginAccountParams: GetMarginAccountParams,\n ): Promise<MarginAccountEntity> {\n const uri = `/api/accounts/${getMarginAccountParams.address}/collateralAccount/${getMarginAccountParams.marginAccountNumber}`;\n return this.get(uri);\n }\n}\n"]}
|
|
@@ -66,8 +66,8 @@ var MarketsClient = /** @class */ (function (_super) {
|
|
|
66
66
|
* This method makes a request to the API to fetch data for markets. If a specific market is provided as a parameter,
|
|
67
67
|
* it fetches data for that particular market; otherwise, it fetches data for all available markets.
|
|
68
68
|
*
|
|
69
|
-
* @param {
|
|
70
|
-
* @returns {Promise<
|
|
69
|
+
* @param {GetMarketsParams} [getMarketsParams] - The specific market ticker identifier for which data is requested. This parameter is optional.
|
|
70
|
+
* @returns {Promise<MarketEntity[]>} A promise that resolves to the response containing market data.
|
|
71
71
|
* @memberof MarketsClient
|
|
72
72
|
*
|
|
73
73
|
* @example
|
|
@@ -78,12 +78,12 @@ var MarketsClient = /** @class */ (function (_super) {
|
|
|
78
78
|
* // Fetch data for a specific market
|
|
79
79
|
* const specificMarketData = await market.getMarkets('ETH-USDC');
|
|
80
80
|
*/
|
|
81
|
-
MarketsClient.prototype.getMarkets = function (
|
|
81
|
+
MarketsClient.prototype.getMarkets = function (getMarketsParams) {
|
|
82
82
|
return __awaiter(this, void 0, void 0, function () {
|
|
83
83
|
var uri;
|
|
84
84
|
return __generator(this, function (_a) {
|
|
85
85
|
uri = '/api/markets';
|
|
86
|
-
return [2 /*return*/, this.get(uri, {
|
|
86
|
+
return [2 /*return*/, this.get(uri, { id: getMarketsParams.id })];
|
|
87
87
|
});
|
|
88
88
|
});
|
|
89
89
|
};
|
|
@@ -93,7 +93,7 @@ var MarketsClient = /** @class */ (function (_super) {
|
|
|
93
93
|
* This method fetches historical candlestick (or OHLC - Open, High, Low, Close) data for a given market.
|
|
94
94
|
* The data can be filtered by time range (fromISO and toISO) and resolution.
|
|
95
95
|
*
|
|
96
|
-
* @param {
|
|
96
|
+
* @param {number} marketId - The market identifier for which candlestick data is to be retrieved.
|
|
97
97
|
* @param {CandlesResolution} resolution - The granularity of the candlestick data (e.g., '1MIN', '5MIN', '1HR').
|
|
98
98
|
* @param {string|null} [fromISO] - The start time for the range of candlestick data in ISO 8601 format. Optional.
|
|
99
99
|
* @param {string|null} [toISO] - The end time for the range of candlestick data in ISO 8601 format. Optional.
|
|
@@ -104,11 +104,11 @@ var MarketsClient = /** @class */ (function (_super) {
|
|
|
104
104
|
* @example
|
|
105
105
|
* const marketCandles = await market.getMarketCandles('BTC-USD', '1HR', '2023-01-01T00:00:00Z', '2023-01-02T00:00:00Z');
|
|
106
106
|
*/
|
|
107
|
-
MarketsClient.prototype.getMarketCandles = function (
|
|
107
|
+
MarketsClient.prototype.getMarketCandles = function (marketId, resolution, fromISO, toISO, limit) {
|
|
108
108
|
return __awaiter(this, void 0, void 0, function () {
|
|
109
109
|
var uri;
|
|
110
110
|
return __generator(this, function (_a) {
|
|
111
|
-
uri = "/api/markets/candles/".concat(
|
|
111
|
+
uri = "/api/markets/candles/".concat(marketId);
|
|
112
112
|
return [2 /*return*/, this.get(uri, {
|
|
113
113
|
resolution: resolution,
|
|
114
114
|
fromISO: fromISO,
|
|
@@ -118,11 +118,11 @@ var MarketsClient = /** @class */ (function (_super) {
|
|
|
118
118
|
});
|
|
119
119
|
});
|
|
120
120
|
};
|
|
121
|
-
MarketsClient.prototype.getPerpetualMarketTrades = function (
|
|
121
|
+
MarketsClient.prototype.getPerpetualMarketTrades = function (marketId, limit) {
|
|
122
122
|
return __awaiter(this, void 0, void 0, function () {
|
|
123
123
|
var uri;
|
|
124
124
|
return __generator(this, function (_a) {
|
|
125
|
-
uri = "/api/trades/".concat(
|
|
125
|
+
uri = "/api/trades/".concat(marketId);
|
|
126
126
|
return [2 /*return*/, this.get(uri, {
|
|
127
127
|
limit: limit,
|
|
128
128
|
})];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markets.js","sourceRoot":"/","sources":["clients/modules/markets.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"markets.js","sourceRoot":"/","sources":["clients/modules/markets.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,gDAAgC;AAEhC;IAA2C,iCAAU;IAArD;;IAsEA,CAAC;IArEC;;;;;;;;;;;;;;;;;OAiBG;IAEG,kCAAU,GAAhB,UACE,gBAAkC;;;;gBAE5B,GAAG,GAAG,cAAc,CAAC;gBAC3B,sBAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE,gBAAgB,CAAC,EAAE,EAAE,CAAC,EAAC;;;KACnD;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,AAtED,CAA2C,cAAU,GAsEpD","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} [getMarketsParams] - 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(\n getMarketsParams: GetMarketsParams,\n ): Promise<MarketEntity[]> {\n const uri = '/api/markets';\n return this.get(uri, { id: getMarketsParams.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 +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
|
|
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 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 tickSizeDecimals: number;\n};\n\nexport type GetMarketsParams = {\n id?: number;\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 marginAccountNumber: 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 interface Position {\n id: number;\n symbol: string;\n side: Side;\n size: number;\n price: number;\n orderStatus: Status;\n markPrice: number;\n unrealisedPnl: number;\n realisedPnl: number;\n liquidationPrice: number;\n fundingRate: string;\n date: string;\n}\n\nexport type Trade = {\n id: number;\n side: Side;\n size: string;\n price: number;\n date: string;\n txId: string;\n};\n\nexport type TradesResponse = {\n trades: Trade[];\n};\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GetMarginAccountParams, GetMarginAccountsParams, MarginAccountEntity } from '../types';
|
|
2
2
|
import RestClient from './rest';
|
|
3
3
|
export default class AccountClient extends RestClient {
|
|
4
4
|
/**
|
|
@@ -8,38 +8,23 @@ export default class AccountClient extends RestClient {
|
|
|
8
8
|
* based on the provided Ethereum address. An optional limit can be specified to control the number of
|
|
9
9
|
* collateral accounts returned in the response.
|
|
10
10
|
*
|
|
11
|
-
* @param {
|
|
12
|
-
* @
|
|
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
|
|
11
|
+
* @param {GetMarginAccountsParams} getMarginAccountsParams
|
|
12
|
+
* @returns {Promise<MarginAccountEntity[]>} A promise that resolves to the response containing the margin
|
|
15
13
|
* account data.
|
|
16
14
|
* @memberof account
|
|
17
|
-
*
|
|
18
|
-
|
|
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>;
|
|
15
|
+
* */
|
|
16
|
+
getCollateralAccounts(getMarginAccountsParams: GetMarginAccountsParams): Promise<MarginAccountEntity[]>;
|
|
27
17
|
/**
|
|
28
18
|
* Asynchronously retrieves details of a specific collateral account for a given Ethereum address.
|
|
29
19
|
*
|
|
30
20
|
* This method sends a request to the API to obtain detailed information about a specific collateral account
|
|
31
21
|
* associated with the provided Ethereum address. The account is identified using the collateral account number.
|
|
32
22
|
*
|
|
33
|
-
* @param {
|
|
34
|
-
* @
|
|
35
|
-
*
|
|
36
|
-
* information of the specified collateral account.
|
|
23
|
+
* @param {GetMarginAccountParams} getMarginAccountParams
|
|
24
|
+
* @returns {Promise<MarginAccountEntity>} A promise that resolves to the response containing the detailed
|
|
25
|
+
* information of the specified margin account.
|
|
37
26
|
* @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
27
|
*/
|
|
43
|
-
getCollateralAccount(
|
|
28
|
+
getCollateralAccount(getMarginAccountParams: GetMarginAccountParams): Promise<MarginAccountEntity>;
|
|
44
29
|
}
|
|
45
30
|
//# sourceMappingURL=account.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account.d.ts","sourceRoot":"/","sources":["clients/modules/account.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"account.d.ts","sourceRoot":"/","sources":["clients/modules/account.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACvB,mBAAmB,EACpB,MAAM,UAAU,CAAC;AAClB,OAAO,UAAU,MAAM,QAAQ,CAAC;AAEhC,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,UAAU;IACnD;;;;;;;;;;;SAWK;IAEC,qBAAqB,CACzB,uBAAuB,EAAE,uBAAuB,GAC/C,OAAO,CAAC,mBAAmB,EAAE,CAAC;IAKjC;;;;;;;;;;OAUG;IAEG,oBAAoB,CACxB,sBAAsB,EAAE,sBAAsB,GAC7C,OAAO,CAAC,mBAAmB,CAAC;CAIhC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CandlesResolution, MarketCandlesResponse,
|
|
1
|
+
import { CandlesResolution, GetMarketsParams, MarketCandlesResponse, MarketEntity, TradesResponse } from '../types';
|
|
2
2
|
import RestClient from './rest';
|
|
3
3
|
export default class MarketsClient extends RestClient {
|
|
4
4
|
/**
|
|
@@ -7,8 +7,8 @@ export default class MarketsClient extends RestClient {
|
|
|
7
7
|
* This method makes a request to the API to fetch data for markets. If a specific market is provided as a parameter,
|
|
8
8
|
* it fetches data for that particular market; otherwise, it fetches data for all available markets.
|
|
9
9
|
*
|
|
10
|
-
* @param {
|
|
11
|
-
* @returns {Promise<
|
|
10
|
+
* @param {GetMarketsParams} [getMarketsParams] - The specific market ticker identifier for which data is requested. This parameter is optional.
|
|
11
|
+
* @returns {Promise<MarketEntity[]>} A promise that resolves to the response containing market data.
|
|
12
12
|
* @memberof MarketsClient
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
@@ -19,14 +19,14 @@ 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(
|
|
22
|
+
getMarkets(getMarketsParams: GetMarketsParams): Promise<MarketEntity[]>;
|
|
23
23
|
/**
|
|
24
24
|
* Retrieves candlestick data for a specified market.
|
|
25
25
|
*
|
|
26
26
|
* This method fetches historical candlestick (or OHLC - Open, High, Low, Close) data for a given market.
|
|
27
27
|
* The data can be filtered by time range (fromISO and toISO) and resolution.
|
|
28
28
|
*
|
|
29
|
-
* @param {
|
|
29
|
+
* @param {number} marketId - The market identifier for which candlestick data is to be retrieved.
|
|
30
30
|
* @param {CandlesResolution} resolution - The granularity of the candlestick data (e.g., '1MIN', '5MIN', '1HR').
|
|
31
31
|
* @param {string|null} [fromISO] - The start time for the range of candlestick data in ISO 8601 format. Optional.
|
|
32
32
|
* @param {string|null} [toISO] - The end time for the range of candlestick data in ISO 8601 format. Optional.
|
|
@@ -37,7 +37,7 @@ export default class MarketsClient extends RestClient {
|
|
|
37
37
|
* @example
|
|
38
38
|
* const marketCandles = await market.getMarketCandles('BTC-USD', '1HR', '2023-01-01T00:00:00Z', '2023-01-02T00:00:00Z');
|
|
39
39
|
*/
|
|
40
|
-
getMarketCandles(
|
|
41
|
-
getPerpetualMarketTrades(
|
|
40
|
+
getMarketCandles(marketId: MarketEntity['id'], resolution: CandlesResolution, fromISO?: string | null, toISO?: string | null, limit?: number | null): Promise<MarketCandlesResponse>;
|
|
41
|
+
getPerpetualMarketTrades(marketId: number, limit?: number | null): Promise<TradesResponse>;
|
|
42
42
|
}
|
|
43
43
|
//# sourceMappingURL=markets.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markets.d.ts","sourceRoot":"/","sources":["clients/modules/markets.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,
|
|
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,CACd,gBAAgB,EAAE,gBAAgB,GACjC,OAAO,CAAC,YAAY,EAAE,CAAC;IAK1B;;;;;;;;;;;;;;;;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"}
|
|
@@ -24,47 +24,49 @@ export interface Candle {
|
|
|
24
24
|
export interface MarketCandlesResponse {
|
|
25
25
|
candles: Candle[];
|
|
26
26
|
}
|
|
27
|
-
export
|
|
27
|
+
export type MarketEntity = {
|
|
28
28
|
id: number;
|
|
29
29
|
ticker: string;
|
|
30
|
-
instrumentName: string;
|
|
31
|
-
instrumentType: string;
|
|
32
30
|
underlyingAsset: string;
|
|
33
|
-
|
|
31
|
+
quoteToken: string;
|
|
34
32
|
markPrice: number;
|
|
35
|
-
indexPrice: number;
|
|
36
33
|
isActive: boolean;
|
|
37
34
|
maxLeverage: number;
|
|
38
35
|
volume24H: number;
|
|
39
36
|
priceChange24H: number;
|
|
40
|
-
priceChange24HPercentage:
|
|
41
|
-
openInterest:
|
|
42
|
-
fundingRate:
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
}
|
|
37
|
+
priceChange24HPercentage: number;
|
|
38
|
+
openInterest: number;
|
|
39
|
+
fundingRate: number;
|
|
40
|
+
description: string;
|
|
41
|
+
tickSizeDecimals: number;
|
|
42
|
+
};
|
|
43
|
+
export type GetMarketsParams = {
|
|
44
|
+
id?: number;
|
|
45
|
+
};
|
|
66
46
|
export type Status = 'OPEN' | 'CLOSED' | 'LIQUIDATED' | 'FILLED';
|
|
67
47
|
export type Side = 'LONG' | 'SHORT';
|
|
48
|
+
export type GetMarginAccountsParams = {
|
|
49
|
+
address: string;
|
|
50
|
+
limit?: number;
|
|
51
|
+
};
|
|
52
|
+
export type GetMarginAccountParams = {
|
|
53
|
+
address: string;
|
|
54
|
+
marginAccountNumber: number;
|
|
55
|
+
};
|
|
56
|
+
export type MarginAccountEntity = {
|
|
57
|
+
id: number;
|
|
58
|
+
name: string;
|
|
59
|
+
marginRatioHealth: 'danger' | 'healthy' | 'warning';
|
|
60
|
+
marginRatioPercentage: number;
|
|
61
|
+
totalBalance: number;
|
|
62
|
+
totalBalanceUnderlyingAsset: string;
|
|
63
|
+
collaterals: {
|
|
64
|
+
token: string;
|
|
65
|
+
percentage: number;
|
|
66
|
+
balance: number;
|
|
67
|
+
balanceRUSD: number;
|
|
68
|
+
}[];
|
|
69
|
+
};
|
|
68
70
|
export interface Position {
|
|
69
71
|
id: number;
|
|
70
72
|
symbol: string;
|
|
@@ -79,26 +81,13 @@ export interface Position {
|
|
|
79
81
|
fundingRate: string;
|
|
80
82
|
date: string;
|
|
81
83
|
}
|
|
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
84
|
export type Trade = {
|
|
97
85
|
id: number;
|
|
98
86
|
side: Side;
|
|
99
87
|
size: string;
|
|
100
88
|
price: number;
|
|
101
89
|
date: string;
|
|
90
|
+
txId: string;
|
|
102
91
|
};
|
|
103
92
|
export type TradesResponse = {
|
|
104
93
|
trades: Trade[];
|
|
@@ -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,WAAW,MAAM;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,iBAAiB,CAAC;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,oBAAoB,EAAE,MAAM,CAAC;IAC7B,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAID,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["clients/types.ts"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reyaxyz/api-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.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": "
|
|
39
|
+
"gitHead": "0a81b19c8d03ac890f08059f697aa4d907ad39e0"
|
|
40
40
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
GetMarginAccountParams,
|
|
3
|
+
GetMarginAccountsParams,
|
|
4
|
+
MarginAccountEntity,
|
|
4
5
|
} from '../types';
|
|
5
6
|
import RestClient from './rest';
|
|
6
7
|
|
|
@@ -12,28 +13,17 @@ export default class AccountClient extends RestClient {
|
|
|
12
13
|
* based on the provided Ethereum address. An optional limit can be specified to control the number of
|
|
13
14
|
* collateral accounts returned in the response.
|
|
14
15
|
*
|
|
15
|
-
* @param {
|
|
16
|
-
* @
|
|
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
|
|
16
|
+
* @param {GetMarginAccountsParams} getMarginAccountsParams
|
|
17
|
+
* @returns {Promise<MarginAccountEntity[]>} A promise that resolves to the response containing the margin
|
|
19
18
|
* account data.
|
|
20
19
|
* @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
|
-
*/
|
|
20
|
+
* */
|
|
30
21
|
|
|
31
22
|
async getCollateralAccounts(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return this.get(uri, { limit });
|
|
23
|
+
getMarginAccountsParams: GetMarginAccountsParams,
|
|
24
|
+
): Promise<MarginAccountEntity[]> {
|
|
25
|
+
const uri = `/api/accounts/${getMarginAccountsParams.address}`;
|
|
26
|
+
return this.get(uri, { limit: getMarginAccountsParams.limit });
|
|
37
27
|
}
|
|
38
28
|
|
|
39
29
|
/**
|
|
@@ -42,22 +32,16 @@ export default class AccountClient extends RestClient {
|
|
|
42
32
|
* This method sends a request to the API to obtain detailed information about a specific collateral account
|
|
43
33
|
* associated with the provided Ethereum address. The account is identified using the collateral account number.
|
|
44
34
|
*
|
|
45
|
-
* @param {
|
|
46
|
-
* @
|
|
47
|
-
*
|
|
48
|
-
* information of the specified collateral account.
|
|
35
|
+
* @param {GetMarginAccountParams} getMarginAccountParams
|
|
36
|
+
* @returns {Promise<MarginAccountEntity>} A promise that resolves to the response containing the detailed
|
|
37
|
+
* information of the specified margin account.
|
|
49
38
|
* @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
39
|
*/
|
|
55
40
|
|
|
56
41
|
async getCollateralAccount(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const uri = `/api/accounts/${address}/collateralAccount/${collateralAccountNumber}`;
|
|
42
|
+
getMarginAccountParams: GetMarginAccountParams,
|
|
43
|
+
): Promise<MarginAccountEntity> {
|
|
44
|
+
const uri = `/api/accounts/${getMarginAccountParams.address}/collateralAccount/${getMarginAccountParams.marginAccountNumber}`;
|
|
61
45
|
return this.get(uri);
|
|
62
46
|
}
|
|
63
47
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CandlesResolution,
|
|
3
|
+
GetMarketsParams,
|
|
3
4
|
MarketCandlesResponse,
|
|
4
|
-
|
|
5
|
+
MarketEntity,
|
|
5
6
|
TradesResponse,
|
|
6
7
|
} from '../types';
|
|
7
8
|
import RestClient from './rest';
|
|
@@ -13,8 +14,8 @@ export default class MarketsClient extends RestClient {
|
|
|
13
14
|
* This method makes a request to the API to fetch data for markets. If a specific market is provided as a parameter,
|
|
14
15
|
* it fetches data for that particular market; otherwise, it fetches data for all available markets.
|
|
15
16
|
*
|
|
16
|
-
* @param {
|
|
17
|
-
* @returns {Promise<
|
|
17
|
+
* @param {GetMarketsParams} [getMarketsParams] - The specific market ticker identifier for which data is requested. This parameter is optional.
|
|
18
|
+
* @returns {Promise<MarketEntity[]>} A promise that resolves to the response containing market data.
|
|
18
19
|
* @memberof MarketsClient
|
|
19
20
|
*
|
|
20
21
|
* @example
|
|
@@ -26,9 +27,11 @@ export default class MarketsClient extends RestClient {
|
|
|
26
27
|
* const specificMarketData = await market.getMarkets('ETH-USDC');
|
|
27
28
|
*/
|
|
28
29
|
|
|
29
|
-
async getMarkets(
|
|
30
|
+
async getMarkets(
|
|
31
|
+
getMarketsParams: GetMarketsParams,
|
|
32
|
+
): Promise<MarketEntity[]> {
|
|
30
33
|
const uri = '/api/markets';
|
|
31
|
-
return this.get(uri, {
|
|
34
|
+
return this.get(uri, { id: getMarketsParams.id });
|
|
32
35
|
}
|
|
33
36
|
|
|
34
37
|
/**
|
|
@@ -37,7 +40,7 @@ export default class MarketsClient extends RestClient {
|
|
|
37
40
|
* This method fetches historical candlestick (or OHLC - Open, High, Low, Close) data for a given market.
|
|
38
41
|
* The data can be filtered by time range (fromISO and toISO) and resolution.
|
|
39
42
|
*
|
|
40
|
-
* @param {
|
|
43
|
+
* @param {number} marketId - The market identifier for which candlestick data is to be retrieved.
|
|
41
44
|
* @param {CandlesResolution} resolution - The granularity of the candlestick data (e.g., '1MIN', '5MIN', '1HR').
|
|
42
45
|
* @param {string|null} [fromISO] - The start time for the range of candlestick data in ISO 8601 format. Optional.
|
|
43
46
|
* @param {string|null} [toISO] - The end time for the range of candlestick data in ISO 8601 format. Optional.
|
|
@@ -50,13 +53,13 @@ export default class MarketsClient extends RestClient {
|
|
|
50
53
|
*/
|
|
51
54
|
|
|
52
55
|
async getMarketCandles(
|
|
53
|
-
|
|
56
|
+
marketId: MarketEntity['id'],
|
|
54
57
|
resolution: CandlesResolution,
|
|
55
58
|
fromISO?: string | null,
|
|
56
59
|
toISO?: string | null,
|
|
57
60
|
limit?: number | null,
|
|
58
61
|
): Promise<MarketCandlesResponse> {
|
|
59
|
-
const uri = `/api/markets/candles/${
|
|
62
|
+
const uri = `/api/markets/candles/${marketId}`;
|
|
60
63
|
return this.get(uri, {
|
|
61
64
|
resolution,
|
|
62
65
|
fromISO,
|
|
@@ -66,10 +69,10 @@ export default class MarketsClient extends RestClient {
|
|
|
66
69
|
}
|
|
67
70
|
|
|
68
71
|
async getPerpetualMarketTrades(
|
|
69
|
-
|
|
72
|
+
marketId: number,
|
|
70
73
|
limit?: number | null,
|
|
71
74
|
): Promise<TradesResponse> {
|
|
72
|
-
const uri = `/api/trades/${
|
|
75
|
+
const uri = `/api/trades/${marketId}`;
|
|
73
76
|
return this.get(uri, {
|
|
74
77
|
limit,
|
|
75
78
|
});
|
package/src/clients/types.ts
CHANGED
|
@@ -30,54 +30,56 @@ export interface MarketCandlesResponse {
|
|
|
30
30
|
|
|
31
31
|
// -- Markets --
|
|
32
32
|
|
|
33
|
-
export
|
|
33
|
+
export type MarketEntity = {
|
|
34
34
|
id: number;
|
|
35
35
|
ticker: string;
|
|
36
|
-
instrumentName: string;
|
|
37
|
-
instrumentType: string;
|
|
38
36
|
underlyingAsset: string;
|
|
39
|
-
|
|
37
|
+
quoteToken: string;
|
|
40
38
|
markPrice: number;
|
|
41
|
-
indexPrice: number;
|
|
42
39
|
isActive: boolean;
|
|
43
40
|
maxLeverage: number;
|
|
44
41
|
volume24H: number;
|
|
45
42
|
priceChange24H: number;
|
|
46
|
-
priceChange24HPercentage:
|
|
47
|
-
openInterest:
|
|
48
|
-
fundingRate:
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export interface MarketListResponse {
|
|
55
|
-
[key: string]: MarketEntry;
|
|
56
|
-
}
|
|
43
|
+
priceChange24HPercentage: number;
|
|
44
|
+
openInterest: number;
|
|
45
|
+
fundingRate: number;
|
|
46
|
+
description: string;
|
|
47
|
+
tickSizeDecimals: number;
|
|
48
|
+
};
|
|
57
49
|
|
|
50
|
+
export type GetMarketsParams = {
|
|
51
|
+
id?: number;
|
|
52
|
+
};
|
|
58
53
|
// -- Account --
|
|
59
54
|
|
|
60
|
-
export interface CollateralAccount {
|
|
61
|
-
id: number;
|
|
62
|
-
name: string;
|
|
63
|
-
equity: number;
|
|
64
|
-
balance: number;
|
|
65
|
-
marginRatio: string;
|
|
66
|
-
collaterals: Collateral[];
|
|
67
|
-
positions: Position[];
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export interface Collateral {
|
|
71
|
-
collateralAsset: string;
|
|
72
|
-
balance: number;
|
|
73
|
-
availableBalance: number;
|
|
74
|
-
withdrawableBalance: number;
|
|
75
|
-
collateralValue: number;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
55
|
export type Status = 'OPEN' | 'CLOSED' | 'LIQUIDATED' | 'FILLED';
|
|
79
56
|
export type Side = 'LONG' | 'SHORT';
|
|
80
57
|
|
|
58
|
+
export type GetMarginAccountsParams = {
|
|
59
|
+
address: string;
|
|
60
|
+
limit?: number;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export type GetMarginAccountParams = {
|
|
64
|
+
address: string;
|
|
65
|
+
marginAccountNumber: number;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export type MarginAccountEntity = {
|
|
69
|
+
id: number;
|
|
70
|
+
name: string;
|
|
71
|
+
marginRatioHealth: 'danger' | 'healthy' | 'warning';
|
|
72
|
+
marginRatioPercentage: number;
|
|
73
|
+
totalBalance: number;
|
|
74
|
+
totalBalanceUnderlyingAsset: string;
|
|
75
|
+
collaterals: {
|
|
76
|
+
token: string;
|
|
77
|
+
percentage: number;
|
|
78
|
+
balance: number;
|
|
79
|
+
balanceRUSD: number;
|
|
80
|
+
}[];
|
|
81
|
+
};
|
|
82
|
+
|
|
81
83
|
export interface Position {
|
|
82
84
|
id: number;
|
|
83
85
|
symbol: string;
|
|
@@ -93,28 +95,13 @@ export interface Position {
|
|
|
93
95
|
date: string;
|
|
94
96
|
}
|
|
95
97
|
|
|
96
|
-
export interface CollateralAccountListResponse {
|
|
97
|
-
address: string;
|
|
98
|
-
collateralAccounts: CollateralAccount[];
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export interface CollateralAccountResponse {
|
|
102
|
-
address: string;
|
|
103
|
-
id: number;
|
|
104
|
-
name: string;
|
|
105
|
-
equity: number;
|
|
106
|
-
balance: number;
|
|
107
|
-
marginRatio: string;
|
|
108
|
-
collaterals: Collateral[];
|
|
109
|
-
positions: Position[];
|
|
110
|
-
}
|
|
111
|
-
|
|
112
98
|
export type Trade = {
|
|
113
99
|
id: number;
|
|
114
100
|
side: Side;
|
|
115
101
|
size: string;
|
|
116
102
|
price: number;
|
|
117
103
|
date: string;
|
|
104
|
+
txId: string;
|
|
118
105
|
};
|
|
119
106
|
|
|
120
107
|
export type TradesResponse = {
|