43 lines
1.0 KiB
TypeScript
43 lines
1.0 KiB
TypeScript
import { get } from './request'
|
||
import type { ApiResponse } from './types'
|
||
|
||
export type PnlCurveRange = '1D' | '1W' | '1M' | '1Y' | 'YTD' | 'ALL'
|
||
|
||
export interface PnlCurvePoint {
|
||
ts: number
|
||
pnl: number
|
||
}
|
||
|
||
export interface PnlCurveData {
|
||
range: PnlCurveRange
|
||
startTs: number
|
||
endTs: number
|
||
currentPnl: number
|
||
changeAmount: number
|
||
changePercent: number
|
||
noHistory: boolean
|
||
points: PnlCurvePoint[]
|
||
}
|
||
|
||
export interface PnlCurveResponse extends ApiResponse {
|
||
data: PnlCurveData
|
||
}
|
||
|
||
/**
|
||
* GET /uas/getPnlCurveClient
|
||
* 获取用户交易盈亏曲线(卖出 − 买入 USDC)
|
||
*/
|
||
export async function getPnlCurve(
|
||
range: PnlCurveRange,
|
||
config?: { headers?: Record<string, string> },
|
||
): Promise<PnlCurveResponse> {
|
||
return get<PnlCurveResponse>('/uas/getPnlCurveClient', { range }, config)
|
||
}
|
||
|
||
export const PNL_CURVE_RANGES: PnlCurveRange[] = ['1D', '1W', '1M', '1Y', 'YTD', 'ALL']
|
||
|
||
export function formatPnlAmount(amount: number): string {
|
||
const sign = amount > 0 ? '+' : amount < 0 ? '-' : ''
|
||
return `${sign}$${Math.abs(amount).toFixed(2)}`
|
||
}
|