@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 CHANGED
@@ -2917,6 +2917,17 @@ query GetTraderOpenTrades($trader: String!, $skip: Int!, $first: Int!) {
2917
2917
  ${PAIR_FULL}
2918
2918
  }
2919
2919
  }`;
2920
+ var GetAllOpenTradesQuery = `
2921
+ query GetAllOpenTrades($skip: Int!, $first: Int!) {
2922
+ trades(
2923
+ where: { isOpen: true }
2924
+ skip: $skip first: $first
2925
+ orderBy: timestamp orderDirection: desc
2926
+ ) {
2927
+ ${TRADE_CORE}
2928
+ ${PAIR_FULL}
2929
+ }
2930
+ }`;
2920
2931
  var ORDER_FIELDS = `
2921
2932
  id tradeID limitID trader
2922
2933
  pair { id from to group { id name } }
@@ -2996,9 +3007,9 @@ query GetTraderActiveLimits($trader: String!, $skip: Int!, $first: Int!) {
2996
3007
  }`;
2997
3008
 
2998
3009
  // src/data/internal/pagination.ts
2999
- async function paginateAll(fetcher, batchSize = 1e3, max = Infinity) {
3010
+ async function paginateAll(fetcher, batchSize = 1e3, max = Infinity, initialSkip = 0) {
3000
3011
  const results = [];
3001
- let skip = 0;
3012
+ let skip = initialSkip;
3002
3013
  while (results.length < max) {
3003
3014
  const remaining = max - results.length;
3004
3015
  const fetchSize = Math.min(batchSize, remaining);
@@ -3927,15 +3938,28 @@ var OstiumSubgraphClient = class _OstiumSubgraphClient {
3927
3938
  * PnL fields are zeroed.
3928
3939
  */
3929
3940
  async getOpenPositions(params) {
3930
- const { user, blockNumber } = params;
3941
+ const { user, blockNumber, limit = Infinity, skip: initialSkip = 0 } = params;
3942
+ const isGlobal = user === "ALL";
3931
3943
  const [trades, prices] = await Promise.all([
3932
- paginateAll(async (skip, first) => {
3933
- const data = await this.query(
3934
- GetTraderOpenTradesQuery,
3935
- { trader: user.toLowerCase(), skip, first }
3936
- );
3937
- return data.trades;
3938
- }),
3944
+ paginateAll(
3945
+ async (skip, first) => {
3946
+ if (isGlobal) {
3947
+ const data2 = await this.query(
3948
+ GetAllOpenTradesQuery,
3949
+ { skip, first }
3950
+ );
3951
+ return data2.trades;
3952
+ }
3953
+ const data = await this.query(
3954
+ GetTraderOpenTradesQuery,
3955
+ { trader: user.toLowerCase(), skip, first }
3956
+ );
3957
+ return data.trades;
3958
+ },
3959
+ 1e3,
3960
+ limit,
3961
+ initialSkip
3962
+ ),
3939
3963
  this.fetchLivePricesSafe()
3940
3964
  ]);
3941
3965
  const pairPositions = trades.map((trade) => {
@@ -5103,11 +5127,18 @@ var OstiumClient = class _OstiumClient {
5103
5127
  /**
5104
5128
  * Open positions + margin summary for a user. Defaults to the connected
5105
5129
  * trader. Live prices and the current block number are fetched automatically.
5130
+ *
5131
+ * - `user`: pass an address to scope to a single trader, or `'ALL'` to fetch
5132
+ * positions across every trader (no trader filter).
5133
+ * - `limit`: cap the number of positions returned (default: all).
5134
+ * - `skip`: offset into the result set for pagination (default: `0`).
5106
5135
  */
5107
5136
  async getOpenPositions(params) {
5108
5137
  return this.subgraph.getOpenPositions({
5109
5138
  user: params?.user ?? this.getTraderAddress(),
5110
- blockNumber: params?.blockNumber ?? await this.publicClient.getBlockNumber()
5139
+ blockNumber: params?.blockNumber ?? await this.publicClient.getBlockNumber(),
5140
+ limit: params?.limit,
5141
+ skip: params?.skip
5111
5142
  });
5112
5143
  }
5113
5144
  /**
package/dist/index.cjs CHANGED
@@ -2944,6 +2944,17 @@ query GetTraderOpenTrades($trader: String!, $skip: Int!, $first: Int!) {
2944
2944
  ${PAIR_FULL}
2945
2945
  }
2946
2946
  }`;
