fix netwrk rebuild
This commit is contained in:
@ -108,43 +108,83 @@ class BaseDataInput:
|
||||
Convert BaseDataInput to standardized feature vector for models
|
||||
|
||||
Returns:
|
||||
np.ndarray: Standardized feature vector combining all data sources
|
||||
np.ndarray: FIXED SIZE standardized feature vector (7850 features)
|
||||
"""
|
||||
# FIXED FEATURE SIZE - this should NEVER change at runtime
|
||||
FIXED_FEATURE_SIZE = 7850
|
||||
features = []
|
||||
|
||||
# OHLCV features for ETH (300 frames x 4 timeframes x 5 features = 6000 features)
|
||||
for ohlcv_list in [self.ohlcv_1s, self.ohlcv_1m, self.ohlcv_1h, self.ohlcv_1d]:
|
||||
for bar in ohlcv_list[-300:]: # Ensure exactly 300 frames
|
||||
# Ensure exactly 300 frames by padding or truncating
|
||||
ohlcv_frames = ohlcv_list[-300:] if len(ohlcv_list) >= 300 else ohlcv_list
|
||||
|
||||
# Pad with zeros if not enough data
|
||||
while len(ohlcv_frames) < 300:
|
||||
# Create a dummy OHLCV bar with zeros
|
||||
dummy_bar = OHLCVBar(
|
||||
symbol="ETH/USDT",
|
||||
timestamp=datetime.now(),
|
||||
open=0.0, high=0.0, low=0.0, close=0.0, volume=0.0,
|
||||
timeframe="1s"
|
||||
)
|
||||
ohlcv_frames.insert(0, dummy_bar)
|
||||
|
||||
# Extract features from exactly 300 frames
|
||||
for bar in ohlcv_frames:
|
||||
features.extend([bar.open, bar.high, bar.low, bar.close, bar.volume])
|
||||
|
||||
# BTC OHLCV features (300 frames x 5 features = 1500 features)
|
||||
for bar in self.btc_ohlcv_1s[-300:]: # Ensure exactly 300 frames
|
||||
btc_frames = self.btc_ohlcv_1s[-300:] if len(self.btc_ohlcv_1s) >= 300 else self.btc_ohlcv_1s
|
||||
|
||||
# Pad BTC data if needed
|
||||
while len(btc_frames) < 300:
|
||||
dummy_bar = OHLCVBar(
|
||||
symbol="BTC/USDT",
|
||||
timestamp=datetime.now(),
|
||||
open=0.0, high=0.0, low=0.0, close=0.0, volume=0.0,
|
||||
timeframe="1s"
|
||||
)
|
||||
btc_frames.insert(0, dummy_bar)
|
||||
|
||||
for bar in btc_frames:
|
||||
features.extend([bar.open, bar.high, bar.low, bar.close, bar.volume])
|
||||
|
||||
# COB features (±20 buckets x multiple metrics ≈ 800 features)
|
||||
# COB features (FIXED SIZE: 200 features)
|
||||
cob_features = []
|
||||
if self.cob_data:
|
||||
# Price bucket features
|
||||
for price in sorted(self.cob_data.price_buckets.keys()):
|
||||
# Price bucket features (up to 40 buckets x 4 metrics = 160 features)
|
||||
price_keys = sorted(self.cob_data.price_buckets.keys())[:40] # Max 40 buckets
|
||||
for price in price_keys:
|
||||
bucket_data = self.cob_data.price_buckets[price]
|
||||
features.extend([
|
||||
cob_features.extend([
|
||||
bucket_data.get('bid_volume', 0.0),
|
||||
bucket_data.get('ask_volume', 0.0),
|
||||
bucket_data.get('total_volume', 0.0),
|
||||
bucket_data.get('imbalance', 0.0)
|
||||
])
|
||||
|
||||
# Moving averages of imbalance for ±5 buckets (5 buckets x 4 MAs x 2 sides = 40 features)
|
||||
for ma_dict in [self.cob_data.ma_1s_imbalance, self.cob_data.ma_5s_imbalance,
|
||||
self.cob_data.ma_15s_imbalance, self.cob_data.ma_60s_imbalance]:
|
||||
for price in sorted(list(ma_dict.keys())[:5]): # ±5 buckets
|
||||
features.append(ma_dict[price])
|
||||
# Moving averages (up to 10 features)
|
||||
ma_features = []
|
||||
for ma_dict in [self.cob_data.ma_1s_imbalance, self.cob_data.ma_5s_imbalance]:
|
||||
for price in sorted(list(ma_dict.keys())[:5]): # Max 5 buckets per MA
|
||||
ma_features.append(ma_dict[price])
|
||||
if len(ma_features) >= 10:
|
||||
break
|
||||
if len(ma_features) >= 10:
|
||||
break
|
||||
cob_features.extend(ma_features)
|
||||
|
||||
# Technical indicators (variable, pad to 100 features)
|
||||
# Pad COB features to exactly 200
|
||||
cob_features.extend([0.0] * (200 - len(cob_features)))
|
||||
features.extend(cob_features[:200]) # Ensure exactly 200 COB features
|
||||
|
||||
# Technical indicators (FIXED SIZE: 100 features)
|
||||
indicator_values = list(self.technical_indicators.values())
|
||||
features.extend(indicator_values[:100]) # Take first 100 indicators
|
||||
features.extend([0.0] * max(0, 100 - len(indicator_values))) # Pad if needed
|
||||
features.extend([0.0] * max(0, 100 - len(indicator_values))) # Pad to exactly 100
|
||||
|
||||
# Last predictions from other models (variable, pad to 50 features)
|
||||
# Last predictions from other models (FIXED SIZE: 50 features)
|
||||
prediction_features = []
|
||||
for model_output in self.last_predictions.values():
|
||||
prediction_features.extend([
|
||||
@ -155,7 +195,15 @@ class BaseDataInput:
|
||||
model_output.predictions.get('expected_reward', 0.0)
|
||||
])
|
||||
features.extend(prediction_features[:50]) # Take first 50 prediction features
|
||||
features.extend([0.0] * max(0, 50 - len(prediction_features))) # Pad if needed
|
||||
features.extend([0.0] * max(0, 50 - len(prediction_features))) # Pad to exactly 50
|
||||
|
||||
# CRITICAL: Ensure EXACTLY the fixed feature size
|
||||
if len(features) > FIXED_FEATURE_SIZE:
|
||||
features = features[:FIXED_FEATURE_SIZE] # Truncate if too long
|
||||
elif len(features) < FIXED_FEATURE_SIZE:
|
||||
features.extend([0.0] * (FIXED_FEATURE_SIZE - len(features))) # Pad if too short
|
||||
|
||||
assert len(features) == FIXED_FEATURE_SIZE, f"Feature vector size mismatch: {len(features)} != {FIXED_FEATURE_SIZE}"
|
||||
|
||||
return np.array(features, dtype=np.float32)
|
||||
|
||||
|
Reference in New Issue
Block a user