-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
88 lines (71 loc) · 2.87 KB
/
example.py
File metadata and controls
88 lines (71 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python3
"""
Simple Example - Crypto Trading Bot
This example demonstrates how to use the crypto trading bot
with basic configuration and paper trading.
"""
from config import Config
from trading_bot import CryptoTradingBot
import time
def main():
"""Simple example of using the trading bot"""
print("🤖 Crypto Trading Bot - Simple Example")
print("=" * 50)
# Create configuration
config = Config()
# Configure for paper trading (safe for testing)
config.ENABLE_LIVE_TRADING = False
config.SYMBOL = "BTC/USDT"
config.TRADE_AMOUNT = 0.001
config.TIMEFRAME = "1h"
config.STRATEGY_TYPE = "RSI_STRATEGY"
# Risk management
config.STOP_LOSS_PERCENTAGE = 5.0
config.TAKE_PROFIT_PERCENTAGE = 10.0
print(f"Configuration:")
print(f" Exchange: {config.EXCHANGE_ID}")
print(f" Symbol: {config.SYMBOL}")
print(f" Strategy: {config.STRATEGY_TYPE}")
print(f" Live Trading: {'Yes' if config.ENABLE_LIVE_TRADING else 'No'}")
print(f" Stop Loss: {config.STOP_LOSS_PERCENTAGE}%")
print(f" Take Profit: {config.TAKE_PROFIT_PERCENTAGE}%")
print("=" * 50)
try:
# Initialize trading bot
print("Initializing trading bot...")
bot = CryptoTradingBot(config)
# Show bot status
status = bot.get_status()
print(f"Bot Status: {'Running' if status['is_running'] else 'Stopped'}")
# Run strategy a few times for demonstration
print("\nRunning strategy execution...")
for i in range(3):
print(f"\n--- Execution {i+1} ---")
# Execute strategy
result = bot.execute_strategy()
if result:
print(f"Action taken: {result['action']}")
if 'profit_loss' in result:
print(f"P&L: ${result['profit_loss']:.2f}")
else:
print("No action taken")
# Wait before next execution
if i < 2: # Don't wait after the last execution
print("Waiting 10 seconds before next execution...")
time.sleep(10)
# Show final performance
stats = bot.get_performance_stats()
print("\n" + "=" * 50)
print("📊 Final Performance:")
print(f" Total Trades: {stats.get('total_trades', 0)}")
print(f" Total P&L: ${stats.get('total_profit_loss', 0):.2f}")
print(f" Win Rate: {stats.get('win_rate', 0):.1f}%")
print(f" Average P&L: ${stats.get('average_profit_loss', 0):.2f}")
except Exception as e:
print(f"❌ Error: {e}")
print("\nTroubleshooting tips:")
print("1. Check your internet connection")
print("2. Verify the exchange is available")
print("3. Check the logs for more details")
if __name__ == "__main__":
main()