2947
+ var GetAllOpenTradesQuery = `
2948
+ query GetAllOpenTrades($skip: Int!, $first: Int!) {
2949
+ trades(
2950
+ where: { isOpen: true }
2951
+ skip: $skip first: $first
2952
+ orderBy: timestamp orderDirection: desc
2953
+ ) {
2954
+ ${TRADE_CORE}
2955
+ ${PAIR_FULL}
2956
+ }
2957
+ }`;
2947
2958
  var ORDER_FIELDS = `
2948
2959
  id tradeID limitID trader
2949
2960
  pair { id from to group { id name } }
@@ -3023,9 +3034,9 @@ query GetTraderActiveLimits($trader: String!, $skip: Int!, $first: Int!) {
3023
3034
  }`;
3024
3035
 
3025
3036
  // src/data/internal/pagination.ts
3026
- async function paginateAll(fetcher, batchSize = 1e3, max = Infinity) {
3037
+ async function paginateAll(fetcher, batchSize = 1e3, max = Infinity, initialSkip = 0) {
3027
3038
  const results = [];
3028
- let skip = 0;
3039
+ let skip = initialSkip;
3029
3040
  while (results.length < max) {
3030
3041
  const remaining = max - results.length;
3031
3042
  const fetchSize = Math.min(batchSize, remaining);
@@ -3954,15 +3965,28 @@ var OstiumSubgraphClient = class _OstiumSubgraphClient {
3954
3965
  * PnL fields are zeroed.
3955
3966
  */
3956
3967
  async getOpenPositions(params) {
3957
- const { user, blockNumber } = params;
3968
+ const { user, blockNumber, limit = Infinity, skip: initialSkip = 0 } = params;
3969
+ const isGlobal = user === "ALL";
3958
3970
  const [trades, prices] = await Promise.all([
3959
- paginateAll(async (skip, first) => {
3960
- const data = await this.query(
3961
- GetTraderOpenTradesQuery,
3962
- { trader: user.toLowerCase(), skip, first }
3963
- );
3964
- return data.trades;
3965
- }),
3971
+ paginateAll(
3972
+ async (skip, first) => {
3973
+ if (isGlobal) {
3974
+ const data2 = await this.query(
3975
+ GetAllOpenTradesQuery,
3976
+ { skip, first }
3977
+ );
3978
+ return data2.trades;
3979
+ }
3980
+ const data = await this.query(
3981
+ GetTraderOpenTradesQuery,
3982
+ { trader: user.toLowerCase(), skip, first }
3983
+ );
3984
+ return data.trades;
3985
+ },
3986
+ 1e3,
3987
+ limit,
3988
+ initialSkip
3989
+ ),
3966
3990
  this.fetchLivePricesSafe()
3967
3991
  ]);
3968
3992
  const pairPositions = trades.map((trade) => {
@@ -5130,11 +5154,18 @@ var OstiumClient = class _OstiumClient {
5130
5154
  /**
5131
5155
  * Open positions + margin summary for a user. Defaults to the connected
5132
5156
  * trader. Live prices and the current block number are fetched automatically.
5157
+ *
5158
+ * - `user`: pass an address to scope to a single trader, or `'ALL'` to fetch
5159
+ * positions across every trader (no trader filter).
5160
+ * - `limit`: cap the number of positions returned (default: all).
5161
+ * - `skip`: offset into the result set for pagination (default: `0`).
5133
5162
  */
5134
5163
  async getOpenPositions(params) {
5135
5164
  return this.subgraph.getOpenPositions({
5136
5165
  user: params?.user ?? this.getTraderAddress(),
5137
- blockNumber: params?.blockNumber ?? await this.publicClient.getBlockNumber()
5166
+ blockNumber: params?.blockNumber ?? await this.publicClient.getBlockNumber(),
5167
+ limit: params?.limit,
5168
+ skip: params?.skip
5138
5169
  });
5139
5170
  }
5140
5171
  /**