12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- import { PacificaClient } from './PacificaClient'
- export class PacificaRestAdapter {
- constructor(private client: PacificaClient) {}
- async getPrices() {
- const response = await this.client.getPublic<any>('/api/v1/info/prices')
- const data = response?.data ?? response
- return Array.isArray(data) ? data : []
- }
- async getFundingHistory(params: { symbol: string; limit?: number; offset?: number }) {
- const { symbol, limit, offset } = params
- const qs = [`symbol=${symbol}`]
- if (limit !== undefined) qs.push(`limit=${limit}`)
- if (offset !== undefined) qs.push(`offset=${offset}`)
- const response = await this.client.getPublic<any>(`/api/v1/funding_rate/history?${qs.join('&')}`)
- const data = response?.data ?? response
- return Array.isArray(data) ? data : []
- }
- async getMarketInfo(symbol?: string) {
- const response = await this.client.getPublic<any>(this.client.endpoints.symbols)
- const data = response?.data ?? response
- if (!Array.isArray(data)) return data
- return symbol ? data.find(item => String(item.symbol) === symbol) : data
- }
- async getOrderBook(params: { symbol: string; aggLevel?: number }) {
- const url = `${this.client.endpoints.depth}?symbol=${params.symbol}&agg_level=${params.aggLevel ?? 1}`
- const response = await this.client.getPublic<any>(url)
- const payload = response?.data ?? response
- return {
- symbol: payload?.s,
- bids: Array.isArray(payload?.l?.[0])
- ? payload.l[0].map((lvl: any) => ({
- price: String(lvl?.p ?? ''),
- amount: String(lvl?.a ?? ''),
- count: lvl?.n ?? 0,
- }))
- : [],
- asks: Array.isArray(payload?.l?.[1])
- ? payload.l[1].map((lvl: any) => ({
- price: String(lvl?.p ?? ''),
- amount: String(lvl?.a ?? ''),
- count: lvl?.n ?? 0,
- }))
- : [],
- timestamp: Number(payload?.t ?? Date.now()),
- }
- }
- }
|