Giter Site home page Giter Site logo

Python Port Docs about asciichart HOT 1 OPEN

kroitor avatar kroitor commented on May 16, 2024 1
Python Port Docs

from asciichart.

Comments (1)

Rolladex avatar Rolladex commented on May 16, 2024
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()

from asciichart.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.