Created
June 16, 2017 08:23
-
-
Save KolevDarko/93068c22b82099781bcb20fc3247c9d5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def calc_percent_diff(now, base): | |
difference = now - base | |
return difference * 100 / base | |
def calculate_profits(cc, latest_bid, starting_price, amount, limit_type, limit): | |
difference = abs((latest_bid - starting_price) * amount) | |
single_diff = latest_bid - starting_price | |
if limit_type == 'percent': | |
percent_difference = calc_percent_diff(latest_bid, starting_price) | |
if percent_difference >= limit: | |
return "The bitcoin price has increased by {:.2f} %, you have a profit of {:.2f} {}\n That is {:.2f} {} per coin.".format(percent_difference, difference, cc, abs(single_diff), cc) | |
elif percent_difference <= -1 * limit: | |
return "The bitcoin price has decreased by {:.2f} %, you have a loss of {:.2f} {}\n That is {:.2f} {} per coin.".format(abs(percent_difference), difference, cc, abs(single_diff), cc) | |
else: | |
if single_diff >= limit: | |
return "The bitcoin price has increased by {:.2f} {}, you have a profit of {:.2f} {}\n That is {:.2f} {} per coin.".format(single_diff, cc, difference, cc, abs(single_diff), cc) | |
elif single_diff <= -1 * limit: | |
return "The bitcoin price has decreased by {:.2f} {}, you have a loss of {:.2f} {}\n That is {:.2f} {} per coin.".format(single_diff, cc, abs(difference), cc, abs(single_diff), cc) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment