From b4ab83c2d9b4f17ec0f8bad6141bc7b5a9dc1228 Mon Sep 17 00:00:00 2001 From: Cameron Gilbert Date: Mon, 1 Apr 2024 16:10:15 -0400 Subject: [PATCH] feat: proxy prices (#343) (#344) * feat: proxy prices (#343) * fix: test name --- src/gql/heart-monitor/heart-monitor.test.ts | 18 +++++++++++ src/gql/heart-monitor/heart-monitor.ts | 8 +++++ src/gql/query/index.ts | 1 + src/gql/query/proxies.ts | 33 +++++++++++++++++++++ src/gql/utils/defaultObjects.ts | 18 +++++++++++ 5 files changed, 78 insertions(+) create mode 100644 src/gql/query/proxies.ts diff --git a/src/gql/heart-monitor/heart-monitor.test.ts b/src/gql/heart-monitor/heart-monitor.test.ts index d86a020c..329564af 100644 --- a/src/gql/heart-monitor/heart-monitor.test.ts +++ b/src/gql/heart-monitor/heart-monitor.test.ts @@ -101,6 +101,8 @@ import { QueryMarketingMutationArgs, GQLMarketingMutationFields, defaultAccountLinksInfo, + defaultProxy, + GQLProxies, } from ".." const nibiruUrl = "testnet-1" @@ -863,6 +865,22 @@ test("perpPositionsSubscription", async () => { ) }) +const testProxies = async (fields?: GQLProxies) => { + const resp = await heartMonitor.proxies(fields) + expect(resp).toHaveProperty("proxies") + + if (resp.proxies) { + const { proxies } = resp + + checkFields([proxies], ["bybit"]) + } +} + +test("proxies", async () => { + await testProxies(defaultProxy) + await testProxies() +}) + test("queryBatchHandler", async () => { // TODO: Make a partial type that includes all of these const resp = await heartMonitor.GQLQueryGqlBatchHandler<{ diff --git a/src/gql/heart-monitor/heart-monitor.ts b/src/gql/heart-monitor/heart-monitor.ts index 91e0c9c2..3705a5d9 100644 --- a/src/gql/heart-monitor/heart-monitor.ts +++ b/src/gql/heart-monitor/heart-monitor.ts @@ -112,6 +112,9 @@ import { DeepPartial, QueryMarketingMutationArgs, GQLMarketingMutationFields, + GQLProxies, + GqlOutProxies, + proxies, } from ".." /** IHeartMonitor is an interface for a Heart Monitor GraphQL API. @@ -207,6 +210,8 @@ export interface IHeartMonitor { AsyncIterableIterator> | undefined > + readonly proxies: (fields?: DeepPartial) => Promise + readonly GQLQueryGqlBatchHandler: ( queryQueryStrings: string[] ) => Promise @@ -374,6 +379,9 @@ export class HeartMonitor implements IHeartMonitor { fields?: DeepPartial ) => perpPositionsSubscription(args, this.subscriptionClient, fields) + proxies = async (fields?: DeepPartial) => + proxies(this.gqlEndpt, fields) + GQLQueryGqlBatchHandler = async (queryQueryStrings: string[]) => queryBatchHandler(queryQueryStrings, this.gqlEndpt) diff --git a/src/gql/query/index.ts b/src/gql/query/index.ts index fd5d833e..541fbff4 100644 --- a/src/gql/query/index.ts +++ b/src/gql/query/index.ts @@ -13,6 +13,7 @@ export * from "./markPriceCandles" export * from "./marketing" export * from "./oracle" export * from "./perp" +export * from "./proxies" export * from "./redelegations" export * from "./spotLpPositions" export * from "./spotPoolCreated" diff --git a/src/gql/query/proxies.ts b/src/gql/query/proxies.ts new file mode 100644 index 00000000..78ceaf92 --- /dev/null +++ b/src/gql/query/proxies.ts @@ -0,0 +1,33 @@ +import { + defaultProxy, + convertObjectToPropertiesString, + doGqlQuery, + gqlQuery, + GQLQuery, + DeepPartial, + GQLProxies, +} from ".." + +export interface GqlOutProxies { + proxies?: GQLQuery["proxies"] +} + +export const proxiesQueryString = ( + excludeParentObject: boolean, + fields?: DeepPartial +) => { + return gqlQuery( + "proxies", + {}, + fields + ? convertObjectToPropertiesString(fields) + : convertObjectToPropertiesString(defaultProxy), + excludeParentObject + ) +} + +export const proxies = async ( + endpt: string, + fields?: DeepPartial +): Promise => + doGqlQuery(proxiesQueryString(false, fields), endpt) diff --git a/src/gql/utils/defaultObjects.ts b/src/gql/utils/defaultObjects.ts index 8a6916af..732dfc5e 100644 --- a/src/gql/utils/defaultObjects.ts +++ b/src/gql/utils/defaultObjects.ts @@ -23,6 +23,7 @@ import { GQLPerpMarket, GQLPerpPosition, GQLPerpPositionChange, + GQLProxies, GQLRedelegation, GQLSpotLpPosition, GQLSpotPool, @@ -509,3 +510,20 @@ export const defaultAccountLinksInfo: GQLAccountLinksInfo = { discordId: "", twitterUser: defaultTwitterUser, } + +export const defaultProxy: GQLProxies = { + bybit: { + ask1Price: "", + ask1Size: "", + bid1Price: "", + bid1Size: "", + highPrice24h: "", + lastPrice: "", + lowPrice24h: "", + prevPrice24h: "", + price24hPcnt: "", + symbol: "", + turnover24h: "", + volume24h: "", + }, +}