mango-ui-v3/utils/chartDataConnector.tsx

47 lines
1.2 KiB
TypeScript
Raw Normal View History

2021-04-05 13:48:24 -07:00
import { ChartTradeType } from '../@types/types'
2021-11-05 06:49:51 -07:00
const baseUrl = 'https://event-history-api-candles.herokuapp.com'
// const baseUrl = 'http://localhost:4000'
2021-04-02 11:26:21 -07:00
export default class ChartApi {
static URL = `${baseUrl}/`
static async get(path: string) {
try {
2021-08-19 19:47:25 -07:00
const response = await fetch(this.URL + path)
if (response.ok) {
const responseJson = await response.json()
return responseJson.success
? responseJson.data
: responseJson
? responseJson
: null
}
} catch (err) {
2021-04-02 11:26:21 -07:00
console.log(`Error fetching from Chart API ${path}: ${err}`)
}
return null
}
static async getRecentTrades(
marketAddress: string
2021-04-05 13:48:24 -07:00
): Promise<ChartTradeType[] | null> {
2022-03-28 08:13:54 -07:00
if (!marketAddress) return null
2021-04-02 11:26:21 -07:00
return ChartApi.get(`trades/address/${marketAddress}`)
}
static async getOhlcv(
symbol: string,
resolution: string,
from: number,
to: number
): Promise<ChartTradeType[] | null> {
2022-03-28 08:13:54 -07:00
if (!symbol) return null
return ChartApi.get(
`tv/history?symbol=${symbol}&resolution=${resolution}&from=${from}&to=${to}`
)
}
}
2021-04-02 11:26:21 -07:00
export const CHART_DATA_FEED = `${baseUrl}/tv`