I was coding a script that calculates percentage differnce of
binance
's close data and
upbit
's close data.
1 import time
2 import pandas as pd
3 import pyupbit
4 import ccxt
5 import requests
6 time.sleep(3)
7
8 binanceX = ccxt.binance(config={
9 'enableRateLimit': True,
10 'options': {
11 'defaultType': 'future'
12 }
13 })
14
15
16 def GetOhlcv(binance, Ticker, period):
17 ohlcv = binance.fetch_ohlcv(Ticker, period)
18 df = pd.DataFrame(ohlcv, columns=['datetime', 'open', 'high', 'low', 'close', 'volume'])
19 df['datetime'] = pd.to_datetime(df['datetime'], unit='ms')
20 df.set_index('datetime', inplace=True)
21 return df
22
23
24 def get_exchange_rate(base_currency, target_currency):
25 url = f'http://www.floatrates.com/daily/{base_currency.lower()}.json'
26 response = requests.get(url)
27
28 if response.status_code == 200:
29 data = response.json()
30
31 if target_currency.lower() in data:
32 exchange_rate = data[target_currency.lower()]['rate']
33 return exchange_rate
34 else:
35 print(f'Error: {target_currency} not found in the conversion rates.')
36 return None
37 else:
38 print(f"Error: HTTP status code {response.status_code} received.")
39 return None
40
41
42 upbit_coin_list = ["KRW-BTC", "KRW-DOGE", "KRW-ETH", "KRW-SOL", "KRW-XRP"]
43 binance_coin_list = ["BTC/BUSD", "DOGE/BUSD", "ETH/BUSD", "SOL/BUSD", "XRP/BUSD"]
44 binance_symbol_list = ["BTCBUSD", "DOGEBUSD", "ETHBUSD", "SOLBUSD", "XRPBUSD"]
45 for i in range(5):
46 upbit_coin = upbit_coin_list[i]
47 binance_coin = binance_coin_list[i]
48
49 exchange_rate_today = get_exchange_rate("USD", 'KRW')
50 df_binance = GetOhlcv(binanceX, binance_coin, '1m')
51 df_binance_close = df_binance["close"].tail(200)
52 df_upbit = pyupbit.get_ohlcv(upbit_coin, interval="minute1")
53 df_upbit_close = df_upbit["close"].tail(200)
54
55 gap_series = (df_binance_close * exchange_rate_today - df_upbit_close) / (
56 df_binance_close * exchange_rate_today) * 100
57 gap_df = pd.DataFrame(gap_series, columns=['now_gap'])
58 now_gap = gap_series.iloc[-2]
59
60 print(gap_series, gap_df, now_gap)
When I was done, I ran the code. Instead of it printing out the dataframe of percentage difference of
binance
's close data and
upbit
's close data, it printed out this:
1 2023-08-21 17:37:00 NaN
2 2023-08-21 17:38:00 NaN
3 2023-08-21 17:39:00 NaN
4 2023-08-21 17:40:00 NaN
5 2023-08-21 17:41:00 NaN
6 ..
7 2023-08-22 05:52:00 NaN
8 2023-08-22 05:53:00 NaN
9 2023-08-22 05:54:00 NaN
10 2023-08-22 05:55:00 NaN
11 2023-08-22 05:56:00 NaN
12 Name: close, Length: 400, dtype: float64 Empty DataFrame
13 Columns: [now_gap]
14 Index: [] nan
15 2023-08-21 17:37:00 NaN
16 2023-08-21 17:38:00 NaN
17 2023-08-21 17:39:00 NaN
18 2023-08-21 17:40:00 NaN
19 2023-08-21 17:41:00 NaN
20 ..
21 2023-08-22 05:49:00 NaN
22 2023-08-22 05:50:00 NaN
23 2023-08-22 05:53:00 NaN
24 2023-08-22 05:54:00 NaN
25 2023-08-22 05:56:00 NaN
26 Name: close, Length: 400, dtype: float64 Empty DataFrame
27 Columns: [now_gap]
28 Index: [] nan
29 2023-08-21 17:37:00 NaN
30 2023-08-21 17:38:00 NaN
31 2023-08-21 17:39:00 NaN
32 2023-08-21 17:40:00 NaN
33 2023-08-21 17:41:00 NaN
34 ..
35 2023-08-22 05:52:00 NaN
36 2023-08-22 05:53:00 NaN
37 2023-08-22 05:54:00 NaN
38 2023-08-22 05:55:00 NaN
39 2023-08-22 05:56:00 NaN
40 Name: close, Length: 400, dtype: float64 Empty DataFrame
41 Columns: [now_gap]
42 Index: [] nan
43 2023-08-21 17:37:00 NaN
44 2023-08-21 17:38:00 NaN
45 2023-08-21 17:39:00 NaN
46 2023-08-21 17:40:00 NaN
47 2023-08-21 17:41:00 NaN
48 ..
49 2023-08-22 05:49:00 NaN
50 2023-08-22 05:50:00 NaN
51 2023-08-22 05:51:00 NaN
52 2023-08-22 05:52:00 NaN
53 2023-08-22 05:53:00 NaN
54 Name: close, Length: 400, dtype: float64 Empty DataFrame
55 Columns: [now_gap]
56 Index: [] nan
57 2023-08-21 17:37:00 NaN
58 2023-08-21 17:38:00 NaN
59 2023-08-21 17:39:00 NaN
60 2023-08-21 17:40:00 NaN
61 2023-08-21 17:41:00 NaN
62 ..
63 2023-08-22 05:52:00 NaN
64 2023-08-22 05:53:00 NaN
65 2023-08-22 05:54:00 NaN
66 2023-08-22 05:55:00 NaN
67 2023-08-22 05:56:00 NaN
68 Name: close, Length: 400, dtype: float64 Empty DataFrame
69 Columns: [now_gap]
70 Index: [] nan
Thank you!
What I have tried:
I have tried to make the length of the
binance
and
upbit
's close dataframe the same, but it didn't work.