跳至主要内容

AI 交易概览

ONE SDK(@one_deploy/sdk v1.1.0)包含一个完整的 AI 驱动交易代理系统。AI 代理代表用户执行算法交易策略,可在多条链和多个交易对上运行,并支持可配置的风险配置和投资周期。

架构

+------------------------------------------------------------------+
| Your Application |
+------------------------------------------------------------------+
| React Native | Web / Node (API only) |
| - OneChainSelector | - OneEngineClient |
| - OneTierSelector | AI trading methods |
| - OneCycleSelector | - useAIStrategies |
| - OnePairSelector | - useAIPortfolio |
+------------------------------------------------------------------+
| @one_deploy/sdk |
| +---------------------------+ +-----------------------------+ |
| | AI Trading Hooks | | AI Trading API | |
| | - useAIStrategies | | - getAIStrategies | |
| | - useAIStrategy | | - createAIOrder | |
| | - useAIOrders | | - pauseAIOrder | |
| | - useAIPortfolio | | - resumeAIOrder | |
| | - useAIMarketData | | - redeemAIOrder | |
| | - useAITrading | | - getAIPortfolio | |
| +---------------------------+ +-----------------------------+ |
| +----------------------------------------------------------+ |
| | botSimulationEngine (P&L projections) | |
| +----------------------------------------------------------+ |
+------------------------------------------------------------------+
| |
v v
ONE Engine API Blockchain Networks
engine.one23.io (Base, Ethereum, etc.)

认证:独立 Token 管理

重要提示

AI 交易的 hook 和 API 方法使用独立 token 管理,而非 OneProvider。在调用任何 AI 交易方法之前,您必须使用 setAITradingAccessToken 显式设置访问 token,并在用户退出登录时使用 clearAITradingAccessToken 清除 token。

import {
setAITradingAccessToken,
clearAITradingAccessToken,
} from '@one_deploy/sdk';

// After your user authenticates, set the token
const token = await authenticateUser(); // your auth flow
setAITradingAccessToken(token);

// All AI trading hooks and API calls now use this token
// ...

// On sign-out, clear the token
clearAITradingAccessToken();

这种设计允许 AI 交易功能独立于基于 provider 的认证系统运行,这在不使用 OneProvider 的 React Native 应用中特别有用。

策略类别

每个 AI 策略都属于一个 StrategyCategory。每个类别代表不同的算法方法和风险/收益配置。

type StrategyCategory =
| 'conservative'
| 'balanced'
| 'aggressive'
| 'hedge'
| 'arbitrage'
| 'trend'
| 'grid'
| 'dca';
类别描述典型风险
conservative以资本保值为主,低回撤容忍度
balanced适度敞口,主动再平衡
aggressive高确信度持仓,止损范围较宽
hedgeDelta 中性或对冲持仓,降低市场敞口低-中
arbitrage利用不同交易场所或跨链的价格差异
trend趋势跟踪算法,捕捉持续行情中-高
grid在价格区间内分层挂买卖单
dca定投策略 -- 将入场分散到多个时间段低-中

风险等级

RiskLevel 类型表示分配给策略或订单的整体风险分类。

type RiskLevel = 'conservative' | 'moderate' | 'aggressive';
风险等级最大回撤仓位规模描述
conservative5-10%小(每笔交易 1-3%)优先保护资本
moderate10-20%中(每笔交易 3-7%)风险与收益平衡
aggressive20-40%大(每笔交易 7-15%)追求最大收益,接受波动

交易操作

TradeAction 类型列举了 AI 代理可以对持仓执行的所有操作。

type TradeAction =
| 'buy'
| 'sell'
| 'long'
| 'short'
| 'close_long'
| 'close_short';
操作方向描述
buy做多开立现货买入仓位
sell--平仓或止盈
long做多开立杠杆多头(永续合约)
short做空开立杠杆空头(永续合约)
close_long--平掉多头仓位
close_short--平掉空头仓位

订单生命周期

AI 交易订单会经历以下状态变迁:

  pending ──> active ──> completed
│ │
├──> paused │
│ │ │
│ └──> active (resumed)

└──> redeemed (early withdrawal)
type AIOrderStatus =
| 'pending'
| 'active'
| 'paused'
| 'completed'
| 'redeemed'
| 'failed';

构建流程

创建 AI 交易订单遵循逐步构建的流程。SDK 为每个步骤提供了专用的选择器组件。

Select Strategy ──> Select Chain ──> Select Tier ──> Select Cycle ──> Select Pair ──> Set Amount ──> Create Order
│ │ │ │ │
v v v v v
useAIStrategies OneChainSelector OneTierSelector OneCycleSelector OnePairSelector

主要导出

import {
// Authentication
setAITradingAccessToken,
clearAITradingAccessToken,

// Hooks
useAIStrategies,
useAIStrategy,
useAIOrders,
useAIPortfolio,
useAIMarketData,
useAITrading,

// Components (React Native)
OneChainSelector,
OneTierSelector,
OneCycleSelector,
OnePairSelector,

// API client
OneEngineClient,

// Simulation
botSimulationEngine,

// Constants
CHAIN_CONFIG,
PAIR_ICONS,
DEFAULT_SHARE_RATES,

// Types
type StrategyCategory,
type RiskLevel,
type TradeAction,
type AIOrderStatus,
type AIStrategy,
type AIOrder,
type AIPortfolioSummary,
type AINavSnapshot,
type AITradeExecution,
type AITradeAllocation,
type AIRedemptionResult,
type CreateAIOrderRequest,
} from '@one_deploy/sdk';

后续步骤