Open nPokemon opened 9 months ago
Sure! a sample Dataset is available in my Kaggle with the notebook to run the code. https://www.kaggle.com/datasets/siavashraz/bitcoin-perpetualbtcusdtp-limit-order-book-data/data
Sorry, I mean , how can I download different data instead of BTCUSDT, because different tickers may have different MM to run right ? Like ETHUSDT ? SOLUSDT ? Thank you for helpin.g
You can get the data through different exchanges by their API. Binance, coinex and kucoin provide this data.
On Wed, Sep 27, 2023, 6:54 PM nPokemon @.***> wrote:
Sorry, I mean , how can I download different data instead of BTCUSDT, because different tickers may have different MM to run right ? Like ETHUSDT ? SOLUSDT ? Thank you for helpin.g
— Reply to this email directly, view it on GitHub https://github.com/S-razmi/DeepLOB/issues/1#issuecomment-1737621545, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKVCY73DOPECZN2YTA6OKSLX4RAKHANCNFSM6AAAAAA5JOSZSI . You are receiving this because you commented.Message ID: @.***>
Yes, Thank you, But I saw there are 40 columns of that can you help me to get the right data ? This is my code as Binance API documents, but did not see the correct format as your:
import json import time import csv import os from binance.client import Client from binance.exceptions import BinanceAPIException
with open('config.json', 'r') as f: config = json.load(f)
client = Client(config['BINANCE_KEY_API'], config['BINANCE_SECRET_API'])
def download_data(trading_pair): try:
depth = client.get_order_book(symbol=trading_pair, limit=20) # 20 bid and 20 ask levels
### Extracting timestamp, bids, and asks from the depth data
timestamp = depth['lastUpdateId']
datetime_str = time.strftime('%d/%m/%Y %H:%M', time.gmtime(time.time()))
bids = depth['bids']
asks = depth['asks']
### Include an additional unnamed index column at the start of each row
formatted_data = [None, timestamp, datetime_str] # None represents the unnamed index column
for bid, ask in zip(bids, asks):
### Append bid price, bid quantity, ask price, ask quantity alternately
formatted_data.extend([bid[0], bid[1], ask[0], ask[1]])
### Define the file name based on trading_pair and current date/time
file_name = f"{trading_pair}_LOB_{time.strftime('%Y%m%d%H%M%S')}.csv"
### Check if file exists to determine whether to write headers
file_exists = os.path.isfile(file_name)
### Open the file in append mode, if file does not exist, it will be created
with open(file_name, 'a', newline='') as file:
writer = csv.writer(file)
### Write headers if file is being created
if not file_exists:
headers = ['Timestamp', 'Datetime']
for i in range(1, 21):
headers.extend([f'Bid_Price_{i}', f'Bid_Quantity_{i}', f'Ask_Price_{i}', f'Ask_Quantity_{i}'])
writer.writerow(headers)
### Write the formatted data to the file
writer.writerow(formatted_data)
except BinanceAPIException as e:
print(f"Error occurred for {trading_pair}: {e.message}")
except Exception as e:
print(f"An unexpected error occurred for {trading_pair}: {str(e)}")
def main(): while True:
for trading_pair in config['TRADING_PAIRS']:
download_data(trading_pair)
time.sleep(config['REFRESH_TIME']) ### Sleep for the specified interval before downloading the next set of data.
if name == "main": main()
Could you help to download data for it or live data for different crypto please ?