Skip to content

Commit

Permalink
feat: proxy prices (#343) (#344)
Browse files Browse the repository at this point in the history
* feat: proxy prices (#343)

* fix: test name
  • Loading branch information
cgilbe27 authored Apr 1, 2024
1 parent e4b97cb commit b4ab83c
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/gql/heart-monitor/heart-monitor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ import {
QueryMarketingMutationArgs,
GQLMarketingMutationFields,
defaultAccountLinksInfo,
defaultProxy,
GQLProxies,
} from ".."

const nibiruUrl = "testnet-1"
Expand Down Expand Up @@ -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<{
Expand Down
8 changes: 8 additions & 0 deletions src/gql/heart-monitor/heart-monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ import {
DeepPartial,
QueryMarketingMutationArgs,
GQLMarketingMutationFields,
GQLProxies,
GqlOutProxies,
proxies,
} from ".."

/** IHeartMonitor is an interface for a Heart Monitor GraphQL API.
Expand Down Expand Up @@ -207,6 +210,8 @@ export interface IHeartMonitor {
AsyncIterableIterator<ExecutionResult<GqlOutPerpPositions>> | undefined
>

readonly proxies: (fields?: DeepPartial<GQLProxies>) => Promise<GqlOutProxies>

readonly GQLQueryGqlBatchHandler: <T>(
queryQueryStrings: string[]
) => Promise<T>
Expand Down Expand Up @@ -374,6 +379,9 @@ export class HeartMonitor implements IHeartMonitor {
fields?: DeepPartial<GQLPerpPosition>
) => perpPositionsSubscription(args, this.subscriptionClient, fields)

proxies = async (fields?: DeepPartial<GQLProxies>) =>
proxies(this.gqlEndpt, fields)

GQLQueryGqlBatchHandler = async <T>(queryQueryStrings: string[]) =>
<T>queryBatchHandler(queryQueryStrings, this.gqlEndpt)

Expand Down
1 change: 1 addition & 0 deletions src/gql/query/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
33 changes: 33 additions & 0 deletions src/gql/query/proxies.ts
Original file line number Diff line number Diff line change
@@ -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<GQLProxies>
) => {
return gqlQuery(
"proxies",
{},
fields
? convertObjectToPropertiesString(fields)
: convertObjectToPropertiesString(defaultProxy),
excludeParentObject
)
}

export const proxies = async (
endpt: string,
fields?: DeepPartial<GQLProxies>
): Promise<GqlOutProxies> =>
doGqlQuery(proxiesQueryString(false, fields), endpt)
18 changes: 18 additions & 0 deletions src/gql/utils/defaultObjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
GQLPerpMarket,
GQLPerpPosition,
GQLPerpPositionChange,
GQLProxies,
GQLRedelegation,
GQLSpotLpPosition,
GQLSpotPool,
Expand Down Expand Up @@ -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: "",
},
}

1 comment on commit b4ab83c

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines Statements Branches Functions
Coverage: 88%
90.31% (1277/1414) 79.85% (543/680) 78.5% (314/400)

Please sign in to comment.