-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved trading view chart data to queries
- Loading branch information
Showing
12 changed files
with
183 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./trading-view-api"; | ||
export * from "./trading-view-query"; | ||
export * from "./market-bucket-size-query"; |
11 changes: 11 additions & 0 deletions
11
src/app/market/advanced/_components/api/market-bucket-size-query.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { QueryIdentifiers } from "@/core/react-query"; | ||
import { client } from "@/api/hive"; | ||
|
||
export function useMarketBucketSizeQuery() { | ||
return useQuery({ | ||
queryKey: [QueryIdentifiers.MARKET_BUCKET_SIZE], | ||
queryFn: () => | ||
client.call("condenser_api", "get_market_history_buckets", []) as Promise<number[]> | ||
}); | ||
} |
49 changes: 0 additions & 49 deletions
49
src/app/market/advanced/_components/api/trading-view-api.ts
This file was deleted.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
src/app/market/advanced/_components/api/trading-view-query.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import moment from "moment/moment"; | ||
import { MarketCandlestickDataItem } from "@/entities"; | ||
import { useInfiniteQuery } from "@tanstack/react-query"; | ||
import { QueryIdentifiers } from "@/core/react-query"; | ||
import { getMarketHistory } from "@/api/hive"; | ||
import { Time } from "lightweight-charts"; | ||
|
||
export interface TradingViewQueryDataItem { | ||
close: number; | ||
open: number; | ||
low: number; | ||
high: number; | ||
volume: number; | ||
time: Time; | ||
} | ||
|
||
export function useTradingViewQuery(bucketSeconds: number) { | ||
return useInfiniteQuery({ | ||
queryKey: [QueryIdentifiers.MARKET_TRADING_VIEW, bucketSeconds], | ||
queryFn: async ({ pageParam: [startDate, endDate] }) => { | ||
const apiData: MarketCandlestickDataItem[] = await getMarketHistory( | ||
bucketSeconds, | ||
startDate.toDate(), | ||
endDate.toDate() | ||
); | ||
|
||
return apiData.map(({ hive, non_hive, open }) => ({ | ||
close: non_hive.close / hive.close, | ||
open: non_hive.open / hive.open, | ||
low: non_hive.low / hive.low, | ||
high: non_hive.high / hive.high, | ||
volume: hive.volume, | ||
time: Math.floor(moment(open).toDate().getTime() / 1000) as Time | ||
})); | ||
}, | ||
initialPageParam: [ | ||
// Fetch at least 8 hours or given interval | ||
moment().subtract(Math.max(100 * bucketSeconds, 28_800), "seconds"), | ||
moment() | ||
], | ||
getNextPageParam: (_, __, [prevStartDate]) => [ | ||
prevStartDate.clone().subtract(Math.max(100 * bucketSeconds, 28_800), "seconds"), | ||
prevStartDate.subtract(bucketSeconds, "seconds") | ||
] | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.