Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import ccxt
- import time
- from datetime import datetime
- import os
- symbol = 'BTC/USDT'
- def fetch_and_print_ticker():
- ticker = exchange.fetch_ticker(symbol)
- timestamp = ticker['timestamp']
- datetime_str = datetime.utcfromtimestamp(timestamp / 1000.0).strftime('%Y-%m-%d %H:%M:%S')
- os.system('cls' if os.name == 'nt' else 'clear') # Clear the console based on the operating system
- # print('Ticker:', ticker)
- print(f"Symbol: {ticker['symbol']}")
- print(f"Timestamp: {datetime_str}")
- print(f"High: {ticker['high']}")
- print(f"Low: {ticker['low']}")
- print(f"Bid Price: {ticker['bid']}")
- print(f"Bid Volume: {ticker['bidVolume']}")
- print(f"Ask Price: {ticker['ask']}")
- print(f"Ask Volume: {ticker['askVolume']}")
- print(f"Last Price: {ticker['last']}")
- print(f"Change: {ticker['change']}")
- print(f"Percentage Change: {ticker['percentage']}")
- print("------------------------------")
- # Create a Binance instance without API credentials
- exchange = ccxt.binance()
- # Fetch and print ticker information every 5 seconds (adjust as needed)
- while True:
- fetch_and_print_ticker()
- time.sleep(5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement