-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbitcoin.py
More file actions
100 lines (79 loc) · 2.96 KB
/
bitcoin.py
File metadata and controls
100 lines (79 loc) · 2.96 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
# Henry Marks
import random
from datetime import date
class Wallet:
def __init__(self, ticker, current_holdings, value):
self.ticker = ticker
self.current_holdings = current_holdings
self.value = value
def data(self):
return self.ticker + " - " + str(self.current_holdings)
class Getlive:
def __init__ (self, currency):
self.currency = currency
def get_price(self):
if(self.currency == "BTC"):
return random.randint(30000,50000)
class MyDate:
def date():
return date.today()
class Leger:
def __init__ (self, type, amount, date):
self.type = type
self.amount = amount
self.date = date
def __str__(self):
return "type:% s amount:% s date:% s" % (self.type, self.amount, self.date)
wallet = Wallet("BTC", 0, 0)
blockchain = []
def bit_sim(balance, previous_price):
menu_data = input("Please enter your query " )
menu_data = menu_data.split(' ')
int; currency_price = Getlive("BTC").get_price()
request = menu_data[0]
if len(menu_data) > 1:
global params
params = menu_data[1]
params = float(params)
if(previous_price != ''):
currency_price = previous_price
if(request == "price"):
print(str(currency_price) + "$")
bit_sim(balance, currency_price)
elif(request == "buy"):
cost = params * currency_price
if(cost <= balance):
print("You bought " + str(params) + " BTC at " + str(currency_price))
balance = balance - cost
wallet.current_holdings = wallet.current_holdings + params
wallet.value = wallet.value + cost
node = str(Leger("Buy",params, MyDate.date()))
blockchain.append(node)
bit_sim(balance, '')
else:
print("Incefficent funds try again")
bit_sim(balance, currency_price)
elif(request == "sell"):
if(wallet.current_holdings != 0 and wallet.current_holdings >= params):
cash = params * currency_price
print("You sold " + str(params) + " BTC for " + str(currency_price))
balance = balance + cash
wallet.current_holdings = wallet.current_holdings - params
wallet.value = wallet.value - cash
node = str(Leger("Sell",params, MyDate.date()))
blockchain.append(node)
bit_sim(balance, '')
else:
print("You either didn't have any crypto or tried to sell too many coins")
elif(request == "balance"):
print("your cash balance is " + str(balance))
print("your crypto balance is " + str(wallet.data()))
bit_sim(balance, currency_price)
elif(request == "history"):
print(blockchain)
bit_sim(balance, currency_price)
elif(request == "wait"):
bit_sim(balance, '')
elif(request == "exit"):
print("Thanks for playing")
bit_sim(100000, '')