def main(): inv.reset_investment_tables() test_buy('BTC') test_sell_in_coin('BTC') test_num_in_current_holdings('BTC') test_usd_amount() test_partial_sell_in_coin('BTC') inv.reset_investment_tables()
def test_buy(symbol): inv.reset_investment_tables() global amount_to_buy inv.buy_in_USD(amount_to_buy, inv.get_gmt_time(), symbol) current_num_btc = inv.get_current_holdings(symbol) translate_to_usd_btc = current_num_btc * inv.get_current_price_from_db(symbol) if translate_to_usd_btc == amount_to_buy: print(f"{bcolors.OKGREEN}Buying coin passed{bcolors.ENDC}") else: print(f"{bcolors.FAIL}Buying coin failed{bcolors.ENDC}")
def test_usd_amount(): global amount_to_buy inv.reset_investment_tables() current_balance = inv.get_USD() if current_balance == 100: print(f"{bcolors.OKGREEN}current balance 100 after reset{bcolors.ENDC}") else: print(f"{bcolors.FAIL}current balance not 100 after reset{bcolors.ENDC}") test_buy('BTC') current_balance = inv.get_USD() if current_balance == 100 - amount_to_buy: print(f"{bcolors.OKGREEN}current balance ok after buy{bcolors.ENDC}") else: print(f"{bcolors.FAIL}current balance not ok after buy{bcolors.ENDC}")
def test_partial_sell_in_coin(symbol): inv.reset_investment_tables() test_buy(symbol) #get $10 of symbol num_coin_units = inv.get_current_holdings(symbol) / 2 inv.sell_sell_sell(num_coin_units, inv.get_gmt_time(), symbol) #sell half coins current_num_coin = inv.get_current_holdings(symbol) cumu_gain = inv.get_current_gain(symbol) current_num_coin = inv.get_current_holdings(symbol) if current_num_coin == num_coin_units: print(f"{bcolors.OKGREEN}Selling half coin units passed{bcolors.ENDC}") ### now need to test for cumu_spend_since_zero time.sleep(20) #need to wait for market data to change price test_cumu_spend_since_zero(symbol) else: print(f"{bcolors.FAIL}Selling coin units back to zero failed{bcolors.ENDC}")
def main(): while(True): action = input("waiting for input...") if action == 'buy': amount = inp.inputNum("amount? (in USD) $") coin = input("symbol? ") inv.buy_in_USD(amount, inv.get_gmt_time(), str.upper(coin)) elif action == 'sell': amount = inp.inputNum("amount? ") coin = input("symbol? ") inv.sell_sell_sell(amount, inv.get_gmt_time(), str.upper(coin)) elif action == 'report': report(input("type? ")) elif action == 'restart': inv.reset_investment_tables() elif action == 'restart coins': inv.reset_coin_tables() elif action == 'help': help() elif action == 'exit': break