Beispiel #1
0
def quitMenu():
    dramatic_typing("Do you want to try again? Y/N ")
    answer = input("").upper()
    if answer == 'Y':
        main()
    else:
        exit()
Beispiel #2
0
def main():
    welcome()
    coins = fetch_coins()
    currency, quantity = input_buy()
    try:
        price = coins[currency]['price']
    except Exception as e:
        dramatic_typing("Invalid currency entered, please try again \n")
        input_buy()
    run_simulation(coins[currency]['price'], quantity, currency)
    quitMenu()
Beispiel #3
0
def run_simulation(bought_price, quantity, currency):
    value_then = bought_price * quantity
    best_price, timestamp = fetch_best_bid(currency)
    best_value = best_price * quantity
    price_difference = (best_value - value_then)/float(value_then) * 100
    time = datetime.datetime.fromtimestamp(timestamp).strftime('%A, %B %-d, %Y %I:%M %p')
    print("The best bid price for {} was ${} at {} \n".format(currency, best_price, time))
    if price_difference > 0:
        dramatic_typing("Your total asset value is ${}, it has increased by {}% \n".format(round(best_value, 4), round(price_difference, 2)))
    else:
        dramatic_typing("Your total asset value is ${}, it has decreased by {} \n".format(round(best_value, 4), round(price_difference, 2)))
Beispiel #4
0
def welcome():
    print("\n")
    dramatic_typing("Simple Crypto Trading Simulator \n")
    dramatic_typing(
        "Hey Yo, you are back in time. It's Wednesday, March 7, 2018 7:39 AM \n"
    )
    dramatic_typing("Here are the crypto currencies you can invest. \n")
    dramatic_typing("Fetching prices ... \n")
Beispiel #5
0
def fetch_coins():
    connection = sqlite3.connect('./currency_monitor.db')
    cursor = connection.cursor()
    query = "SELECT first_leg, ask FROM prices WHERE timestamp='1520408341.52' AND second_leg='USD';"
    cursor.execute(query)
    coin_ask_prices = cursor.fetchall()
    coins = {}
    for coin_ask_price in coin_ask_prices:
        if coin_ask_price[0] in coins:
            continue
        coins[coin_ask_price[0]] = {
            "price": coin_ask_price[1],
            "curreny": coin_ask_price[0]
        }
        dramatic_typing("{} - ${} \n".format(coin_ask_price[0],
                                             round(coin_ask_price[1], 4)))
    return coins
Beispiel #6
0
def input_buy():
    dramatic_typing("Select the crypto currency you want to buy? \n")
    currency = input("").upper()
    dramatic_typing("That's great. How much quantity you want to buy? \n")
    quantity = float(input(""))
    return currency, quantity