mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-11 06:46:59 +08:00
- trader/alpaca/: Full Trader interface implementation for Alpaca - Paper/Live trading support (market orders, stop/limit) - GetBalance, GetPositions, GetMarketPrice via Alpaca API - Fractional share support (4 decimal places) - Commission-free trading - Agent trade routing: stock symbols (AAPL, TSLA) → Alpaca - isStockSymbol() heuristic to distinguish crypto vs stock - execute_trade tool updated for stock buy/sell semantics - get_market_price works for both crypto and stocks - TraderManager + API: Alpaca registered as exchange type - Factory case in auto_trader.go - Config mapping in trader_manager.go - Temp trader creation in handler_trader.go for balance query - Frontend: PositionsPanel distinguishes stock vs crypto - US flag emoji for stock positions - Dollar prefix for stock PnL/prices - 'Shares' label instead of 'Qty' for stocks - System prompts updated for stock trading capabilities
75 lines
2.7 KiB
Go
75 lines
2.7 KiB
Go
package alpaca
|
|
|
|
import "nofx/trader/types"
|
|
|
|
// Re-export for convenience
|
|
type (
|
|
ClosedPnLRecord = types.ClosedPnLRecord
|
|
OpenOrder = types.OpenOrder
|
|
)
|
|
|
|
// AlpacaAccount represents Alpaca account info
|
|
type AlpacaAccount struct {
|
|
ID string `json:"id"`
|
|
AccountNumber string `json:"account_number"`
|
|
Status string `json:"status"`
|
|
Currency string `json:"currency"`
|
|
Cash string `json:"cash"`
|
|
Equity string `json:"equity"`
|
|
BuyingPower string `json:"buying_power"`
|
|
PortfolioValue string `json:"portfolio_value"`
|
|
PatternDayTrader bool `json:"pattern_day_trader"`
|
|
DaytradeCount int `json:"daytrade_count"`
|
|
TradingBlocked bool `json:"trading_blocked"`
|
|
}
|
|
|
|
// AlpacaPosition represents an open position
|
|
type AlpacaPosition struct {
|
|
AssetID string `json:"asset_id"`
|
|
Symbol string `json:"symbol"`
|
|
Exchange string `json:"exchange"`
|
|
AssetClass string `json:"asset_class"`
|
|
AvgEntryPrice string `json:"avg_entry_price"`
|
|
Qty string `json:"qty"`
|
|
Side string `json:"side"`
|
|
MarketValue string `json:"market_value"`
|
|
CostBasis string `json:"cost_basis"`
|
|
UnrealizedPL string `json:"unrealized_pl"`
|
|
UnrealizedPLPC string `json:"unrealized_plpc"`
|
|
CurrentPrice string `json:"current_price"`
|
|
LastdayPrice string `json:"lastday_price"`
|
|
ChangeToday string `json:"change_today"`
|
|
}
|
|
|
|
// AlpacaOrderRequest represents an order submission
|
|
type AlpacaOrderRequest struct {
|
|
Symbol string `json:"symbol"`
|
|
Qty string `json:"qty,omitempty"`
|
|
Notional string `json:"notional,omitempty"` // Dollar amount instead of qty
|
|
Side string `json:"side"` // buy, sell
|
|
Type string `json:"type"` // market, limit, stop, stop_limit
|
|
TimeInForce string `json:"time_in_force"` // day, gtc, opg, cls, ioc, fok
|
|
LimitPrice string `json:"limit_price,omitempty"`
|
|
StopPrice string `json:"stop_price,omitempty"`
|
|
}
|
|
|
|
// AlpacaOrder represents an order response
|
|
type AlpacaOrder struct {
|
|
ID string `json:"id"`
|
|
ClientOrderID string `json:"client_order_id"`
|
|
Symbol string `json:"symbol"`
|
|
Side string `json:"side"`
|
|
Type string `json:"type"`
|
|
Qty string `json:"qty"`
|
|
FilledQty string `json:"filled_qty"`
|
|
FilledAvgPrice string `json:"filled_avg_price"`
|
|
LimitPrice string `json:"limit_price"`
|
|
StopPrice string `json:"stop_price"`
|
|
Status string `json:"status"`
|
|
CreatedAt string `json:"created_at"`
|
|
UpdatedAt string `json:"updated_at"`
|
|
SubmittedAt string `json:"submitted_at"`
|
|
FilledAt string `json:"filled_at"`
|
|
TimeInForce string `json:"time_in_force"`
|
|
}
|