Dobromir Popov 5606ed3cab init gogo
2025-02-12 01:15:44 +02:00

35 lines
1.3 KiB
Python

# visualization/plotting.py
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import time
from IPython.display import clear_output #to clear output each time we plot
def plot_live_data(candles, trade_history):
clear_output(wait=True) # Clear previous plot
# Extract data for plotting
times = [candle['timestamp'] for candle in candles]
close_prices = [candle['close'] for candle in candles]
# Create the figure and axes
fig, ax = plt.subplots(figsize=(12, 6))
ax.plot(times, close_prices, label="Close Price", color='blue')
# Plot trade signals
buy_times = [trade['time'] * 1000 for trade in trade_history if trade['type'] == 'buy']
buy_prices = [trade['price'] for trade in trade_history if trade['type'] == 'buy']
sell_times = [trade['time'] * 1000 for trade in trade_history if trade['type'] == 'sell']
sell_prices = [trade['price'] for trade in trade_history if trade['type'] == 'sell']
ax.scatter(buy_times, buy_prices, color='green', marker='^', label='Buy')
ax.scatter(sell_times, sell_prices, color='red', marker='v', label='Sell')
# Format the plot
ax.set_xlabel('Time')
ax.set_ylabel('Price')
ax.set_title('Live Trading Data with Signals')
ax.legend()
ax.grid(True)
plt.tight_layout()
plt.show()