Skip to content

Conversation

@feherg78
Copy link

@feherg78 feherg78 commented Nov 6, 2025

πŸš€ Feature: Crypto Trading Support

This PR adds comprehensive cryptocurrency trading capabilities to AI-Trader with support for multiple deployment environments.

✨ What's New

πŸ€– Crypto Trading Agent

  • BaseAgentCrypto - Specialized agent for crypto markets
  • Support for derivatives trading (futures, perpetuals)
  • Real-time price monitoring and decision making
  • Multi-exchange support (ByBit, Binance, Coinbase, Kraken)

πŸ”§ New Tools

  • tool_crypto_exchange.py - Exchange API integration (CCXT-based)
  • tool_get_price_crypto.py - Real-time price fetching
  • cost_tracker.py - API cost monitoring and budget tracking
  • environment_detector.py - Auto-detect runtime environment

🌍 Multi-Environment Support

1. Local Development (crypto_config_local.json)

  • TESTNET mode only (no real money)
  • Free GitHub Models API (gpt-4o)
  • Perfect for testing and development

2. GitHub Codespaces (crypto_config_codespaces.json)

  • 90-180 hours/month free compute
  • Live trading with testnet option
  • Scheduled trading hours

3. VPS Production (crypto_config_vps.json)

  • 24/7 live trading
  • Oracle Cloud Free Tier compatible
  • Advanced risk management
  • Performance monitoring and alerts

πŸ“œ Deployment Scripts

  • start_crypto_local.sh - Local dev startup
  • start_crypto_codespaces.sh - Codespaces startup
  • start_crypto_vps.sh - VPS production startup
  • deploy_oracle_vps.sh - Automated Oracle Cloud setup

🎯 AI Provider Management

  • Unified interface for multiple AI providers
  • Automatic failover between providers
  • Priority-based model selection
  • Cost tracking per provider

πŸ”’ Risk Management Features

  • Position size limits
  • Stop-loss and take-profit automation
  • Trailing stop support
  • Daily loss limits
  • Emergency stop-loss

πŸ’° Cost Optimization

  • Free GitHub Models API (primary)
  • Daily/monthly budget tracking
  • Alert at 80% budget threshold
  • Cost per trade tracking

πŸ§ͺ Testing

  • Local development tested
  • Codespaces deployment pending
  • VPS deployment pending
  • Live trading not yet enabled

πŸ“‹ Before Merging

  • Review configuration files
  • Test in local environment
  • Verify API key setup instructions
  • Document deployment process

πŸ” Security Notes

  • All API keys stored in .env (gitignored)
  • Testnet mode enabled by default
  • Explicit confirmation required for live trading

Ready for review! πŸš€

Copilot AI review requested due to automatic review settings November 6, 2025 11:49
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds comprehensive cryptocurrency trading capabilities to the AI-Trader system with multi-environment support and advanced infrastructure.

Key Changes:

  • Multi-environment detection and configuration system for local, VPS, Codespaces, and Docker deployments
  • Real-time API cost tracking with budget management across GitHub Models (free), Anthropic Claude, and OpenAI
  • Complete cryptocurrency trading agent supporting ByBit, Binance, Coinbase, and Kraken exchanges with derivatives/spot trading

Reviewed Changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 31 comments.

Show a summary per file
File Description
tools/environment_detector.py Automatic runtime environment detection with platform-specific configurations
tools/cost_tracker.py Real-time API cost tracking with per-provider monitoring and budget alerts
scripts/start_crypto_vps.sh VPS production deployment script for 24/7 live trading
scripts/start_crypto_local.sh Local development startup script with testnet mode
scripts/start_crypto_codespaces.sh GitHub Codespaces-specific startup automation
scripts/deploy_oracle_vps.sh Automated Oracle Cloud VPS deployment and initial setup
prompts/agent_prompt_crypto.py Specialized crypto trading prompts with 24/7 market awareness
data/merge_crypto_jsonl.py Utility to merge individual crypto JSON files into unified JSONL format
configs/crypto_config_vps.json VPS production configuration with live trading settings
configs/crypto_config_local.json Local development configuration with testnet defaults
configs/crypto_config_codespaces.json GitHub Codespaces-optimized configuration
agent_tools/tool_get_price_crypto.py MCP tool for real-time and historical crypto price queries
agent_tools/tool_crypto_exchange.py Multi-exchange integration with unified API for trading operations
agent/providers/ai_provider_manager.py Multi-provider AI API manager with automatic failover and rate limiting
agent/providers/init.py Provider module initialization
agent/base_agent_crypto/base_agent_crypto.py Advanced cryptocurrency trading agent with 24/7 support and multi-timeframe analysis
agent/base_agent_crypto/init.py Crypto agent module initialization
Comments suppressed due to low confidence (1)

