Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python Port Docs #78

Open
jonnyhoff opened this issue Jan 6, 2023 · 1 comment
Open

Python Port Docs #78

jonnyhoff opened this issue Jan 6, 2023 · 1 comment
Assignees

Comments

@jonnyhoff
Copy link

Hiya,

Please add the Python port docs.

Cheers,
Jonny

@kroitor kroitor self-assigned this Jul 31, 2023
@Rolladex
Copy link

Rolladex commented Oct 10, 2023

import time
import ccxt
import asciichartpy

#Define a dictionary for your crypto information
cryptocom = {
    "exchange_name": 'cryptocom',  # Use the exchange name as a string
    "pairs": ["ETH/BTC", "ETH/USD"]
}

#List of pairs
pairs = cryptocom["pairs"]

#Initialize the exchange using the exchange name
exchange = getattr(ccxt, cryptocom["exchange_name"])()

#Function to get and print the spot price
def get_spot_price(pair):
    ticker = exchange.fetch_ticker(pair)
    spot_price = ticker['last']
    print(f"Spot price of {pair}: {spot_price}")
    return spot_price

#Get and print your ETH balance in USD
get_USD = ETH_BAL * get_spot_price(pairs[2])
print(f"Your ETH balance in USD is {get_USD}")

#Refactored code for updating ETH spot price
interval = 30
ETH_SPOT = []
plot_data = []

def fetch_and_update_spot_price():
    while True:
        ticker = get_spot_price(pairs[2])
        ETH_SPOT.append(ticker)
        
        if len(ETH_SPOT) == 2:
            change = ETH_SPOT[1] - ETH_SPOT[0]
            plot_data.append(change)
            s = plot_data
            chart = asciichartpy.plot(s, {'height': 10, 'padding': '      ', 'offset': 5})
            print(chart)
            ETH_SPOT.pop(0)
        
        time.sleep(0.5)

        #Sleep for 30 seconds, not in a loop
        time.sleep(interval)

#Call the function to start updating the spot price
fetch_and_update_spot_price()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants