не сохраняется изображение пайтон

борюсь с ии )) подскажите пож что поправить чтобы изображение в папке сохранялось ,код без ошибок ,все разрешения есть ,но в папке нет фото

import os
import requests
import pandas as pd
import plotly.graph_objects as go
from datetime import datetime, timedelta, timezone
import uuid

# Constants
BINANCE_FUTURES_API_URL = "https://fapi.binance.com/fapi/v1/klines"

# API Session for Efficient Requests to the API
session = requests.Session()

def get_historical_data(symbol, interval, start_time=None, end_time=None, limit=1000):
params = {
    'symbol': symbol,
    'interval': interval,
    'limit': limit  # Max number of candles returned
    }
    if start_time and end_time:
    params.update({
        'startTime': int(start_time.timestamp() * 1000),
        'endTime': int(end_time.timestamp() * 1000)
    })

    try:
    response = session.get(BINANCE_FUTURES_API_URL, params=params)
    response.raise_for_status()
    data = response.json()
    except requests.RequestException as e:
    print(f"Error requesting data: {e}")
    return pd.DataFrame()  # Return an empty DataFrame on fail

    # Transforming Data to DataFrame
    column_names = ['Open time', 'Open', 'High', 'Low', 'Close', 'Volume', 'Close 
time',
                'Quote asset volume', 'Number of trades', 'Taker buy base asset 
volume',
                'Taker buy quote asset volume', 'Ignore']
df = pd.DataFrame(data, columns=column_names)
df['Open time'] = pd.to_datetime(df['Open time'], unit='ms')
df['Close time'] = pd.to_datetime(df['Close time'], unit='ms')
for col in ['Open', 'High', 'Low', 'Close', 'Volume']:
    df[col] = df[col].astype('float')

return df

def save_chart_as_image(fig, file_path):
# Ensure the directory exists
os.makedirs(os.path.dirname(file_path), exist_ok=True)
# Write the image
fig.write_image(file_path)
return file_path

def plot_candlestick_chart(df, symbol, interval):
fig = go.Figure(data=[go.Candlestick(x=df['Open time'],
                                     open=df['Open'],
                                     high=df['High'],
                                     low=df['Low'],
                                     close=df['Close'])])
fig.update_layout(
    title=f"{symbol} Candlestick Chart ({interval})",
    xaxis_title="Time",
    yaxis_title="Price",
    xaxis_rangeslider_visible=False,
    plot_bgcolor='rgb(30, 30, 30)',
    paper_bgcolor='rgb(30, 30, 30)',
    font_color='white',
    xaxis=dict(showgrid=False, zeroline=False, showline=False),
    yaxis=dict(showgrid=False, zeroline=False, showline=False),
)
return fig

def print_image_location(image_path):
print(f"The image is located at: {image_path}")

# Example Usage
symbol = 'BTCUSDT'
interval = '5m'
end_time = datetime.now(timezone.utc)
start_time = end_time - timedelta(hours=4)
custom_directory = r"C:\Users\User\Desktop\oi"

df = get_historical_data(symbol, interval, start_time, end_time)
if not df.empty:
fig = plot_candlestick_chart(df, symbol, interval)
file_name = f"{symbol}_{interval}_chart_{uuid.uuid4().hex}.png"
image_path = os.path.join(custom_directory, file_name)
saved_path = save_chart_as_image(fig, image_path)
print_image_location(saved_path)
else:
print("Failed to retrieve data.")'''

Ответы (1 шт):

Автор решения: вася

все спасибо ))разобрался -для построеения графиков нужго использовать другую библеотеку- import mplfinance as mpf

→ Ссылка