<jupyter_start><jupyter_text>Getting historical price data (ohlc and volume) verion 2<jupyter_code>def get_history(symbol, interval, start, end = None):
    bars = client.get_historical_klines(symbol = symbol, interval = interval, start_str = start, end_str = end, limit = 1000)
    df = pd.DataFrame(bars)
    df["Date"] = pd.to_datetime(df.iloc[:,0], unit = "ms")
    df.columns = ["Open Time", "Open", "High", "Low", "Close", "Volume", "Clos time", "Quote Asset Volume", "Number of Trades", "Taker Buy Base Asset Volume", "Taker Buy Quote Asset Volume", "Ignore", "Date"]
    df = df[["Date", "Open", "High", "Low", "Close", "Volume"]].copy()
    df.set_index("Date", inplace =True)
    for column in df.columns:
        df[column] = pd.to_numeric(df[column], errors = "coerce")
    return df
timestamp
df = get_history(symbol = "BTCUSDT", interval = "1d", start = timestamp)
df
# the last cabdle is incomplete
df.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 1631 entries, 2017-08-17 to 2022-02-02
Data columns (total 5 columns):
 #   Column  Non-Null Count  Dtype  
---  ------  --------------  -----  
 0   Open    1631 non-null   float64
 1   High    1631 non-null   float64
 2   Low     1631 non-null   float64
 3   Close   1631 non-null   float64
 4   Volume  1631 non-null   float64
dtypes: float64(5)
memory usage: 76.5 KB<jupyter_text>Daily date for specified time period<jupyter_code>df = get_history(symbol = "BTCUSDT", interval = "1d", start = "2022-01-01", end = "2022-02-02")
df
df = get_history(symbol = "BTCUSDT", interval = "1w", start = "2022-01-01", end = "2022-02-02")
df
df = get_history(symbol = "BTCUSDT", interval = "1h", start = "2022-02-01 00:00:00", end = "2022-02-02 23:59:59")
df<jupyter_output><empty_output><jupyter_text>Most recent time<jupyter_code>from datetime import datetime, timedelta
now = datetime.utcnow()
now
two_hours_before = now - timedelta(hours = 2)
two_hours_before
df = get_history(symbol = "BTCUSDT", interval = "1m", start = str(two_hours_before))
df<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15559864275327193, 'fraction_numerical': 0.06495395055744062, 'mean_word_length': 4.134328358208955, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '21338', 'license': 'MIT', 'n_tokens_mistral': 832, 'n_tokens_neox': 739, 'n_words': 199, 'path': '4. Getting historical price data (ohlc and volume) verion 1.ipynb', 'repo_name': 'seamonsterlab/initial_tradingbot', 'size': '2063'}