-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBTC-Sim.py
More file actions
103 lines (82 loc) · 3.15 KB
/
BTC-Sim.py
File metadata and controls
103 lines (82 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Ethan Hopkins
import random
from datetime import datetime
import pytz
class Wallet:
def __init__(self, ticker, coinCount):
self.ticker = ticker
self.coinCount = coinCount
def checkAmount(self):
print(self.ticker + str(self.coinCount))
class Ledger:
def __init__(self, history):
self.history = history
def printHistory(self):
print("Account history:", self.history)
class MyDate:
def date():
return datetime.now(pytz.timezone('America/Los_Angeles')).strftime("%B %d, %Y at %I:%M %p")
class GetLive:
def fluctuations():
return random.randint(10000,12000)
bal = 20000
bitcoinCount = Wallet("BTC", 0)
bitcoinVal = GetLive.fluctuations()
record = Ledger([])
def BitcoinSimulator():
choice = int(input("Choose an option — \n\n1) Check Current Bitcoin Value\n2) Purchase Bitcoin\n3) Sell Bitcoin\n4) View User Portfolio\n5) View Transaction History\n\nEnter choice: "))
def check():
global bitcoinVal
print("\nCurrent value of " + bitcoinCount.ticker + ": $" + str(bitcoinVal) + "\n")
BitcoinSimulator()
def buy():
global bitcoinVal
global bal
global record
bitcoinVal = GetLive.fluctuations()
purchased = float(input("How many Bitcoins would you like to purchase? "))
if (bal >= (bitcoinVal * purchased)):
bitcoinCount.coinCount += purchased
bal -= (bitcoinVal * purchased)
print("\n" + MyDate.date() + ": Purchased " + str(purchased) + " " + bitcoinCount.ticker + " for $" + str(bitcoinVal * purchased) + ".\n")
record.history.append(MyDate.date() + ": Purchased " + str(purchased) + " " + bitcoinCount.ticker + " for $" + str(bitcoinVal * purchased) + ".")
else:
print("\nError: Not enough funds to purchase " + str(purchased) + " " + bitcoinCount.ticker + ".\n")
BitcoinSimulator()
def sell():
global bitcoinVal
global bal
global record
bitcoinVal = GetLive.fluctuations()
sold = float(input("How many Bitcoins would you like to sell? "))
if (bitcoinCount.coinCount >= sold):
bal += (sold * bitcoinVal)
bitcoinCount.coinCount -= sold
print("\n" + MyDate.date() + ": Sold " + str(sold) + " " + bitcoinCount.ticker + " for $" + str(bitcoinVal * sold) + ".\n")
record.history.append(MyDate.date() + ": Sold " + str(sold) + " " + bitcoinCount.ticker + " for $" + str(bitcoinVal * sold) + ".")
else:
print("\nError: Your account has a total of " + str(bitcoinCount.coinCount) + " " + bitcoinCount.ticker + ", which is not enough to sell " + str(sold) + " " + bitcoinCount.ticker + ".\n")
BitcoinSimulator()
def bal():
global bal
print("\nYour portfolio: \n\n" + str(bal) + " USD\n" + str(bitcoinCount.coinCount) + " " + bitcoinCount.ticker + "\n")
BitcoinSimulator()
def history():
print("\nYour transaction history:\n")
if (len(record.history) > 0):
for recorded in record.history:
print(recorded)
else:
print("You do not have any transaction history.")
BitcoinSimulator()
if (choice == 1):
check()
elif (choice == 2):
buy()
elif (choice == 3):
sell()
elif (choice == 4):
bal()
elif (choice == 5):
history()
BitcoinSimulator()