Skip to content

Commit ded33c4

Browse files
committed
added coin score calculator method
1 parent db311d1 commit ded33c4

2 files changed

Lines changed: 59 additions & 5 deletions

File tree

tests/test_kraken_client.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22
Refactored tests for Kraken WebSocket client.
33
Matches the current KrakenClient implementation.
44
"""
5-
import asyncio
65
import json
76
from decimal import Decimal
8-
from unittest.mock import patch, MagicMock, AsyncMock
7+
from unittest.mock import AsyncMock
98

109
import pytest
11-
import aiohttp
1210

13-
from traid.data.clients.kraken_client import KrakenClient
11+
from traid.kraken_client import KrakenClient
1412

1513

1614
@pytest.fixture
@@ -167,7 +165,6 @@ def test_reverse_format_symbol(client):
167165

168166

169167
import pytest
170-
import ssl
171168
import asyncio
172169

173170
@pytest.mark.asyncio

traid/trading_bot.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,63 @@ def _calculate_opportunity_scores(self) -> Dict[str, int]:
292292

293293
return self.opportunity_scores
294294

295+
def _calculate_coin_score(self, symbol: str, prices: np.ndarray, volumes: np.ndarray) -> int:
296+
"""Calculate opportunity score for a single coin (more aggressive)."""
297+
# Base score starts at 50 (neutral)
298+
score = 50
299+
300+
try:
301+
# Check if we have enough data
302+
if len(prices) < 10:
303+
return 50
304+
305+
# Calculate price changes
306+
if len(prices) >= 2:
307+
recent_change = (prices[-1] / prices[-2] - 1) * 100
308+
# Reward recent price increases more aggressively
309+
if recent_change > 1:
310+
score += recent_change * 2 # Double weight for upward movement
311+
elif recent_change < -1:
312+
score -= abs(recent_change)
313+
314+
# Calculate RSI
315+
rsi = self._calculate_rsi(prices)
316+
317+
# RSI component - more aggressive weighting
318+
if rsi < 30: # Oversold - buying opportunity
319+
score += (30 - rsi) * 1.5
320+
elif rsi > 70: # Overbought - selling opportunity
321+
score -= (rsi - 70) * 1.5
322+
323+
# Price trend component - shorter timeframes for faster response
324+
if len(prices) >= 6:
325+
short_ma = np.mean(prices[-3:]) # 3-period MA (was 5)
326+
long_ma = np.mean(prices[-6:]) # 6-period MA (was 10)
327+
328+
# More aggressive scoring for uptrends
329+
if short_ma > long_ma: # Uptrend
330+
trend_strength = (short_ma / long_ma - 1) * 100
331+
score += 10 + trend_strength
332+
else: # Downtrend
333+
trend_weakness = (1 - short_ma / long_ma) * 100
334+
score -= 10 + trend_weakness
335+
336+
# Volume component - more aggressive
337+
if len(volumes) >= 3:
338+
avg_volume = np.mean(volumes[-4:-1]) # Last 3 periods excluding current
339+
current_volume = volumes[-1]
340+
341+
# Higher volume is more important
342+
if current_volume > avg_volume * 1.5:
343+
volume_increase = (current_volume / avg_volume - 1) * 10
344+
score += 10 + volume_increase
345+
346+
except Exception as e:
347+
print(f"Error in score calculation: {e}")
348+
349+
# Ensure score is within 0-100 range
350+
return max(0, min(100, int(score)))
351+
295352
def _calculate_rsi(self, prices: np.ndarray, period: int = 14) -> float:
296353
"""Calculate Relative Strength Index."""
297354
if len(prices) < period + 1:

0 commit comments

Comments
 (0)