(feat) add method to cache candles

This commit is contained in:
cardosofede
2024-05-21 11:28:14 -05:00
parent 8cd669dae2
commit 397986faa0

View File

@@ -1,5 +1,18 @@
import streamlit as st
import pandas as pd
from CONFIG import BACKEND_API_HOST, BACKEND_API_PORT
from backend.services.backend_api_client import BackendAPIClient
def get_max_records(days_to_download: int, interval: str) -> int:
conversion = {"s": 1 / 60, "m": 1, "h": 60, "d": 1440}
unit = interval[-1]
quantity = int(interval[:-1])
return int(days_to_download * 24 * 60 / (quantity * conversion[unit]))
@st.cache_data
def get_candles(connector_name="binance", trading_pair="BTC-USDT", interval="1m", max_records=5000):
backend_client = BackendAPIClient(BACKEND_API_HOST, BACKEND_API_PORT)
return pd.DataFrame(backend_client.get_real_time_candles(connector_name, trading_pair, interval, max_records))