@ostium/builder-sdk 0.2.0 → 0.3.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/dist/cli.js +42 -11
- package/dist/index.cjs +42 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -2
- package/dist/index.d.ts +20 -2
- package/dist/index.js +42 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -624,11 +624,24 @@ interface GetPairsParams {
|
|
|
624
624
|
interface GetUserParams {
|
|
625
625
|
user: Address;
|
|
626
626
|
}
|
|
627
|
-
interface GetOpenPositionsParams
|
|
627
|
+
interface GetOpenPositionsParams {
|
|
628
|
+
/**
|
|
629
|
+
* Trader address — pass `'ALL'` to fetch every trader's open positions
|
|
630
|
+
* (no trader filter applied to the subgraph query).
|
|
631
|
+
*/
|
|
632
|
+
user: Address | AllTraders;
|
|
628
633
|
/** Current Arbitrum block number — required for live PnL. Auto-fetched on `OstiumClient`. */
|
|
629
634
|
blockNumber?: bigint;
|
|
635
|
+
/**
|
|
636
|
+
* Maximum number of positions to return. Defaults to `Infinity` (all positions).
|
|
637
|
+
*/
|
|
638
|
+
limit?: number;
|
|
639
|
+
/**
|
|
640
|
+
* Number of positions to skip (for pagination). Defaults to `0`.
|
|
641
|
+
*/
|
|
642
|
+
skip?: number;
|
|
630
643
|
}
|
|
631
|
-
/** Sentinel value for `getFills
|
|
644
|
+
/** Sentinel value for `getOpenPositions`, `getFills`, and `getFillsByTime` to fetch across every trader. */
|
|
632
645
|
type AllTraders = 'ALL';
|
|
633
646
|
interface GetFillsParams {
|
|
634
647
|
/**
|
|
@@ -1349,6 +1362,11 @@ declare class OstiumClient {
|
|
|
1349
1362
|
/**
|
|
1350
1363
|
* Open positions + margin summary for a user. Defaults to the connected
|
|
1351
1364
|
* trader. Live prices and the current block number are fetched automatically.
|
|
1365
|
+
*
|
|
1366
|
+
* - `user`: pass an address to scope to a single trader, or `'ALL'` to fetch
|
|
1367
|
+
* positions across every trader (no trader filter).
|
|
1368
|
+
* - `limit`: cap the number of positions returned (default: all).
|
|
1369
|
+
* - `skip`: offset into the result set for pagination (default: `0`).
|
|
1352
1370
|
*/
|
|
1353
1371
|
getOpenPositions(params?: Partial<GetOpenPositionsParams>): Promise<OpenPositionsResponse>;
|
|
1354
1372
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -624,11 +624,24 @@ interface GetPairsParams {
|
|
|
624
624
|
interface GetUserParams {
|
|
625
625
|
user: Address;
|
|
626
626
|
}
|
|
627
|
-
interface GetOpenPositionsParams
|
|
627
|
+
interface GetOpenPositionsParams {
|
|
628
|
+
/**
|
|
629
|
+
* Trader address — pass `'ALL'` to fetch every trader's open positions
|
|
630
|
+
* (no trader filter applied to the subgraph query).
|
|
631
|
+
*/
|
|
632
|
+
user: Address | AllTraders;
|
|
628
633
|
/** Current Arbitrum block number — required for live PnL. Auto-fetched on `OstiumClient`. */
|
|
629
634
|
blockNumber?: bigint;
|
|
635
|
+
/**
|
|
636
|
+
* Maximum number of positions to return. Defaults to `Infinity` (all positions).
|
|
637
|
+
*/
|
|
638
|
+
limit?: number;
|
|
639
|
+
/**
|
|
640
|
+
* Number of positions to skip (for pagination). Defaults to `0`.
|
|
641
|
+
*/
|
|
642
|
+
skip?: number;
|
|
630
643
|
}
|
|
631
|
-
/** Sentinel value for `getFills
|
|
644
|
+
/** Sentinel value for `getOpenPositions`, `getFills`, and `getFillsByTime` to fetch across every trader. */
|
|
632
645
|
type AllTraders = 'ALL';
|
|
633
646
|
interface GetFillsParams {
|
|
634
647
|
/**
|
|
@@ -1349,6 +1362,11 @@ declare class OstiumClient {
|
|
|
1349
1362
|
/**
|
|
1350
1363
|
* Open positions + margin summary for a user. Defaults to the connected
|
|
1351
1364
|
* trader. Live prices and the current block number are fetched automatically.
|
|
1365
|
+
*
|
|
1366
|
+
* - `user`: pass an address to scope to a single trader, or `'ALL'` to fetch
|
|
1367
|
+
* positions across every trader (no trader filter).
|
|
1368
|
+
* - `limit`: cap the number of positions returned (default: all).
|
|
1369
|
+
* - `skip`: offset into the result set for pagination (default: `0`).
|
|
1352
1370
|
*/
|
|
1353
1371
|
getOpenPositions(params?: Partial<GetOpenPositionsParams>): Promise<OpenPositionsResponse>;
|
|
1354
1372
|
/**
|
package/dist/index.js
CHANGED
|
@@ -2938,6 +2938,17 @@ query GetTraderOpenTrades($trader: String!, $skip: Int!, $first: Int!) {
|
|
|
2938
2938
|
${PAIR_FULL}
|
|
2939
2939
|
}
|
|
2940
2940
|
}`;
|
|
2941
|
+
var GetAllOpenTradesQuery = `
|
|
2942
|
+
query GetAllOpenTrades($skip: Int!, $first: Int!) {
|
|
2943
|
+
trades(
|
|
2944
|
+
where: { isOpen: true }
|
|
2945
|
+
skip: $skip first: $first
|
|
2946
|
+
orderBy: timestamp orderDirection: desc
|
|
2947
|
+
) {
|
|
2948
|
+
${TRADE_CORE}
|
|
2949
|
+
${PAIR_FULL}
|
|
2950
|
+
}
|
|
2951
|
+
}`;
|
|
2941
2952
|
var ORDER_FIELDS = `
|
|
2942
2953
|
id tradeID limitID trader
|
|
2943
2954
|
pair { id from to group { id name } }
|
|
@@ -3017,9 +3028,9 @@ query GetTraderActiveLimits($trader: String!, $skip: Int!, $first: Int!) {
|
|
|
3017
3028
|
}`;
|
|
3018
3029
|
|
|
3019
3030
|
// src/data/internal/pagination.ts
|
|
3020
|
-
async function paginateAll(fetcher, batchSize = 1e3, max = Infinity) {
|
|
3031
|
+
async function paginateAll(fetcher, batchSize = 1e3, max = Infinity, initialSkip = 0) {
|
|
3021
3032
|
const results = [];
|
|
3022
|
-
let skip =
|
|
3033
|
+
let skip = initialSkip;
|
|
3023
3034
|
while (results.length < max) {
|
|
3024
3035
|
const remaining = max - results.length;
|
|
3025
3036
|
const fetchSize = Math.min(batchSize, remaining);
|
|
@@ -3948,15 +3959,28 @@ var OstiumSubgraphClient = class _OstiumSubgraphClient {
|
|
|
3948
3959
|
* PnL fields are zeroed.
|
|
3949
3960
|
*/
|
|
3950
3961
|
async getOpenPositions(params) {
|
|
3951
|
-
const { user, blockNumber } = params;
|
|
3962
|
+
const { user, blockNumber, limit = Infinity, skip: initialSkip = 0 } = params;
|
|
3963
|
+
const isGlobal = user === "ALL";
|
|
3952
3964
|
const [trades, prices] = await Promise.all([
|
|
3953
|
-
paginateAll(
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
|
|
3957
|
-
|
|
3958
|
-
|
|
3959
|
-
|
|
3965
|
+
paginateAll(
|
|
3966
|
+
async (skip, first) => {
|
|
3967
|
+
if (isGlobal) {
|
|
3968
|
+
const data2 = await this.query(
|
|
3969
|
+
GetAllOpenTradesQuery,
|
|
3970
|
+
{ skip, first }
|
|
3971
|
+
);
|
|
3972
|
+
return data2.trades;
|
|
3973
|
+
}
|
|
3974
|
+
const data = await this.query(
|
|
3975
|
+
GetTraderOpenTradesQuery,
|
|
3976
|
+
{ trader: user.toLowerCase(), skip, first }
|
|
3977
|
+
);
|
|
3978
|
+
return data.trades;
|
|
3979
|
+
},
|
|
3980
|
+
1e3,
|
|
3981
|
+
limit,
|
|
3982
|
+
initialSkip
|
|
3983
|
+
),
|
|
3960
3984
|
this.fetchLivePricesSafe()
|
|
3961
3985
|
]);
|
|
3962
3986
|
const pairPositions = trades.map((trade) => {
|
|
@@ -5124,11 +5148,18 @@ var OstiumClient = class _OstiumClient {
|
|
|
5124
5148
|
/**
|
|
5125
5149
|
* Open positions + margin summary for a user. Defaults to the connected
|
|
5126
5150
|
* trader. Live prices and the current block number are fetched automatically.
|
|
5151
|
+
*
|
|
5152
|
+
* - `user`: pass an address to scope to a single trader, or `'ALL'` to fetch
|
|
5153
|
+
* positions across every trader (no trader filter).
|
|
5154
|
+
* - `limit`: cap the number of positions returned (default: all).
|
|
5155
|
+
* - `skip`: offset into the result set for pagination (default: `0`).
|
|
5127
5156
|
*/
|
|
5128
5157
|
async getOpenPositions(params) {
|
|
5129
5158
|
return this.subgraph.getOpenPositions({
|
|
5130
5159
|
user: params?.user ?? this.getTraderAddress(),
|
|
5131
|
-
blockNumber: params?.blockNumber ?? await this.publicClient.getBlockNumber()
|
|
5160
|
+
blockNumber: params?.blockNumber ?? await this.publicClient.getBlockNumber(),
|
|
5161
|
+
limit: params?.limit,
|
|
5162
|
+
skip: params?.skip
|
|
5132
5163
|
});
|
|
5133
5164
|
}
|
|
5134
5165
|
/**
|