交易历史
StableFX 中的每笔外汇交易都遵循从报价请求(RFQ)到最终结算的定义生命周期。本页介绍 ForexTradeRecord 类型、ForexTradeStatus 生命周期,以及如何获取和显示交易历史。
交易生命周期
StableFX 交易按照以下状态流转:
RFQ ──> QUOTED ──> MATCHED ──> SETTLED
| | |
| | +──> FAILED
| +──> FAILED
+──> FAILED
| 状态 | 描述 |
|---|---|
RFQ | 报价请求已提交。系统正在从流动性池中获取报价。 |
QUOTED | 已收到报价。价格在短时间窗口内被锁定。 |
MATCHED | 交易已与对手方匹配。结算进行中。 |
SETTLED | 交易成功完成。资金已分配。 |
FAILED | 交易在任何阶段失败。清算池中的资金将被退回。 |
ForexTradeStatus 类型
import type { ForexTradeStatus } from '@one_deploy/sdk';
type ForexTradeStatus = 'RFQ' | 'QUOTED' | 'MATCHED' | 'SETTLED' | 'FAILED';
ForexTradeRecord 类型
import type { ForexTradeRecord } from '@one_deploy/sdk';
interface ForexTradeRecord {
/** Unique trade identifier. */
id: string;
/** The investment this trade belongs to. */
investmentId: string;
/** Currency pair traded, e.g. "EUR/USD". */
currencyPair: string;
/** Trade direction. */
side: 'buy' | 'sell';
/** Trade amount in base currency units. */
amount: number;
/** Quoted price at time of trade. */
quotePrice: number;
/** Execution price (may differ from quotePrice due to slippage). */
executionPrice: number | null;
/** Current trade status. */
status: ForexTradeStatus;
/** Realized profit or loss (in USDC), set after settlement. */
pnl: number | null;
/** Fee charged for this trade (in USDC). */
fee: number;
/** Slippage between quote and execution price (decimal). */
slippage: number | null;
/** ISO-8601 timestamp when the RFQ was submitted. */
createdAt: string;
/** ISO-8601 timestamp when the trade was last updated. */
updatedAt: string;
/** ISO-8601 timestamp when the trade was settled, if applicable. */
settledAt: string | null;
/** On-chain transaction hash, if applicable. */
txHash: string | null;
/** Reason for failure, if status is FAILED. */
failureReason: string | null;
}
获取交易历史
交易记录可通过 useForexInvestments hook 的投资数据获取,也可直接通过 useForexTrading hook 获取。
使用 useForexTrading
import { useForexTrading } from '@one_deploy/sdk';
function useTradeHistory() {
const { getTradeHistory } = useForexTrading();
const fetchTrades = async (investmentId: string) => {
const trades = await getTradeHistory({
investmentId,
limit: 50,
offset: 0,
});
return trades;
};
return { fetchTrades };
}