Date: 2024-12-29
Feature: Multi-account wash trading system for BTC pairs
Status: Complete
Purpose: Represents a single trading account on Pacifica DEX
interface Account {
id: string; // Unique account identifier
name: string; // Human-readable account name
apiKey: string; // Pacifica API key (encrypted)
privateKey: string; // Private key for signing (encrypted)
address: string; // Wallet address
balance: {
total: number; // Total account balance (USD)
available: number; // Available balance for trading
used: number; // Used balance (margin)
};
positions: Position[]; // Current positions
riskLimits: RiskLimits; // Account-specific risk limits
isActive: boolean; // Whether account is active for trading
createdAt: Date; // Account creation timestamp
lastUpdated: Date; // Last update timestamp
}
Validation Rules:
id
must be unique across all accountsapiKey
and privateKey
must be encryptedbalance.total
must be >= 0balance.available
must be >= 0balance.used
must be >= 0balance.total
must equal balance.available + balance.used
State Transitions:
inactive
→ active
: Account enabled for tradingactive
→ inactive
: Account disabled for tradingactive
→ suspended
: Account suspended due to risk breachPurpose: Represents a coordinated wash trading session across multiple accounts
interface WashTradingSession {
id: string; // Unique session identifier
name: string; // Human-readable session name
strategy: TradingStrategy; // Trading strategy configuration
accounts: string[]; // Array of account IDs participating
status: SessionStatus; // Current session status
targetVolume: number; // Target volume to generate (BTC)
currentVolume: number; // Current volume generated (BTC)
startTime: Date; // Session start timestamp
endTime?: Date; // Session end timestamp (if completed)
duration: number; // Planned session duration (ms)
orderPairs: OrderPair[]; // Generated order pairs
riskMetrics: RiskMetrics; // Current risk metrics
auditLog: AuditEntry[]; // Audit trail
createdAt: Date; // Session creation timestamp
updatedAt: Date; // Last update timestamp
}
Validation Rules:
id
must be unique across all sessionsaccounts
must contain at least 2 account IDstargetVolume
must be > 0currentVolume
must be >= 0duration
must be > 0startTime
must be <= endTime
(if both present)State Transitions:
pending
→ active
: Session startedactive
→ paused
: Session pausedpaused
→ active
: Session resumedactive
→ completed
: Session completed successfullyactive
→ failed
: Session failedactive
→ cancelled
: Session cancelledPurpose: Represents a matched buy and sell order across different accounts
interface OrderPair {
id: string; // Unique order pair identifier
sessionId: string; // Parent session ID
buyOrder: Order; // Buy order details
sellOrder: Order; // Sell order details
status: OrderPairStatus; // Current order pair status
volume: number; // Order volume (BTC)
price: number; // Order price (USD)
expectedProfit: number; // Expected profit from spread
actualProfit: number; // Actual profit realized
fees: number; // Total fees paid
slippage: number; // Actual slippage experienced
executionTime: number; // Time to execute (ms)
createdAt: Date; // Order pair creation timestamp
updatedAt: Date; // Last update timestamp
}
Validation Rules:
id
must be unique across all order pairsbuyOrder.accountId
must differ from sellOrder.accountId
volume
must be > 0price
must be > 0buyOrder.side
must be 'buy'sellOrder.side
must be 'sell'State Transitions:
pending
→ submitted
: Orders submitted to exchangesubmitted
→ filled
: Both orders filled successfullysubmitted
→ partial
: One or both orders partially filledsubmitted
→ failed
: One or both orders failedsubmitted
→ cancelled
: Orders cancelledPurpose: Represents a single order on Pacifica DEX
interface Order {
id: string; // Unique order identifier
accountId: string; // Account that placed the order
pairId: string; // Parent order pair ID
symbol: string; // Trading pair (e.g., 'BTC/USD')
side: 'buy' | 'sell'; // Order side
type: 'market' | 'limit'; // Order type
size: number; // Order size (BTC)
price?: number; // Order price (for limit orders)
status: OrderStatus; // Current order status
filledSize: number; // Amount filled (BTC)
averagePrice?: number; // Average fill price
fees: number; // Fees paid
slippage: number; // Slippage experienced
pacificaOrderId?: string; // Pacifica exchange order ID
createdAt: Date; // Order creation timestamp
updatedAt: Date; // Last update timestamp
}
Validation Rules:
id
must be unique across all orderssize
must be > 0price
must be > 0 (for limit orders)filledSize
must be >= 0 and <= size
side
must be either 'buy' or 'sell'type
must be either 'market' or 'limit'State Transitions:
pending
→ submitted
: Order submitted to exchangesubmitted
→ filled
: Order completely filledsubmitted
→ partial
: Order partially filledsubmitted
→ cancelled
: Order cancelledsubmitted
→ failed
: Order failedPurpose: Defines how wash trading orders are generated and executed
interface TradingStrategy {
id: string; // Unique strategy identifier
name: string; // Human-readable strategy name
type: StrategyType; // Strategy type
symbol: string; // Trading pair (e.g., 'BTC/USD')
parameters: {
volumeDistribution: 'equal' | 'weighted' | 'random';
priceRange: {
min: number; // Minimum price offset (%)
max: number; // Maximum price offset (%)
};
timing: {
minInterval: number; // Minimum interval between orders (ms)
maxInterval: number; // Maximum interval between orders (ms)
orderSize: {
min: number; // Minimum order size (BTC)
max: number; // Maximum order size (BTC)
};
};
riskLimits: {
maxPositionSize: number; // Maximum position size (% of balance)
stopLossThreshold: number; // Stop loss threshold (%)
maxSlippage: number; // Maximum acceptable slippage (%)
};
};
isActive: boolean; // Whether strategy is active
createdAt: Date; // Strategy creation timestamp
updatedAt: Date; // Last update timestamp
}
Validation Rules:
id
must be unique across all strategiessymbol
must be a valid trading pairpriceRange.min
must be < priceRange.max
timing.minInterval
must be < timing.maxInterval
timing.orderSize.min
must be < timing.orderSize.max
Purpose: Tracks risk metrics for a trading session
interface RiskMetrics {
sessionId: string; // Parent session ID
totalExposure: number; // Total exposure across all accounts
maxDrawdown: number; // Maximum drawdown experienced
currentDrawdown: number; // Current drawdown
sharpeRatio: number; // Risk-adjusted return ratio
volatility: number; // Price volatility
correlation: number; // Correlation between accounts
riskScore: number; // Overall risk score (0-100)
alerts: RiskAlert[]; // Active risk alerts
lastUpdated: Date; // Last update timestamp
}
Validation Rules:
totalExposure
must be >= 0maxDrawdown
must be >= 0currentDrawdown
must be >= 0riskScore
must be between 0 and 100correlation
must be between -1 and 1Purpose: Represents a risk management alert
interface RiskAlert {
id: string; // Unique alert identifier
sessionId: string; // Parent session ID
type: RiskAlertType; // Alert type
severity: 'low' | 'medium' | 'high' | 'critical';
message: string; // Alert message
threshold: number; // Threshold that was breached
currentValue: number; // Current value
accountId?: string; // Account ID (if account-specific)
isAcknowledged: boolean; // Whether alert was acknowledged
createdAt: Date; // Alert creation timestamp
acknowledgedAt?: Date; // Acknowledgment timestamp
}
Validation Rules:
id
must be unique across all alertsseverity
must be one of the defined levelsmessage
must not be emptythreshold
must be > 0currentValue
must be >= 0Purpose: Represents an audit log entry for compliance and debugging
interface AuditEntry {
id: string; // Unique audit entry identifier
sessionId: string; // Parent session ID
action: string; // Action performed
details: any; // Action details
accountId?: string; // Account ID (if applicable)
orderId?: string; // Order ID (if applicable)
timestamp: Date; // Action timestamp
userId?: string; // User ID (if applicable)
}
Validation Rules:
id
must be unique across all audit entriesaction
must not be emptytimestamp
must be valid datedetails
must be serializabletype SessionStatus = 'pending' | 'active' | 'paused' | 'completed' | 'failed' | 'cancelled';
type OrderPairStatus = 'pending' | 'submitted' | 'filled' | 'partial' | 'failed' | 'cancelled';
type OrderStatus = 'pending' | 'submitted' | 'filled' | 'partial' | 'cancelled' | 'failed';
type StrategyType = 'equal_volume' | 'time_based' | 'market_making' | 'custom';
type RiskAlertType = 'position_size' | 'drawdown' | 'slippage' | 'margin' | 'correlation' | 'volatility';