chore: fix candles queries
This commit is contained in:
@@ -15,10 +15,7 @@ export const PageQueryContainer = <TData, TVariables = OperationVariables>({
|
||||
options,
|
||||
render,
|
||||
}: PageQueryContainerProps<TData, TVariables>) => {
|
||||
const { data, loading, error } = useQuery<TData, TVariables>(query, {
|
||||
...options,
|
||||
errorPolicy: 'ignore',
|
||||
});
|
||||
const { data, loading, error } = useQuery<TData, TVariables>(query, options);
|
||||
|
||||
return (
|
||||
<AsyncRenderer<TData>
|
||||
|
||||
-113
@@ -1,113 +0,0 @@
|
||||
import { Schema as Types } from '@vegaprotocol/types';
|
||||
|
||||
import { gql } from '@apollo/client';
|
||||
import * as Apollo from '@apollo/client';
|
||||
const defaultOptions = {} as const;
|
||||
export type CandleFieldsFragment = { __typename?: 'Candle', timestamp: string, high: string, low: string, open: string, close: string, volume: string };
|
||||
|
||||
export type CandlesQueryVariables = Types.Exact<{
|
||||
marketId: Types.Scalars['ID'];
|
||||
interval: Types.Interval;
|
||||
since: Types.Scalars['String'];
|
||||
}>;
|
||||
|
||||
|
||||
export type CandlesQuery = { __typename?: 'Query', market?: { __typename?: 'Market', id: string, decimalPlaces: number, tradableInstrument: { __typename?: 'TradableInstrument', instrument: { __typename?: 'Instrument', id: string, name: string, code: string } }, candles?: Array<{ __typename?: 'Candle', timestamp: string, high: string, low: string, open: string, close: string, volume: string } | null> | null } | null };
|
||||
|
||||
export type CandlesEventsSubscriptionVariables = Types.Exact<{
|
||||
marketId: Types.Scalars['ID'];
|
||||
interval: Types.Interval;
|
||||
}>;
|
||||
|
||||
|
||||
export type CandlesEventsSubscription = { __typename?: 'Subscription', candles: { __typename?: 'Candle', timestamp: string, high: string, low: string, open: string, close: string, volume: string } };
|
||||
|
||||
export const CandleFieldsFragmentDoc = gql`
|
||||
fragment CandleFields on Candle {
|
||||
periodStart
|
||||
high
|
||||
low
|
||||
open
|
||||
close
|
||||
volume
|
||||
}
|
||||
`;
|
||||
export const CandlesDocument = gql`
|
||||
query Candles($marketId: ID!, $interval: Interval!, $since: String!) {
|
||||
market(id: $marketId) {
|
||||
id
|
||||
decimalPlaces
|
||||
tradableInstrument {
|
||||
instrument {
|
||||
id
|
||||
name
|
||||
code
|
||||
}
|
||||
}
|
||||
candles(interval: $interval, since: $since) {
|
||||
...CandleFields
|
||||
}
|
||||
}
|
||||
}
|
||||
${CandleFieldsFragmentDoc}`;
|
||||
|
||||
/**
|
||||
* __useCandlesQuery__
|
||||
*
|
||||
* To run a query within a React component, call `useCandlesQuery` and pass it any options that fit your needs.
|
||||
* When your component renders, `useCandlesQuery` returns an object from Apollo Client that contains loading, error, and data properties
|
||||
* you can use to render your UI.
|
||||
*
|
||||
* @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
|
||||
*
|
||||
* @example
|
||||
* const { data, loading, error } = useCandlesQuery({
|
||||
* variables: {
|
||||
* marketId: // value for 'marketId'
|
||||
* interval: // value for 'interval'
|
||||
* since: // value for 'since'
|
||||
* },
|
||||
* });
|
||||
*/
|
||||
export function useCandlesQuery(baseOptions: Apollo.QueryHookOptions<CandlesQuery, CandlesQueryVariables>) {
|
||||
const options = {...defaultOptions, ...baseOptions}
|
||||
return Apollo.useQuery<CandlesQuery, CandlesQueryVariables>(CandlesDocument, options);
|
||||
}
|
||||
export function useCandlesLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<CandlesQuery, CandlesQueryVariables>) {
|
||||
const options = {...defaultOptions, ...baseOptions}
|
||||
return Apollo.useLazyQuery<CandlesQuery, CandlesQueryVariables>(CandlesDocument, options);
|
||||
}
|
||||
export type CandlesQueryHookResult = ReturnType<typeof useCandlesQuery>;
|
||||
export type CandlesLazyQueryHookResult = ReturnType<typeof useCandlesLazyQuery>;
|
||||
export type CandlesQueryResult = Apollo.QueryResult<CandlesQuery, CandlesQueryVariables>;
|
||||
export const CandlesEventsDocument = gql`
|
||||
subscription CandlesEvents($marketId: ID!, $interval: Interval!) {
|
||||
candles(marketId: $marketId, interval: $interval) {
|
||||
...CandleFields
|
||||
}
|
||||
}
|
||||
${CandleFieldsFragmentDoc}`;
|
||||
|
||||
/**
|
||||
* __useCandlesEventsSubscription__
|
||||
*
|
||||
* To run a query within a React component, call `useCandlesEventsSubscription` and pass it any options that fit your needs.
|
||||
* When your component renders, `useCandlesEventsSubscription` returns an object from Apollo Client that contains loading, error, and data properties
|
||||
* you can use to render your UI.
|
||||
*
|
||||
* @param baseOptions options that will be passed into the subscription, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
|
||||
*
|
||||
* @example
|
||||
* const { data, loading, error } = useCandlesEventsSubscription({
|
||||
* variables: {
|
||||
* marketId: // value for 'marketId'
|
||||
* interval: // value for 'interval'
|
||||
* },
|
||||
* });
|
||||
*/
|
||||
export function useCandlesEventsSubscription(baseOptions: Apollo.SubscriptionHookOptions<CandlesEventsSubscription, CandlesEventsSubscriptionVariables>) {
|
||||
const options = {...defaultOptions, ...baseOptions}
|
||||
return Apollo.useSubscription<CandlesEventsSubscription, CandlesEventsSubscriptionVariables>(CandlesEventsDocument, options);
|
||||
}
|
||||
export type CandlesEventsSubscriptionHookResult = ReturnType<typeof useCandlesEventsSubscription>;
|
||||
export type CandlesEventsSubscriptionResult = Apollo.SubscriptionResult<CandlesEventsSubscription>;
|
||||
-55
@@ -1,55 +0,0 @@
|
||||
import { Schema as Types } from '@vegaprotocol/types';
|
||||
|
||||
import { gql } from '@apollo/client';
|
||||
import * as Apollo from '@apollo/client';
|
||||
const defaultOptions = {} as const;
|
||||
export type ChartQueryVariables = Types.Exact<{
|
||||
marketId: Types.Scalars['ID'];
|
||||
}>;
|
||||
|
||||
|
||||
export type ChartQuery = { __typename?: 'Query', market?: { __typename?: 'Market', decimalPlaces: number, data?: { __typename?: 'MarketData', priceMonitoringBounds?: Array<{ __typename?: 'PriceMonitoringBounds', minValidPrice: string, maxValidPrice: string, referencePrice: string }> | null } | null } | null };
|
||||
|
||||
|
||||
export const ChartDocument = gql`
|
||||
query Chart($marketId: ID!) {
|
||||
market(id: $marketId) {
|
||||
decimalPlaces
|
||||
data {
|
||||
priceMonitoringBounds {
|
||||
minValidPrice
|
||||
maxValidPrice
|
||||
referencePrice
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
/**
|
||||
* __useChartQuery__
|
||||
*
|
||||
* To run a query within a React component, call `useChartQuery` and pass it any options that fit your needs.
|
||||
* When your component renders, `useChartQuery` returns an object from Apollo Client that contains loading, error, and data properties
|
||||
* you can use to render your UI.
|
||||
*
|
||||
* @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
|
||||
*
|
||||
* @example
|
||||
* const { data, loading, error } = useChartQuery({
|
||||
* variables: {
|
||||
* marketId: // value for 'marketId'
|
||||
* },
|
||||
* });
|
||||
*/
|
||||
export function useChartQuery(baseOptions: Apollo.QueryHookOptions<ChartQuery, ChartQueryVariables>) {
|
||||
const options = {...defaultOptions, ...baseOptions}
|
||||
return Apollo.useQuery<ChartQuery, ChartQueryVariables>(ChartDocument, options);
|
||||
}
|
||||
export function useChartLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<ChartQuery, ChartQueryVariables>) {
|
||||
const options = {...defaultOptions, ...baseOptions}
|
||||
return Apollo.useLazyQuery<ChartQuery, ChartQueryVariables>(ChartDocument, options);
|
||||
}
|
||||
export type ChartQueryHookResult = ReturnType<typeof useChartQuery>;
|
||||
export type ChartLazyQueryHookResult = ReturnType<typeof useChartLazyQuery>;
|
||||
export type ChartQueryResult = Apollo.QueryResult<ChartQuery, ChartQueryVariables>;
|
||||
@@ -1,21 +1,22 @@
|
||||
import compact from 'lodash/compact';
|
||||
import type { ApolloClient } from '@apollo/client';
|
||||
import type { Candle, DataSource } from 'pennant';
|
||||
import { Interval as PennantInterval } from 'pennant';
|
||||
|
||||
import { addDecimal } from '@vegaprotocol/react-helpers';
|
||||
import { ChartDocument } from './__generated__/Chart';
|
||||
import type { ChartQuery, ChartQueryVariables } from './__generated__/Chart';
|
||||
import { ChartDocument } from './__generated___/Chart';
|
||||
import type { ChartQuery, ChartQueryVariables } from './__generated___/Chart';
|
||||
import {
|
||||
CandlesDocument,
|
||||
CandlesEventsDocument,
|
||||
} from './__generated__/Candles';
|
||||
} from './__generated___/Candles';
|
||||
import type {
|
||||
CandlesQuery,
|
||||
CandlesQueryVariables,
|
||||
CandleFieldsFragment,
|
||||
CandlesEventsSubscription,
|
||||
CandlesEventsSubscriptionVariables,
|
||||
} from './__generated__/Candles';
|
||||
} from './__generated___/Candles';
|
||||
import type { Subscription } from 'zen-observable-ts';
|
||||
import { Interval } from '@vegaprotocol/types';
|
||||
|
||||
@@ -142,14 +143,15 @@ export class VegaDataSource implements DataSource {
|
||||
},
|
||||
fetchPolicy: 'no-cache',
|
||||
});
|
||||
console.log(data);
|
||||
|
||||
if (data && data.market && data.market.candles) {
|
||||
if (data && data.market && data.market.candlesConnection) {
|
||||
const decimalPlaces = data.market.decimalPlaces;
|
||||
|
||||
const candles = data.market.candles
|
||||
const candles = compact(data.market.candlesConnection.edges)
|
||||
.map((e) => e.node)
|
||||
.filter((d): d is CandleFieldsFragment => d !== null)
|
||||
.map((d) => parseCandle(d, decimalPlaces));
|
||||
|
||||
return candles;
|
||||
} else {
|
||||
return [];
|
||||
@@ -198,8 +200,9 @@ function parseCandle(
|
||||
candle: CandleFieldsFragment,
|
||||
decimalPlaces: number
|
||||
): Candle {
|
||||
console.log(candle);
|
||||
return {
|
||||
date: new Date(Number(candle.timestamp) / 1_000_000),
|
||||
date: new Date(candle.periodStart),
|
||||
high: Number(addDecimal(candle.high, decimalPlaces)),
|
||||
low: Number(addDecimal(candle.low, decimalPlaces)),
|
||||
open: Number(addDecimal(candle.open, decimalPlaces)),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export * from './__generated__/Candles';
|
||||
export * from './__generated__/Chart';
|
||||
export * from './__generated___/Candles';
|
||||
export * from './__generated___/Chart';
|
||||
export * from './candles-chart';
|
||||
export * from './data-source';
|
||||
|
||||
Reference in New Issue
Block a user