62 lines
1.7 KiB
Python
62 lines
1.7 KiB
Python
|
|
import asyncio
|
|
import logging
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
# Setup path
|
|
project_root = Path(__file__).parent
|
|
sys.path.insert(0, str(project_root))
|
|
sys.path.insert(0, str(project_root / 'trading_system'))
|
|
sys.path.insert(0, str(project_root / 'backend'))
|
|
|
|
# Mock config
|
|
from trading_system import config
|
|
config.TRADING_CONFIG = {
|
|
'STOP_LOSS_PERCENT': 0.03,
|
|
'TAKE_PROFIT_PERCENT': 0.05,
|
|
'ATR_STOP_LOSS_MULTIPLIER': 2.5,
|
|
'USE_ATR_STOP_LOSS': True
|
|
}
|
|
|
|
from trading_system.risk_manager import RiskManager
|
|
from trading_system.position_manager import PositionManager
|
|
|
|
# Mock classes
|
|
class MockClient:
|
|
pass
|
|
|
|
async def test_risk_manager():
|
|
print("Testing RiskManager...")
|
|
rm = RiskManager(None)
|
|
|
|
entry_price = 100.0
|
|
side = 'BUY'
|
|
quantity = 1.0
|
|
leverage = 10
|
|
stop_loss_pct = 0.03
|
|
|
|
# Case 1: No ATR, No Klines
|
|
sl = rm.get_stop_loss_price(entry_price, side, quantity, leverage, stop_loss_pct=stop_loss_pct)
|
|
print(f"Case 1 (Basic): SL = {sl}")
|
|
|
|
# Case 2: With ATR
|
|
atr = 2.0
|
|
sl_atr = rm.get_stop_loss_price(entry_price, side, quantity, leverage, stop_loss_pct=stop_loss_pct, atr=atr)
|
|
print(f"Case 2 (ATR={atr}): SL = {sl_atr}")
|
|
|
|
# Case 3: SELL side
|
|
side = 'SELL'
|
|
sl_sell = rm.get_stop_loss_price(entry_price, side, quantity, leverage, stop_loss_pct=stop_loss_pct)
|
|
print(f"Case 3 (SELL): SL = {sl_sell}")
|
|
|
|
# Case 4: Zero/None input
|
|
sl_none = rm.get_stop_loss_price(entry_price, side, quantity, leverage, stop_loss_pct=None)
|
|
print(f"Case 4 (None pct): SL = {sl_none}")
|
|
|
|
sl_zero = rm.get_stop_loss_price(entry_price, side, quantity, leverage, stop_loss_pct=0)
|
|
print(f"Case 4 (Zero pct): SL = {sl_zero}")
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(test_risk_manager())
|