diff --git a/lib/client/client.ts b/lib/client/client.ts index ff961dd..50869bb 100644 --- a/lib/client/client.ts +++ b/lib/client/client.ts @@ -149,6 +149,8 @@ export interface FutarchyMarketsClient { ): Observable<{ orders: Order[]; totalOrders: number }>; watchTwapPrices(marketKey: PublicKey): Observable; watchSpotPrices(marketKey: PublicKey): Observable; + // watchCurrentSpotPrice(marketKey: PublicKey): Observable; + // watchConditionalSpotPrice(marketKey: PublicKey): Observable; } export interface FutarchyOrderbookMarketsClient< diff --git a/lib/client/indexer/markets.ts b/lib/client/indexer/markets.ts index 876afd3..31670f0 100644 --- a/lib/client/indexer/markets.ts +++ b/lib/client/indexer/markets.ts @@ -156,9 +156,9 @@ export class FutarchyIndexerMarketsClient implements FutarchyMarketsClient { }, order_by: [ { - interv: "asc" + interv: "desc" } - ] + ], limit: 1 }, token_amount: true, market: { @@ -421,6 +421,119 @@ export class FutarchyIndexerMarketsClient implements FutarchyMarketsClient { limit: pageSizeValue }); } + watchConditionalSpotPrice( + marketKey: PublicKey, + filters?: prices_chart_data_bool_exp + ): Observable { + const { query, variables } = generateSubscriptionOp({ + prices_chart_data: { + __args: { + where: { + market_acct: { _eq: marketKey.toString() }, + prices_type: { + _in: ["conditional"] + }, + ...filters + }, + order_by: [ + { + interv: "desc" + } + ], + limit: 1 + }, + interv: true, + price: true, + quote_amount: true, + base_amount: true + } + }); + + return new Observable((subscriber) => { + const subscriptionCleanup = this.graphqlWSClient.subscribe<{ + prices_chart_data: { + interv: string; + price: number; + quote_amount: number; + base_amount: number; + }[]; + }>( + { query, variables }, + { + next: (data) => { + const spotObservations = + data.data?.prices_chart_data?.map((d) => ({ + priceUi: d.price, + createdAt: new Date(d.interv), + quoteAmount: d.quote_amount, + baseAmount: d.base_amount + })); + subscriber.next(spotObservations); + }, + error: (error) => subscriber.error(error), + complete: () => subscriber.complete() + } + ); + return () => subscriptionCleanup(); + }); + } + + watchCurrentSpotPrice( + marketKey: PublicKey, + filters?: prices_chart_data_bool_exp + ): Observable { + const { query, variables } = generateSubscriptionOp({ + prices_chart_data: { + __args: { + where: { + market_acct: { _eq: marketKey.toString() }, + prices_type: { + _in: ["spot"] + }, + ...filters + }, + order_by: [ + { + interv: "desc" + } + ], + limit: 1 + }, + interv: true, + price: true, + quote_amount: true, + base_amount: true + } + }); + + return new Observable((subscriber) => { + const subscriptionCleanup = this.graphqlWSClient.subscribe<{ + prices_chart_data: { + interv: string; + price: number; + quote_amount: number; + base_amount: number; + }[]; + }>( + { query, variables }, + { + next: (data) => { + const spotObservations = + data.data?.prices_chart_data?.map((d) => ({ + priceUi: d.price, + createdAt: new Date(d.interv), + quoteAmount: d.quote_amount, + baseAmount: d.base_amount + })); + subscriber.next(spotObservations); + }, + error: (error) => subscriber.error(error), + complete: () => subscriber.complete() + } + ); + return () => subscriptionCleanup(); + }); + } watchSpotPrices( marketKey: PublicKey, diff --git a/lib/client/indexer/proposals.ts b/lib/client/indexer/proposals.ts index e272cdf..35ce8ea 100644 --- a/lib/client/indexer/proposals.ts +++ b/lib/client/indexer/proposals.ts @@ -351,7 +351,8 @@ export class FutarchyIndexerProposalsClient implements FutarchyProposalsClient { { created_at: "desc" } - ] + ], + limit: 1 }, dao: { dao_detail: {