Skip to content

Commit

Permalink
Moved trading view chart data to queries
Browse files Browse the repository at this point in the history
  • Loading branch information
dkildar committed Dec 27, 2024
1 parent b6ab50c commit 992d12f
Show file tree
Hide file tree
Showing 12 changed files with 183 additions and 230 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"diff-match-patch": "^1.0.5",
"emoji-mart": "^5.5.2",
"framer-motion": "^11.3.24",
"highcharts": "^11.4.5",
"highcharts": "^12.1.2",
"highcharts-react-official": "^3.2.1",
"hive-uri": "^0.2.5",
"hivesigner": "^3.3.4",
Expand Down
3 changes: 0 additions & 3 deletions src/api/hive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ export const getTradeHistory = (limit: number = 1000): Promise<OrdersDataItem[]>
limit
]);

export const getMarketBucketSizes = (): Promise<number[]> =>
client.call("condenser_api", "get_market_history_buckets", []);

export const getMarketHistory = (
seconds: number,
startDate: Date,
Expand Down
3 changes: 2 additions & 1 deletion src/app/market/advanced/_components/api/index.ts
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";
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 src/app/market/advanced/_components/api/trading-view-api.ts

This file was deleted.

46 changes: 46 additions & 0 deletions src/app/market/advanced/_components/api/trading-view-query.ts
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")
]
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const MarketAdvancedModeWidgetHeader = ({
</div>
</div>
{settings ? (
<AccordionCollapse eventKey="0">
<AccordionCollapse overflowHidden={false} eventKey="0">
<div className="p-0 market-advanced-mode-widget-settings">{settings}</div>
</AccordionCollapse>
) : (
Expand Down
Loading

0 comments on commit 992d12f

Please sign in to comment.