Giter Club home page Giter Club logo

Comments (4)

S-razmi avatar S-razmi commented on July 19, 2024

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

from deeplob.

nPokemon avatar nPokemon commented on July 19, 2024

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

from deeplob.

S-razmi avatar S-razmi commented on July 19, 2024

from deeplob.

nPokemon avatar nPokemon commented on July 19, 2024

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

Load config.json

with open('config.json', 'r') as f:
config = json.load(f)

Initialize Binance Client

client = Client(config['BINANCE_KEY_API'], config['BINANCE_SECRET_API'])

def download_data(trading_pair):
try:
### Interact with Binance API to get the order book depth
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:
### Handle the continuous downloading of data.
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()

from deeplob.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.