Post
Topic
Board Speculation
Merits 5 from 5 users
Re: Wall Observer BTC/USD - Bitcoin price movement tracking & discussion
by
fillippone
on 30/09/2023, 15:34:27 UTC
⭐ Merited by xhomerx10 (1) ,JayJuanGee (1) ,SamReomo (1) ,vapourminer (1) ,philipma1957 (1)
Too much, buddy  Angry


EDIT: I'd recommend to change Buddy's policy to post a price update only if it moved by a certain amount of dollars.

Post a buddychart only if price moves more than 1% either direction since last post. Else wait another 60 minutes and check again.


Code:

import ccxt
import time

# Initialize the exchange
exchange = ccxt.binance()  # You can replace 'binance' with your preferred exchange

# Function to get current Bitcoin price
def get_bitcoin_price():
    ticker = exchange.fetch_ticker('BTC/USDT')
    return ticker['last']

# Function to make a post
def make_post(price_change):
    # Replace this with your actual post logic
    print(f"Bitcoin price changed by {price_change}%")

# Main loop
while True:
    try:
        # Get the current price
        current_price = get_bitcoin_price()

        # Check if there was a 1% change from the last post
        if 'last_price' in locals() and abs(current_price - last_price) / last_price > 0.01:
            make_post(abs(current_price - last_price) / last_price * 100)

        # Update last_price
        last_price = current_price

    except Exception as e:
        print(f"An error occurred: {e}")

    # Wait for 60 minutes
    time.sleep(60 * 60)



This would also make @philipma1957 happy.