Skip to content

Commit

Permalink
feat: filters on prices and orders markets data (#143)
Browse files Browse the repository at this point in the history
* feat: filters on prices and orders markets data

* chore: ver bump
  • Loading branch information
LukasDeco authored and kilgaloon committed Aug 6, 2024
1 parent 7bdf943 commit 63b30f3
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 34 deletions.
77 changes: 44 additions & 33 deletions lib/client/indexer/markets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ import {
generateSubscriptionOp,
orders_bool_exp,
orders_order_by,
orders_select_column
orders_select_column,
prices_chart_data_bool_exp,
proposal_prices_chart_data_bool_exp
} from "./__generated__";
import { Client as GQLWebSocketClient } from "graphql-ws";
import { FutarchyMarketsRPCClient } from "../rpc/markets";
Expand Down Expand Up @@ -129,13 +131,15 @@ export class FutarchyIndexerMarketsClient implements FutarchyMarketsClient {
}

watchProposalMarketPricesAggregate(
proposalKey: PublicKey
proposalKey: PublicKey,
filters?: proposal_prices_chart_data_bool_exp
): Observable<ProposalMarketPricesAggregate[]> {
const { query, variables } = generateSubscriptionOp({
proposal_prices_chart_data: {
__args: {
where: {
proposal_acct: { _eq: proposalKey.toBase58() }
proposal_acct: { _eq: proposalKey.toBase58() },
...filters
},
order_by: [
{
Expand Down Expand Up @@ -204,32 +208,31 @@ export class FutarchyIndexerMarketsClient implements FutarchyMarketsClient {
{ query, variables },
{
next: (data) => {
const proposalMarketPrices =
data.data?.proposal_prices_chart_data?.map<ProposalMarketPricesAggregate>(
(d) => ({
failMarket: {
acct: d.fail_market_acct,
baseAmount: d.fail_market_base_amount,
baseDecimals:
d.proposalPriceFailMarket.tokenByBaseMintAcct.decimals,
price: d.fail_market_price,
quoteAmount: d.fail_market_quote_amount,
quoteDecimals:
d.proposalPriceFailMarket.tokenByQuoteMintAcct.decimals
},
passMarket: {
acct: d.pass_market_acct,
baseAmount: d.pass_market_base_amount,
baseDecimals:
d.proposalPricePassMarket.tokenByBaseMintAcct.decimals,
price: d.pass_market_price,
quoteAmount: d.pass_market_quote_amount,
quoteDecimals:
d.proposalPricePassMarket.tokenByQuoteMintAcct.decimals
},
createdAt: new Date(d.interv)
})
);
const proposalMarketPrices = data.data?.proposal_prices_chart_data
?.map<ProposalMarketPricesAggregate>((d) => ({
failMarket: {
acct: d.fail_market_acct,
baseAmount: d.fail_market_base_amount,
baseDecimals:
d.proposalPriceFailMarket.tokenByBaseMintAcct.decimals,
price: d.fail_market_price,
quoteAmount: d.fail_market_quote_amount,
quoteDecimals:
d.proposalPriceFailMarket.tokenByQuoteMintAcct.decimals
},
passMarket: {
acct: d.pass_market_acct,
baseAmount: d.pass_market_base_amount,
baseDecimals:
d.proposalPricePassMarket.tokenByBaseMintAcct.decimals,
price: d.pass_market_price,
quoteAmount: d.pass_market_quote_amount,
quoteDecimals:
d.proposalPricePassMarket.tokenByQuoteMintAcct.decimals
},
createdAt: new Date(d.interv)
}))
.filter((d) => !!d.passMarket.price && !!d.failMarket.price);
subscriber.next(proposalMarketPrices);
},
error: (error) => subscriber.error(error),
Expand Down Expand Up @@ -385,10 +388,14 @@ export class FutarchyIndexerMarketsClient implements FutarchyMarketsClient {
});
}

watchAllUserOrders(owner: PublicKey): Observable<Order[]> {
watchAllUserOrders(
owner: PublicKey,
filters?: orders_bool_exp
): Observable<Order[]> {
return this.watchOrdersForArgs({
where: {
actor_acct: { _eq: owner.toBase58() }
actor_acct: { _eq: owner.toBase58() },
...filters
},
order_by: [
{
Expand Down Expand Up @@ -427,15 +434,19 @@ export class FutarchyIndexerMarketsClient implements FutarchyMarketsClient {
});
}

watchSpotPrices(marketKey: PublicKey): Observable<SpotObservation[]> {
watchSpotPrices(
marketKey: PublicKey,
filters?: prices_chart_data_bool_exp
): Observable<SpotObservation[]> {
const { query, variables } = generateSubscriptionOp({
prices_chart_data: {
__args: {
where: {
market_acct: { _eq: marketKey.toString() },
prices_type: {
_in: ["spot", "conditional"]
}
},
...filters
},
order_by: [
{
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metadaoproject/futarchy-sdk",
"version": "3.0.0-alpha.7",
"version": "3.0.0-alpha.8",
"main": "dist",
"scripts": {
"preinstall": "npx only-allow pnpm",
Expand Down

0 comments on commit 63b30f3

Please sign in to comment.