J2897 icon

CCXT Ticker Example

J2897 | PRO | 01/25/24 02:27:46 AM UTC | 0 ⭐ | 1392 👁️ | Never ⏰ | []
Python |

1.16 KB

|

None

|

0 👍

/

0 👎

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)
 

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