xtraderClient/src/api/pnlCurve.ts
马丁 d3f237168c 新增:钱包页交易盈亏曲线,并对齐 Polymarket 双卡布局。
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-26 17:16:15 +08:00

43 lines
1.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)}`
}