artifacts-dashboard/frontend/src/hooks/use-exchange.ts
Paweł Orzech 2484a40dbd
Fix Grand Exchange: use public browse endpoint, fix price capture, add proper tabs
- Market tab now calls GET /grandexchange/orders (all public orders) instead of
  /my/grandexchange/orders (own orders only), fixing the empty exchange issue
- Fix capture_prices reading "type" field instead of wrong "order" field
- Add proper pagination to all GE queries via _get_paginated
- Separate My Orders (active own orders) from Trade History (transaction log)
- Add GEHistoryEntry type matching GeOrderHistorySchema (order_id, seller, buyer, sold_at)
- Add /api/exchange/my-orders and /api/exchange/sell-history endpoints
- Exchange page now has 4 tabs: Market, My Orders, Trade History, Price History
2026-03-01 20:38:19 +01:00

53 lines
1.3 KiB
TypeScript

"use client";
import { useQuery } from "@tanstack/react-query";
import {
getExchangeOrders,
getMyOrders,
getExchangeHistory,
getSellHistory,
getPriceHistory,
} from "@/lib/api-client";
import type { GEOrder, GEHistoryEntry, PricePoint } from "@/lib/types";
export function useExchangeOrders() {
return useQuery<GEOrder[]>({
queryKey: ["exchange", "orders"],
queryFn: getExchangeOrders,
refetchInterval: 10000,
});
}
export function useMyOrders() {
return useQuery<GEOrder[]>({
queryKey: ["exchange", "my-orders"],
queryFn: getMyOrders,
refetchInterval: 10000,
});
}
export function useExchangeHistory() {
return useQuery<GEHistoryEntry[]>({
queryKey: ["exchange", "history"],
queryFn: getExchangeHistory,
refetchInterval: 30000,
});
}
export function useSellHistory(itemCode: string) {
return useQuery<GEHistoryEntry[]>({
queryKey: ["exchange", "sell-history", itemCode],
queryFn: () => getSellHistory(itemCode),
enabled: !!itemCode,
refetchInterval: 30000,
});
}
export function usePriceHistory(itemCode: string) {
return useQuery<PricePoint[]>({
queryKey: ["exchange", "prices", itemCode],
queryFn: () => getPriceHistory(itemCode),
enabled: !!itemCode,
refetchInterval: 30000,
});
}