tools/environment_detector.py:43

  • Except block directly handles BaseException.
    except:

πŸ’‘ Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

return "local"


def get_environment_config(env: Optional[str] = None) -> Dict[str, any]:
Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type hint uses lowercase any instead of the proper Any type from typing. This should be Dict[str, Any] with Any imported from the typing module.

Copilot uses AI. Check for mistakes.
product = f.read().strip().lower()
if any(cloud in product for cloud in ["google", "amazon", "azure", "oracle", "digitalocean"]):
return "vps"
except:
Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bare except clause without specifying an exception type is a bad practice. This should catch specific exceptions like IOError or FileNotFoundError to avoid silently catching unexpected errors like KeyboardInterrupt or SystemExit.

Suggested change
except:
except (FileNotFoundError, PermissionError, OSError):

Copilot uses AI. Check for mistakes.
Comment on lines +44 to +45
export $(cat .env | grep -v '^#' | xargs)

Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This command is vulnerable to command injection if the .env file contains malicious content. Consider using set -a; source .env; set +a or a safer method to load environment variables that doesn't execute arbitrary code through xargs.

Suggested change
export $(cat .env | grep -v '^#' | xargs)
set -a
source .env
set +a

Copilot uses AI. Check for mistakes.

"performance_monitoring": {
"enabled": true,
"alert_email": "feherg78@example.com",
Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The email address "feherg78@example.com" uses the "@example.com" domain which is a reserved domain for examples. This should be replaced with a real email address or made configurable via environment variables for production use.

Suggested change
"alert_email": "feherg78@example.com",
"alert_email": "${ALERT_EMAIL}",

Copilot uses AI. Check for mistakes.
Comment on lines +54 to +60
dt = candle['datetime']
time_series[dt] = {
'open': candle['open'],
'high': candle['high'],
'low': candle['low'],
'close': candle['close'],
'volume': candle['volume']
Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function assumes that each candle dictionary has the keys 'datetime', 'open', 'high', 'low', 'close', and 'volume'. If any of these keys are missing, the code will raise a KeyError. Consider adding validation or using .get() with defaults for better error handling.

Suggested change
dt = candle['datetime']
time_series[dt] = {
'open': candle['open'],
'high': candle['high'],
'low': candle['low'],
'close': candle['close'],
'volume': candle['volume']
dt = candle.get('datetime')
if dt is None:
continue # skip candles without datetime
time_series[dt] = {
'open': candle.get('open', None),
'high': candle.get('high', None),
'low': candle.get('low', None),
'close': candle.get('close', None),
'volume': candle.get('volume', None)

Copilot uses AI. Check for mistakes.
Comment on lines +10 to +12
from typing import List, Dict, Any


Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import of 'Dict' is not used.
Import of 'List' is not used.
Import of 'Any' is not used.

Suggested change
from typing import List, Dict, Any

Copilot uses AI. Check for mistakes.

import os
import time
from typing import Dict, List, Optional, Any
Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import of 'Any' is not used.

Suggested change
from typing import Dict, List, Optional, Any
from typing import Dict, List, Optional

Copilot uses AI. Check for mistakes.
import os
import time
from typing import Dict, List, Optional, Any
from datetime import datetime
Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import of 'datetime' is not used.

Suggested change
from datetime import datetime

Copilot uses AI. Check for mistakes.

import json
import os
from typing import Dict, List, Optional, Any
Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import of 'List' is not used.
Import of 'Optional' is not used.

Suggested change
from typing import Dict, List, Optional, Any
from typing import Dict, Any

Copilot uses AI. Check for mistakes.
product = f.read().strip().lower()
if any(cloud in product for cloud in ["google", "amazon", "azure", "oracle", "digitalocean"]):
return "vps"
except:
Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'except' clause does nothing but pass and there is no explanatory comment.

Suggested change
except:
except (FileNotFoundError, PermissionError, OSError):
# It's normal for this file to be missing or unreadable on many systems.
# In that case, we simply cannot detect a cloud provider here.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant