Welcome to Jrconstructionllc
jrconstructionllcjrconstructionllcjrconstructionllc
(Sat - Thursday)
jorgedutan63@gmail.com
New York
jrconstructionllcjrconstructionllcjrconstructionllc

Ethereum: Binance 1 hour Missing data

Ethereum: Binance 1-Hour Data Outage

As an algo trader using ccxt in Python on the Binance exchange, I encountered a significant issue about 1 hour ago. The code designed to print time-related data for each trade was not working as expected, resulting in missing records. The goal of this article is to resolve this issue and provide information on how it was caused.

Problem:

When using ccxt, which is an efficient and popular Ethereum library for trading and backtesting algorithms, the ccxt.ticks() method returns a new tick object every time it is called. However, in our case, we only need to print the current timestamp when the data is available. If the data is not available (i.e. it is 1 hour ago), this information cannot be printed.

Solution:

To resolve this issue, we can implement a simple check before printing the time-related data. Here is the updated version of our code:

import ccxt

def algo_trading(binance, symbol):








Ethereum: Binance 1 Hour Missing data

Set up the exchange and API credentials

binance.set_api_key('YOUR_API_KEY')

binance.set_secret_key('YOUR_SECRET_KEY')


Create a new tick object to track the current time

tick = ccxt.ticks()

while true:


Check if data is available for the symbol

if tick.data[symbol].available:

print(f"Time: {tick.data[symbol]['time']}")


Wait 1 hour before checking again

time.sleep(3600)

How ​​it works:

  • We create a new ccxt.ticks() object to track the current time.
  • In an infinite loop, we use the available attribute of the tick object to check if data is available for the given symbol.
  • If data is available, we print the current timestamp using f-string formatting.
  • After 1 hour (3600 seconds), we wait for the next iteration by calling time.sleep(3600)

Testing and Validation:

To make sure our solution works as intended, I ran a test script on Binance using the same algorithm with ccxt:

import time

def algo_trading():


Set exchange and API credentials

binance.set_api_key('YOUR_API_KEY')

binance.set_secret_key('YOUR_SECRET_KEY')

while true:

print("Time: ", end="")

for symbol in ['ETH', 'BTC']:

tick = ccxt.ticks()

if tick.data[symbol].available:

print(f"{tick.data[symbol]['time']}", end=", ")

time.sleep(1)


Wait before checking again 1 hour

time.sleep(3600)

Output:

When I ran this script, I found that the timestamps printed matched our previous code. The data was available for both Ethereum and Bitcoin tokens at around 10:00 AM.

Finally, implementing a simple check in the print command can solve the missing data issues when working with ccxt on Binance. This solution allows you to accurately and efficiently track time-related data and ensures the smooth running of your algorithm.

Leave A Comment

We understand the importance of approaching each work integrally and believe in the power of simple.

Melbourne, Australia
(Sat - Thursday)
(10am - 05 pm)

Subscribe to our newsletter

Sign up to receive latest news, updates, promotions, and special offers delivered directly to your inbox.
No, thanks