@decibeltrade/sdk 0.1.6 → 0.1.8
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/dist/abi/generate-abis.js +9 -44
- package/dist/abi/types.js +1 -2
- package/dist/admin.js +10 -14
- package/dist/base.js +19 -26
- package/dist/constants.js +34 -41
- package/dist/fee-pay.js +1 -4
- package/dist/gas/gas-price-manager.js +3 -7
- package/dist/index.js +10 -26
- package/dist/order-event.types.js +1 -2
- package/dist/order-status.js +16 -23
- package/dist/read/account-overview/account-overview.reader.js +20 -91
- package/dist/read/account-overview/account-overview.types.d.ts +7 -7
- package/dist/read/account-overview/account-overview.types.js +23 -26
- package/dist/read/base-reader.js +5 -9
- package/dist/read/candlesticks/candlesticks.reader.js +24 -95
- package/dist/read/candlesticks/candlesticks.types.js +14 -17
- package/dist/read/delegations/delegations.reader.js +14 -84
- package/dist/read/delegations/delegations.types.js +6 -9
- package/dist/read/index.js +50 -68
- package/dist/read/leaderboard/leaderboard.reader.js +13 -94
- package/dist/read/leaderboard/leaderboard.types.js +10 -13
- package/dist/read/market-contexts/market-contexts.reader.js +16 -83
- package/dist/read/market-contexts/market-contexts.types.js +12 -15
- package/dist/read/market-depth/market-depth.reader.js +29 -101
- package/dist/read/market-depth/market-depth.types.js +8 -11
- package/dist/read/market-prices/market-prices.reader.js +30 -111
- package/dist/read/market-prices/market-prices.types.js +21 -24
- package/dist/read/market-trades/market-trades.reader.js +23 -94
- package/dist/read/market-trades/market-trades.types.js +18 -21
- package/dist/read/markets/markets.reader.js +55 -152
- package/dist/read/markets/markets.types.js +32 -35
- package/dist/read/pagination.types.js +5 -11
- package/dist/read/portfolio-chart/portfolio-chart.reader.js +12 -82
- package/dist/read/portfolio-chart/portfolio-chart.types.js +5 -8
- package/dist/read/types.js +58 -75
- package/dist/read/user-active-twaps/user-active-twaps.reader.js +16 -86
- package/dist/read/user-active-twaps/user-active-twaps.types.js +18 -21
- package/dist/read/user-bulk-orders/user-bulk-orders.reader.js +16 -86
- package/dist/read/user-bulk-orders/user-bulk-orders.types.js +16 -19
- package/dist/read/user-funding-history/user-funding-history.reader.js +16 -86
- package/dist/read/user-funding-history/user-funding-history.types.js +13 -16
- package/dist/read/user-notifications/user-notifications.reader.js +8 -32
- package/dist/read/user-notifications/user-notifications.types.js +19 -22
- package/dist/read/user-open-orders/user-open-orders.reader.js +16 -86
- package/dist/read/user-open-orders/user-open-orders.types.js +27 -30
- package/dist/read/user-order-history/user-order-history.reader.js +18 -88
- package/dist/read/user-order-history/user-order-history.types.js +29 -32
- package/dist/read/user-positions/user-positions.reader.js +24 -95
- package/dist/read/user-positions/user-positions.types.d.ts +15 -15
- package/dist/read/user-positions/user-positions.types.js +22 -25
- package/dist/read/user-subaccounts/user-subaccounts.reader.js +18 -89
- package/dist/read/user-subaccounts/user-subaccounts.types.js +8 -11
- package/dist/read/user-trade-history/user-trade-history.reader.js +16 -86
- package/dist/read/user-trade-history/user-trade-history.types.js +18 -21
- package/dist/read/vaults/vaults.reader.js +45 -150
- package/dist/read/vaults/vaults.types.js +52 -55
- package/dist/read/ws-subscription.js +10 -17
- package/dist/subaccount-types.js +4 -7
- package/dist/transaction-builder.js +15 -23
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils.js +28 -42
- package/dist/write.js +20 -24
- package/package.json +4 -3
- package/tsconfig.json +4 -1
|
@@ -1,100 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
28
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
-
function step(op) {
|
|
31
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
33
|
-
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;
|
|
34
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
-
switch (op[0]) {
|
|
36
|
-
case 0: case 1: t = op; break;
|
|
37
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
-
default:
|
|
41
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
-
if (t[2]) _.ops.pop();
|
|
46
|
-
_.trys.pop(); continue;
|
|
47
|
-
}
|
|
48
|
-
op = body.call(thisArg, _);
|
|
49
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
54
|
-
var t = {};
|
|
55
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
56
|
-
t[p] = s[p];
|
|
57
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
58
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
59
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
60
|
-
t[p[i]] = s[p[i]];
|
|
61
|
-
}
|
|
62
|
-
return t;
|
|
63
|
-
};
|
|
64
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
|
-
exports.LeaderboardReader = void 0;
|
|
66
|
-
var utils_1 = require("../../utils");
|
|
67
|
-
var base_reader_1 = require("../base-reader");
|
|
68
|
-
var leaderboard_types_1 = require("./leaderboard.types");
|
|
69
|
-
var LeaderboardReader = /** @class */ (function (_super) {
|
|
70
|
-
__extends(LeaderboardReader, _super);
|
|
71
|
-
function LeaderboardReader() {
|
|
72
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
73
|
-
}
|
|
1
|
+
import { constructKnownQueryParams } from "../../utils";
|
|
2
|
+
import { BaseReader } from "../base-reader";
|
|
3
|
+
import { LeaderboardSchema } from "./leaderboard.types";
|
|
4
|
+
export class LeaderboardReader extends BaseReader {
|
|
74
5
|
/**
|
|
75
6
|
* Get the leaderboard
|
|
76
7
|
* @param queryParams The query parameters for the leaderboard
|
|
77
8
|
* @returns The leaderboard
|
|
78
9
|
*/
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
case 0: return [4 /*yield*/, this.getRequest({
|
|
86
|
-
schema: leaderboard_types_1.LeaderboardSchema,
|
|
87
|
-
url: "".concat(this.deps.config.tradingHttpUrl, "/api/v1/leaderboard"),
|
|
88
|
-
queryParams: (0, utils_1.constructKnownQueryParams)(args),
|
|
89
|
-
options: fetchOptions,
|
|
90
|
-
})];
|
|
91
|
-
case 1:
|
|
92
|
-
response = _b.sent();
|
|
93
|
-
return [2 /*return*/, response.data];
|
|
94
|
-
}
|
|
95
|
-
});
|
|
10
|
+
async getLeaderboard({ fetchOptions, ...args }) {
|
|
11
|
+
const response = await this.getRequest({
|
|
12
|
+
schema: LeaderboardSchema,
|
|
13
|
+
url: `${this.deps.config.tradingHttpUrl}/api/v1/leaderboard`,
|
|
14
|
+
queryParams: constructKnownQueryParams(args),
|
|
15
|
+
options: fetchOptions,
|
|
96
16
|
});
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
exports.LeaderboardReader = LeaderboardReader;
|
|
17
|
+
return response.data;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
realized_pnl: v4_1.z.number(),
|
|
11
|
-
roi: v4_1.z.number(),
|
|
12
|
-
volume: v4_1.z.number(),
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
import { PaginatedResponseSchema } from "../types";
|
|
3
|
+
export const LeaderboardItemSchema = z.object({
|
|
4
|
+
rank: z.number(),
|
|
5
|
+
account: z.string(),
|
|
6
|
+
account_value: z.number(),
|
|
7
|
+
realized_pnl: z.number(),
|
|
8
|
+
roi: z.number(),
|
|
9
|
+
volume: z.number(),
|
|
13
10
|
});
|
|
14
|
-
|
|
11
|
+
export const LeaderboardSchema = PaginatedResponseSchema(LeaderboardItemSchema);
|
|
@@ -1,64 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
28
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
-
function step(op) {
|
|
31
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
33
|
-
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;
|
|
34
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
-
switch (op[0]) {
|
|
36
|
-
case 0: case 1: t = op; break;
|
|
37
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
-
default:
|
|
41
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
-
if (t[2]) _.ops.pop();
|
|
46
|
-
_.trys.pop(); continue;
|
|
47
|
-
}
|
|
48
|
-
op = body.call(thisArg, _);
|
|
49
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
-
exports.MarketContextsReader = void 0;
|
|
55
|
-
var base_reader_1 = require("../base-reader");
|
|
56
|
-
var market_contexts_types_1 = require("./market-contexts.types");
|
|
57
|
-
var MarketContextsReader = /** @class */ (function (_super) {
|
|
58
|
-
__extends(MarketContextsReader, _super);
|
|
59
|
-
function MarketContextsReader() {
|
|
60
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
61
|
-
}
|
|
1
|
+
import { BaseReader } from "../base-reader";
|
|
2
|
+
import { MarketContextsSchema } from "./market-contexts.types";
|
|
3
|
+
export class MarketContextsReader extends BaseReader {
|
|
62
4
|
/**
|
|
63
5
|
* Get the asset context for a given market
|
|
64
6
|
*
|
|
@@ -66,26 +8,17 @@ var MarketContextsReader = /** @class */ (function (_super) {
|
|
|
66
8
|
* // @param marketName The name of the market to get asset context for
|
|
67
9
|
* @returns The asset context for the given market or all if no market name is provided
|
|
68
10
|
*/
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
// queryParams: marketAddr ? { market: marketAddr.toString() } : undefined,
|
|
80
|
-
options: fetchOptions,
|
|
81
|
-
})];
|
|
82
|
-
case 1:
|
|
83
|
-
response = _c.sent();
|
|
84
|
-
return [2 /*return*/, response.data];
|
|
85
|
-
}
|
|
86
|
-
});
|
|
11
|
+
async getAll({ fetchOptions } = {}) {
|
|
12
|
+
// const marketAddr = marketName
|
|
13
|
+
// ? getMarketAddr(marketName, this.config.deployment.perpEngineGlobal)
|
|
14
|
+
// : undefined;
|
|
15
|
+
const response = await this.getRequest({
|
|
16
|
+
schema: MarketContextsSchema,
|
|
17
|
+
// TODO: Update this when the API is /market_contexts
|
|
18
|
+
url: `${this.deps.config.tradingHttpUrl}/api/v1/asset_contexts`,
|
|
19
|
+
// queryParams: marketAddr ? { market: marketAddr.toString() } : undefined,
|
|
20
|
+
options: fetchOptions,
|
|
87
21
|
});
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
exports.MarketContextsReader = MarketContextsReader;
|
|
22
|
+
return response.data;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
previous_day_price: v4_1.default.number(),
|
|
13
|
-
price_change_pct_24h: v4_1.default.number(),
|
|
14
|
-
price_history: v4_1.default.array(v4_1.default.number()),
|
|
1
|
+
import z from "zod/v4";
|
|
2
|
+
export const MarketContextSchema = z.object({
|
|
3
|
+
market: z.string(),
|
|
4
|
+
volume_24h: z.number(),
|
|
5
|
+
open_interest: z.number(),
|
|
6
|
+
mark_price: z.number(),
|
|
7
|
+
mid_price: z.number(),
|
|
8
|
+
oracle_price: z.number(),
|
|
9
|
+
previous_day_price: z.number(),
|
|
10
|
+
price_change_pct_24h: z.number(),
|
|
11
|
+
price_history: z.array(z.number()),
|
|
15
12
|
});
|
|
16
|
-
|
|
13
|
+
export const MarketContextsSchema = z.array(MarketContextSchema);
|
|
@@ -1,115 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
28
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
-
function step(op) {
|
|
31
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
33
|
-
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;
|
|
34
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
-
switch (op[0]) {
|
|
36
|
-
case 0: case 1: t = op; break;
|
|
37
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
-
default:
|
|
41
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
-
if (t[2]) _.ops.pop();
|
|
46
|
-
_.trys.pop(); continue;
|
|
47
|
-
}
|
|
48
|
-
op = body.call(thisArg, _);
|
|
49
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
-
exports.MarketDepthReader = void 0;
|
|
55
|
-
var utils_1 = require("../../utils");
|
|
56
|
-
var base_reader_1 = require("../base-reader");
|
|
57
|
-
var market_depth_types_1 = require("./market-depth.types");
|
|
58
|
-
var MarketDepthReader = /** @class */ (function (_super) {
|
|
59
|
-
__extends(MarketDepthReader, _super);
|
|
60
|
-
function MarketDepthReader() {
|
|
61
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
62
|
-
}
|
|
1
|
+
import { getMarketAddr } from "../../utils";
|
|
2
|
+
import { BaseReader } from "../base-reader";
|
|
3
|
+
import { MarketDepthSchema, } from "./market-depth.types";
|
|
4
|
+
export class MarketDepthReader extends BaseReader {
|
|
63
5
|
/**
|
|
64
6
|
* Get the market depth data for a given market
|
|
65
7
|
* @param marketName The name of the market to get market depth for
|
|
66
8
|
* @returns The market depth data for the given market
|
|
67
9
|
*/
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
return [4 /*yield*/, this.getRequest({
|
|
81
|
-
schema: market_depth_types_1.MarketDepthSchema,
|
|
82
|
-
url: "".concat(this.deps.config.tradingHttpUrl, "/api/v1/depth"),
|
|
83
|
-
queryParams: queryParams,
|
|
84
|
-
options: fetchOptions,
|
|
85
|
-
})];
|
|
86
|
-
case 1:
|
|
87
|
-
response = _c.sent();
|
|
88
|
-
return [2 /*return*/, response.data];
|
|
89
|
-
}
|
|
90
|
-
});
|
|
10
|
+
async getByName({ marketName, limit, fetchOptions }) {
|
|
11
|
+
const marketAddr = getMarketAddr(marketName, this.deps.config.deployment.perpEngineGlobal);
|
|
12
|
+
const queryParams = new URLSearchParams({ market: marketAddr.toString() });
|
|
13
|
+
if (limit !== undefined) {
|
|
14
|
+
queryParams.set("limit", limit.toString());
|
|
15
|
+
}
|
|
16
|
+
const response = await this.getRequest({
|
|
17
|
+
schema: MarketDepthSchema,
|
|
18
|
+
url: `${this.deps.config.tradingHttpUrl}/api/v1/depth`,
|
|
19
|
+
queryParams,
|
|
20
|
+
options: fetchOptions,
|
|
91
21
|
});
|
|
92
|
-
|
|
22
|
+
return response.data;
|
|
23
|
+
}
|
|
93
24
|
/**
|
|
94
25
|
* Subscribe to market depth updates for a given market ID
|
|
95
26
|
* @param marketName The name of the market to subscribe to
|
|
96
27
|
* @param onData Callback function for received market depth data
|
|
97
28
|
* @returns A function to unsubscribe from the market depth updates
|
|
98
29
|
*/
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return this.deps.ws.subscribe(topic,
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
var topic = "depth:".concat(marketAddr, ":").concat(aggregationSize);
|
|
30
|
+
subscribeByName(marketName, aggregationSize, onData) {
|
|
31
|
+
const marketAddr = getMarketAddr(marketName, this.deps.config.deployment.perpEngineGlobal);
|
|
32
|
+
const topic = `depth:${marketAddr}:${aggregationSize}`;
|
|
33
|
+
return this.deps.ws.subscribe(topic, MarketDepthSchema, onData);
|
|
34
|
+
}
|
|
35
|
+
resetSubscriptionByName(marketName, aggregationSize = 1) {
|
|
36
|
+
const marketAddr = getMarketAddr(marketName, this.deps.config.deployment.perpEngineGlobal);
|
|
37
|
+
const topic = `depth:${marketAddr}:${aggregationSize}`;
|
|
108
38
|
this.deps.ws.reset(topic);
|
|
109
|
-
}
|
|
110
|
-
|
|
39
|
+
}
|
|
40
|
+
getAggregationSizes() {
|
|
111
41
|
return [1, 2, 5, 10];
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
}(base_reader_1.BaseReader));
|
|
115
|
-
exports.MarketDepthReader = MarketDepthReader;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
exports.MarketOrderSchema = v4_1.default.object({
|
|
6
|
-
price: v4_1.default.number(),
|
|
7
|
-
size: v4_1.default.number(),
|
|
1
|
+
import z from "zod/v4";
|
|
2
|
+
export const MarketOrderSchema = z.object({
|
|
3
|
+
price: z.number(),
|
|
4
|
+
size: z.number(),
|
|
8
5
|
});
|
|
9
|
-
|
|
10
|
-
market:
|
|
11
|
-
bids:
|
|
12
|
-
asks:
|
|
6
|
+
export const MarketDepthSchema = z.object({
|
|
7
|
+
market: z.string(),
|
|
8
|
+
bids: z.array(MarketOrderSchema),
|
|
9
|
+
asks: z.array(MarketOrderSchema),
|
|
13
10
|
});
|
|
@@ -1,130 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
28
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
-
function step(op) {
|
|
31
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
33
|
-
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;
|
|
34
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
-
switch (op[0]) {
|
|
36
|
-
case 0: case 1: t = op; break;
|
|
37
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
-
default:
|
|
41
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
-
if (t[2]) _.ops.pop();
|
|
46
|
-
_.trys.pop(); continue;
|
|
47
|
-
}
|
|
48
|
-
op = body.call(thisArg, _);
|
|
49
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
-
exports.MarketPricesReader = void 0;
|
|
55
|
-
var utils_1 = require("../../utils");
|
|
56
|
-
var base_reader_1 = require("../base-reader");
|
|
57
|
-
var market_prices_types_1 = require("./market-prices.types");
|
|
58
|
-
var MarketPricesReader = /** @class */ (function (_super) {
|
|
59
|
-
__extends(MarketPricesReader, _super);
|
|
60
|
-
function MarketPricesReader() {
|
|
61
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
62
|
-
}
|
|
63
|
-
MarketPricesReader.prototype.getAll = function () {
|
|
64
|
-
return __awaiter(this, arguments, void 0, function (_a) {
|
|
65
|
-
var response;
|
|
66
|
-
var _b = _a === void 0 ? {} : _a, fetchOptions = _b.fetchOptions;
|
|
67
|
-
return __generator(this, function (_c) {
|
|
68
|
-
switch (_c.label) {
|
|
69
|
-
case 0: return [4 /*yield*/, this.getRequest({
|
|
70
|
-
schema: market_prices_types_1.MarketPricesSchema,
|
|
71
|
-
url: "".concat(this.deps.config.tradingHttpUrl, "/api/v1/prices"),
|
|
72
|
-
options: fetchOptions,
|
|
73
|
-
})];
|
|
74
|
-
case 1:
|
|
75
|
-
response = _c.sent();
|
|
76
|
-
return [2 /*return*/, response.data];
|
|
77
|
-
}
|
|
78
|
-
});
|
|
1
|
+
import { getMarketAddr } from "../../utils";
|
|
2
|
+
import { BaseReader } from "../base-reader";
|
|
3
|
+
import { MarketPricesSchema, MarketPriceWsMessageSchema, } from "./market-prices.types";
|
|
4
|
+
export class MarketPricesReader extends BaseReader {
|
|
5
|
+
async getAll({ fetchOptions } = {}) {
|
|
6
|
+
const response = await this.getRequest({
|
|
7
|
+
schema: MarketPricesSchema,
|
|
8
|
+
url: `${this.deps.config.tradingHttpUrl}/api/v1/prices`,
|
|
9
|
+
options: fetchOptions,
|
|
79
10
|
});
|
|
80
|
-
|
|
11
|
+
return response.data;
|
|
12
|
+
}
|
|
81
13
|
/**
|
|
82
14
|
* Get the price data for a given market
|
|
83
15
|
* @param marketName The name of the market to get prices for
|
|
84
16
|
* @returns The price data for the given market
|
|
85
17
|
*/
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
marketAddr = (0, utils_1.getMarketAddr)(marketName, this.deps.config.deployment.perpEngineGlobal);
|
|
94
|
-
return [4 /*yield*/, this.getRequest({
|
|
95
|
-
schema: market_prices_types_1.MarketPricesSchema,
|
|
96
|
-
url: "".concat(this.deps.config.tradingHttpUrl, "/api/v1/prices"),
|
|
97
|
-
queryParams: { market: marketAddr.toString() },
|
|
98
|
-
options: fetchOptions,
|
|
99
|
-
})];
|
|
100
|
-
case 1:
|
|
101
|
-
response = _c.sent();
|
|
102
|
-
return [2 /*return*/, response.data];
|
|
103
|
-
}
|
|
104
|
-
});
|
|
18
|
+
async getByName({ marketName, fetchOptions }) {
|
|
19
|
+
const marketAddr = getMarketAddr(marketName, this.deps.config.deployment.perpEngineGlobal);
|
|
20
|
+
const response = await this.getRequest({
|
|
21
|
+
schema: MarketPricesSchema,
|
|
22
|
+
url: `${this.deps.config.tradingHttpUrl}/api/v1/prices`,
|
|
23
|
+
queryParams: { market: marketAddr.toString() },
|
|
24
|
+
options: fetchOptions,
|
|
105
25
|
});
|
|
106
|
-
|
|
26
|
+
return response.data;
|
|
27
|
+
}
|
|
107
28
|
/**
|
|
108
29
|
* Subscribe to price updates for a market
|
|
109
30
|
* @param marketName The name of the market to subscribe to
|
|
110
31
|
* @param onData Callback function for received price data
|
|
111
32
|
* @returns A function to unsubscribe from the oracle price updates
|
|
112
33
|
*/
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
return this.deps.ws.subscribe(topic,
|
|
117
|
-
}
|
|
34
|
+
subscribeByName(marketName, onData) {
|
|
35
|
+
const marketAddr = getMarketAddr(marketName, this.deps.config.deployment.perpEngineGlobal);
|
|
36
|
+
const topic = `market_price:${marketAddr}`;
|
|
37
|
+
return this.deps.ws.subscribe(topic, MarketPriceWsMessageSchema, onData);
|
|
38
|
+
}
|
|
118
39
|
/**
|
|
119
40
|
* Subscribe to price updates for a market
|
|
120
41
|
* @param marketAddr The address of the market to subscribe to
|
|
121
42
|
* @param onData Callback function for received price data
|
|
122
43
|
* @returns A function to unsubscribe from the oracle price updates
|
|
123
44
|
*/
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
return this.deps.ws.subscribe(topic,
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
}(base_reader_1.BaseReader));
|
|
130
|
-
exports.MarketPricesReader = MarketPricesReader;
|
|
45
|
+
subscribeByAddress(marketAddr, onData) {
|
|
46
|
+
const topic = `market_price:${marketAddr}`;
|
|
47
|
+
return this.deps.ws.subscribe(topic, MarketPriceWsMessageSchema, onData);
|
|
48
|
+
}
|
|
49
|
+
}
|