mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2025-12-06 13:54:41 +08:00
* refactor: 简化交易动作,移除 update_stop_loss/update_take_profit/partial_close - 移除 Decision 结构体中的 NewStopLoss, NewTakeProfit, ClosePercentage 字段 - 删除 executeUpdateStopLossWithRecord, executeUpdateTakeProfitWithRecord, executePartialCloseWithRecord 函数 - 简化 logger 中的 partial_close 聚合逻辑 - 更新 AI prompt 和验证逻辑,只保留 6 个核心动作 - 清理相关测试代码 保留的交易动作: open_long, open_short, close_long, close_short, hold, wait * refactor: 移除 AI学习与反思 模块 - 删除前端 AILearning.tsx 组件和相关引用 - 删除后端 /performance API 接口 - 删除 logger 中 AnalyzePerformance、calculateSharpeRatio 等函数 - 删除 PerformanceAnalysis、TradeOutcome、SymbolPerformance 等结构体 - 删除 Context 中的 Performance 字段 - 移除 AI prompt 中夏普比率自我进化相关内容 - 清理 i18n 翻译文件中的相关条目 该模块基于磁盘存储计算,经常出错,做减法移除 * refactor: 将数据库操作统一迁移到 store 包 - 新增 store/ 包,统一管理所有数据库操作 - store.go: 主 Store 结构,懒加载各子模块 - user.go, ai_model.go, exchange.go, trader.go 等子模块 - 支持加密/解密函数注入 (SetCryptoFuncs) - 更新 main.go 使用 store.New() 替代 config.NewDatabase() - 更新 api/server.go 使用 *store.Store 替代 *config.Database - 更新 manager/trader_manager.go: - 新增 LoadTradersFromStore, LoadUserTradersFromStore 方法 - 删除旧版 LoadUserTraders, LoadTraderByID, loadSingleTrader 等方法 - 移除 nofx/config 依赖 - 删除 config/database.go 和 config/database_test.go - 更新 api/server_test.go 使用 store.Trader 类型 - 清理 logger/ 包中未使用的 telegram 相关代码 * refactor: unify encryption key management via .env - Remove redundant EncryptionManager and SecureStorage - Simplify CryptoService to load keys from environment variables only - RSA_PRIVATE_KEY: RSA private key for client-server encryption - DATA_ENCRYPTION_KEY: AES-256 key for database encryption - JWT_SECRET: JWT signing key for authentication - Update start.sh to auto-generate missing keys on first run - Remove secrets/ directory and file-based key storage - Delete obsolete encryption setup scripts - Update .env.example with all required keys * refactor: unify logger usage across mcp package - Add MCPLogger adapter in logger package to implement mcp.Logger interface - Update mcp/config.go to use global logger by default - Remove redundant defaultLogger from mcp/logger.go - Keep noopLogger for testing purposes * chore: remove leftover test RSA key file * chore: remove unused bootstrap package * refactor: unify logging to use logger package instead of fmt/log - Replace all fmt.Print/log.Print calls with logger package - Add auto-initialization in logger package init() for test compatibility - Update main.go to initialize logger at startup - Migrate all packages: api, backtest, config, decision, manager, market, store, trader * refactor: rename database file from config.db to data.db - Update main.go, start.sh, docker-compose.yml - Update migration script and documentation - Update .gitignore and translations * fix: add RSA_PRIVATE_KEY to docker-compose environment * fix: add registration_enabled to /api/config response * fix: Fix navigation between login and register pages Use window.location.href instead of react-router's navigate() to fix the issue where URL changes but the page doesn't reload due to App.tsx using custom route state management. * fix: Switch SQLite from WAL to DELETE mode for Docker compatibility WAL mode causes data sync issues with Docker bind mounts on macOS due to incompatible file locking mechanisms between the container and host. DELETE mode (traditional journaling) ensures data is written directly to the main database file. * refactor: Remove default user from database initialization The default user was a legacy placeholder that is no longer needed now that proper user registration is in place. * feat: Add order tracking system with centralized status sync - Add trader_orders table for tracking all order lifecycle - Implement GetOrderStatus interface for all exchanges (Binance, Bybit, Hyperliquid, Aster, Lighter) - Create OrderSyncManager for centralized order status polling - Add trading statistics (Sharpe ratio, win rate, profit factor) to AI context - Include recent completed orders in AI decision input - Remove per-order goroutine polling in favor of global sync manager * feat: Add TradingView K-line chart to dashboard - Create TradingViewChart component with exchange/symbol selectors - Support Binance, Bybit, OKX, Coinbase, Kraken, KuCoin exchanges - Add popular symbols quick selection - Support multiple timeframes (1m to 1W) - Add fullscreen mode - Integrate with Dashboard page below equity chart - Add i18n translations for zh/en * refactor: Replace separate charts with tabbed ChartTabs component - Create ChartTabs component with tab switching between equity curve and K-line - Add embedded mode support for EquityChart and TradingViewChart - User can now switch between account equity and market chart in same area * fix: Use ChartTabs in App.tsx and fix embedded mode in EquityChart - Replace EquityChart with ChartTabs in App.tsx (the actual dashboard renderer) - Fix EquityChart embedded mode for error and empty data states - Rename interval state to timeInterval to avoid shadowing window.setInterval - Add debug logging to ChartTabs component * feat: Add position tracking system for accurate trade history - Add trader_positions table to track complete open/close trades - Add PositionSyncManager to detect manual closes via polling - Record position on open, update on close with PnL calculation - Use positions table for trading stats and recent trades (replacing orders table) - Fix TradingView chart symbol format (add .P suffix for futures) - Fix DecisionCard wait/hold action color (gray instead of red) - Auto-append USDT suffix for custom symbol input * update ---------
474 lines
12 KiB
Go
474 lines
12 KiB
Go
package trader
|
||
|
||
import (
|
||
"bytes"
|
||
"encoding/json"
|
||
"fmt"
|
||
"io"
|
||
"nofx/logger"
|
||
"net/http"
|
||
"time"
|
||
|
||
"github.com/elliottech/lighter-go/types"
|
||
)
|
||
|
||
// OpenLong 開多倉(實現 Trader 接口)
|
||
func (t *LighterTraderV2) OpenLong(symbol string, quantity float64, leverage int) (map[string]interface{}, error) {
|
||
if t.txClient == nil {
|
||
return nil, fmt.Errorf("TxClient 未初始化,請先設置 API Key")
|
||
}
|
||
|
||
logger.Infof("📈 LIGHTER 開多倉: %s, qty=%.4f, leverage=%dx", symbol, quantity, leverage)
|
||
|
||
// 1. 設置杠杆(如果需要)
|
||
if err := t.SetLeverage(symbol, leverage); err != nil {
|
||
logger.Infof("⚠️ 設置杠杆失敗: %v", err)
|
||
}
|
||
|
||
// 2. 獲取市場價格
|
||
marketPrice, err := t.GetMarketPrice(symbol)
|
||
if err != nil {
|
||
return nil, fmt.Errorf("獲取市場價格失敗: %w", err)
|
||
}
|
||
|
||
// 3. 創建市價買入單(開多)
|
||
orderResult, err := t.CreateOrder(symbol, false, quantity, 0, "market")
|
||
if err != nil {
|
||
return nil, fmt.Errorf("開多倉失敗: %w", err)
|
||
}
|
||
|
||
logger.Infof("✓ LIGHTER 開多倉成功: %s @ %.2f", symbol, marketPrice)
|
||
|
||
return map[string]interface{}{
|
||
"orderId": orderResult["orderId"],
|
||
"symbol": symbol,
|
||
"side": "long",
|
||
"status": "FILLED",
|
||
"price": marketPrice,
|
||
}, nil
|
||
}
|
||
|
||
// OpenShort 開空倉(實現 Trader 接口)
|
||
func (t *LighterTraderV2) OpenShort(symbol string, quantity float64, leverage int) (map[string]interface{}, error) {
|
||
if t.txClient == nil {
|
||
return nil, fmt.Errorf("TxClient 未初始化,請先設置 API Key")
|
||
}
|
||
|
||
logger.Infof("📉 LIGHTER 開空倉: %s, qty=%.4f, leverage=%dx", symbol, quantity, leverage)
|
||
|
||
// 1. 設置杠杆
|
||
if err := t.SetLeverage(symbol, leverage); err != nil {
|
||
logger.Infof("⚠️ 設置杠杆失敗: %v", err)
|
||
}
|
||
|
||
// 2. 獲取市場價格
|
||
marketPrice, err := t.GetMarketPrice(symbol)
|
||
if err != nil {
|
||
return nil, fmt.Errorf("獲取市場價格失敗: %w", err)
|
||
}
|
||
|
||
// 3. 創建市價賣出單(開空)
|
||
orderResult, err := t.CreateOrder(symbol, true, quantity, 0, "market")
|
||
if err != nil {
|
||
return nil, fmt.Errorf("開空倉失敗: %w", err)
|
||
}
|
||
|
||
logger.Infof("✓ LIGHTER 開空倉成功: %s @ %.2f", symbol, marketPrice)
|
||
|
||
return map[string]interface{}{
|
||
"orderId": orderResult["orderId"],
|
||
"symbol": symbol,
|
||
"side": "short",
|
||
"status": "FILLED",
|
||
"price": marketPrice,
|
||
}, nil
|
||
}
|
||
|
||
// CloseLong 平多倉(實現 Trader 接口)
|
||
func (t *LighterTraderV2) CloseLong(symbol string, quantity float64) (map[string]interface{}, error) {
|
||
if t.txClient == nil {
|
||
return nil, fmt.Errorf("TxClient 未初始化")
|
||
}
|
||
|
||
// 如果 quantity=0,獲取當前持倉數量
|
||
if quantity == 0 {
|
||
pos, err := t.GetPosition(symbol)
|
||
if err != nil {
|
||
return nil, fmt.Errorf("獲取持倉失敗: %w", err)
|
||
}
|
||
if pos == nil || pos.Size == 0 {
|
||
return map[string]interface{}{
|
||
"symbol": symbol,
|
||
"status": "NO_POSITION",
|
||
}, nil
|
||
}
|
||
quantity = pos.Size
|
||
}
|
||
|
||
logger.Infof("🔻 LIGHTER 平多倉: %s, qty=%.4f", symbol, quantity)
|
||
|
||
// 創建市價賣出單平倉(reduceOnly=true)
|
||
orderResult, err := t.CreateOrder(symbol, true, quantity, 0, "market")
|
||
if err != nil {
|
||
return nil, fmt.Errorf("平多倉失敗: %w", err)
|
||
}
|
||
|
||
// 平倉後取消所有掛單
|
||
if err := t.CancelAllOrders(symbol); err != nil {
|
||
logger.Infof("⚠️ 取消掛單失敗: %v", err)
|
||
}
|
||
|
||
logger.Infof("✓ LIGHTER 平多倉成功: %s", symbol)
|
||
|
||
return map[string]interface{}{
|
||
"orderId": orderResult["orderId"],
|
||
"symbol": symbol,
|
||
"status": "FILLED",
|
||
}, nil
|
||
}
|
||
|
||
// CloseShort 平空倉(實現 Trader 接口)
|
||
func (t *LighterTraderV2) CloseShort(symbol string, quantity float64) (map[string]interface{}, error) {
|
||
if t.txClient == nil {
|
||
return nil, fmt.Errorf("TxClient 未初始化")
|
||
}
|
||
|
||
// 如果 quantity=0,獲取當前持倉數量
|
||
if quantity == 0 {
|
||
pos, err := t.GetPosition(symbol)
|
||
if err != nil {
|
||
return nil, fmt.Errorf("獲取持倉失敗: %w", err)
|
||
}
|
||
if pos == nil || pos.Size == 0 {
|
||
return map[string]interface{}{
|
||
"symbol": symbol,
|
||
"status": "NO_POSITION",
|
||
}, nil
|
||
}
|
||
quantity = pos.Size
|
||
}
|
||
|
||
logger.Infof("🔺 LIGHTER 平空倉: %s, qty=%.4f", symbol, quantity)
|
||
|
||
// 創建市價買入單平倉(reduceOnly=true)
|
||
orderResult, err := t.CreateOrder(symbol, false, quantity, 0, "market")
|
||
if err != nil {
|
||
return nil, fmt.Errorf("平空倉失敗: %w", err)
|
||
}
|
||
|
||
// 平倉後取消所有掛單
|
||
if err := t.CancelAllOrders(symbol); err != nil {
|
||
logger.Infof("⚠️ 取消掛單失敗: %v", err)
|
||
}
|
||
|
||
logger.Infof("✓ LIGHTER 平空倉成功: %s", symbol)
|
||
|
||
return map[string]interface{}{
|
||
"orderId": orderResult["orderId"],
|
||
"symbol": symbol,
|
||
"status": "FILLED",
|
||
}, nil
|
||
}
|
||
|
||
// CreateOrder 創建訂單(市價或限價)- 使用官方 SDK 簽名
|
||
func (t *LighterTraderV2) CreateOrder(symbol string, isAsk bool, quantity float64, price float64, orderType string) (map[string]interface{}, error) {
|
||
if t.txClient == nil {
|
||
return nil, fmt.Errorf("TxClient 未初始化")
|
||
}
|
||
|
||
// 獲取市場索引(需要從 symbol 轉換)
|
||
marketIndex, err := t.getMarketIndex(symbol)
|
||
if err != nil {
|
||
return nil, fmt.Errorf("獲取市場索引失敗: %w", err)
|
||
}
|
||
|
||
// 構建訂單請求
|
||
clientOrderIndex := time.Now().UnixNano() // 使用時間戳作為客戶端訂單ID
|
||
|
||
var orderTypeValue uint8 = 0 // 0=limit, 1=market
|
||
if orderType == "market" {
|
||
orderTypeValue = 1
|
||
}
|
||
|
||
// 將數量和價格轉換為LIGHTER格式(需要乘以精度)
|
||
baseAmount := int64(quantity * 1e8) // 8位小數精度
|
||
priceValue := uint32(0)
|
||
if orderType == "limit" {
|
||
priceValue = uint32(price * 1e2) // 價格精度
|
||
}
|
||
|
||
txReq := &types.CreateOrderTxReq{
|
||
MarketIndex: marketIndex,
|
||
ClientOrderIndex: clientOrderIndex,
|
||
BaseAmount: baseAmount,
|
||
Price: priceValue,
|
||
IsAsk: boolToUint8(isAsk),
|
||
Type: orderTypeValue,
|
||
TimeInForce: 0, // GTC
|
||
ReduceOnly: 0, // 不只減倉
|
||
TriggerPrice: 0,
|
||
OrderExpiry: time.Now().Add(24 * 28 * time.Hour).UnixMilli(), // 28天後過期
|
||
}
|
||
|
||
// 使用SDK簽名交易(nonce會自動獲取)
|
||
nonce := int64(-1) // -1表示自動獲取
|
||
tx, err := t.txClient.GetCreateOrderTransaction(txReq, &types.TransactOpts{
|
||
Nonce: &nonce,
|
||
})
|
||
if err != nil {
|
||
return nil, fmt.Errorf("簽名訂單失敗: %w", err)
|
||
}
|
||
|
||
// 序列化交易
|
||
txBytes, err := json.Marshal(tx)
|
||
if err != nil {
|
||
return nil, fmt.Errorf("序列化交易失敗: %w", err)
|
||
}
|
||
|
||
// 提交訂單到LIGHTER API
|
||
orderResp, err := t.submitOrder(txBytes)
|
||
if err != nil {
|
||
return nil, fmt.Errorf("提交訂單失敗: %w", err)
|
||
}
|
||
|
||
side := "buy"
|
||
if isAsk {
|
||
side = "sell"
|
||
}
|
||
logger.Infof("✓ LIGHTER訂單已創建: %s %s qty=%.4f", symbol, side, quantity)
|
||
|
||
return orderResp, nil
|
||
}
|
||
|
||
// SendTxRequest 發送交易請求
|
||
type SendTxRequest struct {
|
||
TxType int `json:"tx_type"`
|
||
TxInfo string `json:"tx_info"`
|
||
PriceProtection bool `json:"price_protection,omitempty"`
|
||
}
|
||
|
||
// SendTxResponse 發送交易響應
|
||
type SendTxResponse struct {
|
||
Code int `json:"code"`
|
||
Message string `json:"message"`
|
||
Data map[string]interface{} `json:"data"`
|
||
}
|
||
|
||
// submitOrder 提交已簽名的訂單到LIGHTER API
|
||
func (t *LighterTraderV2) submitOrder(signedTx []byte) (map[string]interface{}, error) {
|
||
const TX_TYPE_CREATE_ORDER = 14
|
||
|
||
// 構建請求
|
||
req := SendTxRequest{
|
||
TxType: TX_TYPE_CREATE_ORDER,
|
||
TxInfo: string(signedTx),
|
||
PriceProtection: true,
|
||
}
|
||
|
||
reqBody, err := json.Marshal(req)
|
||
if err != nil {
|
||
return nil, fmt.Errorf("序列化請求失敗: %w", err)
|
||
}
|
||
|
||
// 發送 POST 請求到 /api/v1/sendTx
|
||
endpoint := fmt.Sprintf("%s/api/v1/sendTx", t.baseURL)
|
||
httpReq, err := http.NewRequest("POST", endpoint, bytes.NewBuffer(reqBody))
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
httpReq.Header.Set("Content-Type", "application/json")
|
||
|
||
resp, err := t.client.Do(httpReq)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
defer resp.Body.Close()
|
||
|
||
body, err := io.ReadAll(resp.Body)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
// 解析響應
|
||
var sendResp SendTxResponse
|
||
if err := json.Unmarshal(body, &sendResp); err != nil {
|
||
return nil, fmt.Errorf("解析響應失敗: %w, body: %s", err, string(body))
|
||
}
|
||
|
||
// 檢查響應碼
|
||
if sendResp.Code != 200 {
|
||
return nil, fmt.Errorf("提交訂單失敗 (code %d): %s", sendResp.Code, sendResp.Message)
|
||
}
|
||
|
||
// 提取交易哈希和訂單ID
|
||
result := map[string]interface{}{
|
||
"tx_hash": sendResp.Data["tx_hash"],
|
||
"status": "submitted",
|
||
}
|
||
|
||
// 如果有訂單ID,添加到結果中
|
||
if orderID, ok := sendResp.Data["order_id"]; ok {
|
||
result["orderId"] = orderID
|
||
} else if txHash, ok := sendResp.Data["tx_hash"].(string); ok {
|
||
// 使用 tx_hash 作為 orderID
|
||
result["orderId"] = txHash
|
||
}
|
||
|
||
logger.Infof("✓ 訂單已提交到 LIGHTER - tx_hash: %v", sendResp.Data["tx_hash"])
|
||
|
||
return result, nil
|
||
}
|
||
|
||
// getMarketIndex 獲取市場索引(從symbol轉換)- 動態從API獲取
|
||
func (t *LighterTraderV2) getMarketIndex(symbol string) (uint8, error) {
|
||
// 1. 檢查緩存
|
||
t.marketMutex.RLock()
|
||
if index, ok := t.marketIndexMap[symbol]; ok {
|
||
t.marketMutex.RUnlock()
|
||
return index, nil
|
||
}
|
||
t.marketMutex.RUnlock()
|
||
|
||
// 2. 從 API 獲取市場列表
|
||
markets, err := t.fetchMarketList()
|
||
if err != nil {
|
||
// 如果 API 失敗,回退到硬編碼映射
|
||
logger.Infof("⚠️ 從 API 獲取市場列表失敗,使用硬編碼映射: %v", err)
|
||
return t.getFallbackMarketIndex(symbol)
|
||
}
|
||
|
||
// 3. 更新緩存
|
||
t.marketMutex.Lock()
|
||
for _, market := range markets {
|
||
t.marketIndexMap[market.Symbol] = market.MarketID
|
||
}
|
||
t.marketMutex.Unlock()
|
||
|
||
// 4. 從緩存中獲取
|
||
t.marketMutex.RLock()
|
||
index, ok := t.marketIndexMap[symbol]
|
||
t.marketMutex.RUnlock()
|
||
|
||
if !ok {
|
||
return 0, fmt.Errorf("未知的市場符號: %s", symbol)
|
||
}
|
||
|
||
return index, nil
|
||
}
|
||
|
||
// MarketInfo 市場信息
|
||
type MarketInfo struct {
|
||
Symbol string `json:"symbol"`
|
||
MarketID uint8 `json:"market_id"`
|
||
}
|
||
|
||
// fetchMarketList 從 API 獲取市場列表
|
||
func (t *LighterTraderV2) fetchMarketList() ([]MarketInfo, error) {
|
||
endpoint := fmt.Sprintf("%s/api/v1/orderBooks", t.baseURL)
|
||
|
||
req, err := http.NewRequest("GET", endpoint, nil)
|
||
if err != nil {
|
||
return nil, fmt.Errorf("創建請求失敗: %w", err)
|
||
}
|
||
|
||
req.Header.Set("Content-Type", "application/json")
|
||
|
||
resp, err := t.client.Do(req)
|
||
if err != nil {
|
||
return nil, fmt.Errorf("請求失敗: %w", err)
|
||
}
|
||
defer resp.Body.Close()
|
||
|
||
body, err := io.ReadAll(resp.Body)
|
||
if err != nil {
|
||
return nil, fmt.Errorf("讀取響應失敗: %w", err)
|
||
}
|
||
|
||
// 解析響應
|
||
var apiResp struct {
|
||
Code int `json:"code"`
|
||
Message string `json:"message"`
|
||
Data []struct {
|
||
Symbol string `json:"symbol"`
|
||
MarketIndex uint8 `json:"market_index"`
|
||
} `json:"data"`
|
||
}
|
||
|
||
if err := json.Unmarshal(body, &apiResp); err != nil {
|
||
return nil, fmt.Errorf("解析響應失敗: %w", err)
|
||
}
|
||
|
||
if apiResp.Code != 200 {
|
||
return nil, fmt.Errorf("獲取市場列表失敗 (code %d): %s", apiResp.Code, apiResp.Message)
|
||
}
|
||
|
||
// 轉換為 MarketInfo 列表
|
||
markets := make([]MarketInfo, len(apiResp.Data))
|
||
for i, market := range apiResp.Data {
|
||
markets[i] = MarketInfo{
|
||
Symbol: market.Symbol,
|
||
MarketID: market.MarketIndex,
|
||
}
|
||
}
|
||
|
||
logger.Infof("✓ 獲取到 %d 個市場", len(markets))
|
||
return markets, nil
|
||
}
|
||
|
||
// getFallbackMarketIndex 硬編碼的回退映射
|
||
func (t *LighterTraderV2) getFallbackMarketIndex(symbol string) (uint8, error) {
|
||
fallbackMap := map[string]uint8{
|
||
"BTC-PERP": 0,
|
||
"ETH-PERP": 1,
|
||
"SOL-PERP": 2,
|
||
"DOGE-PERP": 3,
|
||
"AVAX-PERP": 4,
|
||
"XRP-PERP": 5,
|
||
}
|
||
|
||
if index, ok := fallbackMap[symbol]; ok {
|
||
logger.Infof("✓ 使用硬編碼市場索引: %s -> %d", symbol, index)
|
||
return index, nil
|
||
}
|
||
|
||
return 0, fmt.Errorf("未知的市場符號: %s", symbol)
|
||
}
|
||
|
||
// SetLeverage 設置杠杆(實現 Trader 接口)
|
||
func (t *LighterTraderV2) SetLeverage(symbol string, leverage int) error {
|
||
if t.txClient == nil {
|
||
return fmt.Errorf("TxClient 未初始化")
|
||
}
|
||
|
||
// TODO: 使用SDK簽名並提交SetLeverage交易
|
||
logger.Infof("⚙️ 設置杠杆: %s = %dx", symbol, leverage)
|
||
|
||
return nil // 暫時返回成功
|
||
}
|
||
|
||
// SetMarginMode 設置倉位模式(實現 Trader 接口)
|
||
func (t *LighterTraderV2) SetMarginMode(symbol string, isCrossMargin bool) error {
|
||
if t.txClient == nil {
|
||
return fmt.Errorf("TxClient 未初始化")
|
||
}
|
||
|
||
modeStr := "逐倉"
|
||
if isCrossMargin {
|
||
modeStr = "全倉"
|
||
}
|
||
|
||
logger.Infof("⚙️ 設置倉位模式: %s = %s", symbol, modeStr)
|
||
|
||
// TODO: 使用SDK簽名並提交SetMarginMode交易
|
||
return nil
|
||
}
|
||
|
||
// boolToUint8 將布爾值轉換為uint8
|
||
func boolToUint8(b bool) uint8 {
|
||
if b {
|
||
return 1
|
||
}
|
||
return 0
|
||
}
|