File size: 1,000 Bytes
cc22067
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25dcd8b
cc22067
 
 
 
 
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
import pandas as pd
import requests
import time
import streamlit as st

def get_data():
    data_points = 10000
    interval = '1h'
    limit = 1500
    start_time = int(time.time() * 1000) - (data_points * 60 * 60 * 1000)
    df_list = []

    for i in range(0, data_points, limit):
        params = {
            'interval': interval,
            'limit': limit,
            'start_time': start_time + (i * 60 * 60 * 1000)
        }
        response = requests.get('https://api.coinex.com/v1/market/kline/BTCUSDT', params=params)
        data = response.json()
        df = pd.DataFrame(data['data'])
        df['time'] = pd.to_datetime(df['time'], unit='ms')
        df.set_index('time', inplace=True)
        df.drop(['vol', 'amount'], axis=1, inplace=True)
        df_list.append(df)

    df = pd.concat(df_list)
    return df

if st.button("sosis"):
# Retrieve historical data from Coinex API
    df = get_data()

# Save historical data to btcusdt_data.pkl
    df.to_pickle('btcusdt_data.pkl')