-
Notifications
You must be signed in to change notification settings - Fork 0
/
CryptoAccount.py
265 lines (225 loc) · 8.96 KB
/
CryptoAccount.py
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# Crypto Account Monitor
# A class which holds all of the values needed to make
# informed decisions what to do with a particular cryptocurrency
# and then perform an action on that cryptocurrency account on coinbase pro
from CryptoStates import CryptoCurrencyPercentageStates
from CryptoSettings import CryptoSettings
class CryptoAccountTracker:
def __init__(self, accountId: str, productId: str,
cryptoName: str, cryptoID: str, minSize: float,
cryptoSettingsJsonRaw):
self.__accountId = accountId # the account ID on coinbase pro
self.__productId = productId # the product ID pair for trading, EX: BTC-USD
self.__cryptoName = cryptoName
self.__cryptoID = cryptoID
self.__minSize = minSize
self.__referencePrice = 0.0 # in USD
self.__currentPrice = 0.0 # in USD
self.__priceSinceLastTransaction = 0.0 # The price of the crypto during the latest transaction
self.__percentage = 0.0
self.__cryptoPercentageState = CryptoCurrencyPercentageStates.Neutral
self.__currentHoldings = 0.0
# How much assets are stored in the cryptocurrency portfolio compared
# to the rest
self.__portfolioPercentage = 0.0
self.__activePurchases = []
self.__renewPriceFlag = True
self.__cryptoSettings = self.__InitCryptoSettings(cryptoSettingsJsonRaw)
def __InitCryptoSettings(self, cryptoSettingsJsonRaw):
cryptoSettings = CryptoSettings()
cryptoSettings.id = cryptoSettingsJsonRaw["id"]
cryptoSettings.LowPercentageThreshold = float(cryptoSettingsJsonRaw["LowPercentageThreshold"])
cryptoSettings.HighPercentageThreshold = float(cryptoSettingsJsonRaw["HighPercentageThreshold"])
cryptoSettings.LowToUpBuyInPercentageThreshold = float(cryptoSettingsJsonRaw["LowToUpBuyInPercentageThreshold"])
cryptoSettings.MaxPercentageDown = float(cryptoSettingsJsonRaw["MaxPercentageDown"])
cryptoSettings.HighToDownSellOutPercentageThreshold = float(cryptoSettingsJsonRaw["HighToDownSellOutPercentageThreshold"])
cryptoSettings.AdjustReferencePriceDownThreshold = float(cryptoSettingsJsonRaw["AdjustReferencePriceDownThreshold"])
cryptoSettings.AdjustReferencePriceUpThreshold = float(cryptoSettingsJsonRaw["AdjustReferencePriceUpThreshold"])
cryptoSettings.SmallestAmountToBuyInUSD = float(cryptoSettingsJsonRaw["SmallestAmountToBuyInUSD"])
cryptoSettings.LargestAmountToBuyInUSD = float(cryptoSettingsJsonRaw["LargestAmountToBuyInUSD"])
cryptoSettings.MaxPortfolioPercentage = float(cryptoSettingsJsonRaw["MaxPortfolioPercentage"])
return cryptoSettings
"""
GetAccountId
@return: the account id linked to the
cryptocurreny account on coinbase pro
"""
def GetAccountId(self):
return self.__accountId
"""
GetProductId
@return: the product id linked to the
cryptocurrency account on coinbase pro
"""
def GetProductId(self):
return self.__productId
"""
GetCryptoName
@return: The name of the cryptocurrency used by
this account tracker
"""
def GetCryptoName(self):
return self.__cryptoName
"""
GetCryptoID
@return: The crypto ID of the cryptocurrency used by
this account tracker
"""
def GetCryptoID(self):
return self.__cryptoID
"""
GetMinSize
@return: The min trading size allowed for buying and selling
this particular crypto currency
"""
def GetMinSize(self):
return self.__minSize
#TODO: test
def SetRenewPriceFlag(self, renewPriceFlagValue):
self.__renewPriceFlag = renewPriceFlagValue
#TODO: test
def GetRenewPriceFlag(self):
return self.__renewPriceFlag
"""
SetReferencePrice
@param referencePrice: The price to set as a
reference for the percentage
"""
def SetReferencePrice(self, referencePrice: float):
self.__referencePrice = referencePrice
"""
GetReferencePrice
@return: the current reference price set
"""
def GetReferencePrice(self):
return self.__referencePrice
#TODO: test
def SetPortfolioPercentage(self, portfolioPercentage: float):
self.__portfolioPercentage = portfolioPercentage
#TODO: test
def GetPortfolioPercentage(self):
return self.__portfolioPercentage
"""
SetPriceSinceLastTransaction
@param priceSinceLastTransaction: The price of the crypto currency
when the last transaction was completed
"""
def SetPriceSinceLastTransaction(self, priceSinceLastTransaction: float):
self.__priceSinceLastTransaction = priceSinceLastTransaction
"""
GetPriceSinceLastTransaction
@return: The price of the crypto currency when
the last transaction was completed
"""
def GetPriceSinceLastTransaction(self):
return self.__priceSinceLastTransaction
"""
SetCurrentPrice
@param currentPrice: The current price to set
"""
def SetCurrentPrice(self, currentPrice: float):
self.__currentPrice = currentPrice
"""
GetCurrentPrice
@return: the current price of the crypto currency
"""
def GetCurrentPrice(self):
return self.__currentPrice
"""
CalculatePercentage
Calculates the percentage standing of the crypto currency
using the reference price and the current price
"""
def CalculatePercentage(self):
self.__percentage = round(((float(self.__currentPrice) / float(self.__referencePrice)) - 1) * 100, 2)
"""
GetPercentage
@return: The percentage standing of the cryptocurrency
"""
def GetPercentage(self):
return self.__percentage
"""
SetCryptoPercentageState
@param: cryptoPercentageState: the percentage state of the
crypto currency (up, down, neutral, etc.) to set
"""
def SetCryptoPercentageState(self, cryptoPercentageState: CryptoCurrencyPercentageStates):
self.__cryptoPercentageState = cryptoPercentageState
"""
GetCryptoPercentageState
@return: the percentage state of the crypto currency
"""
def GetCryptoPercentageState(self):
return self.__cryptoPercentageState
"""
SetCurrentHoldingsInCoin
@param currentHoldingsInCoin: The current amount of crypto currency
the account is holding in the native coin
"""
def SetCurrentHoldingsInCoin(self, currentHoldingsInCoin: float):
self.__currentHoldings = currentHoldingsInCoin
"""
GetCurrentHoldingsInCoin
@return: the current amount of crypto currency
the account is holding in the native coin
"""
def GetCurrentHoldingsInCoin(self):
return self.__currentHoldings
"""
GetCurrentHoldingsInUSD
@return: the current amount of crypto currency
the account is holding in USD
"""
def GetCurrentHoldingsInUSD(self):
return round(self.__currentHoldings * self.__currentPrice, 2)
"""
AddActivePurchase
Adds an active purchase for the crypto account tracker to keep
track of
@param amountBoughtInCoin: The amount of crypto coin spent on the purchase
"""
def AddActivePurchase(self, amountBoughtInCoin: float):
self.__activePurchases.append([amountBoughtInCoin,
self.__currentPrice, # This is the reference price
self.__currentPrice,
CryptoCurrencyPercentageStates.Neutral])
#TODO: test
def RestoreActivePurchasesFromBackup(self, activePurchaseBackup):
self.__activePurchases = activePurchaseBackup
"""
UpdateActivePurchasePercentageState
Updates the Percentage State of a particular active purchase
@param index: the index of the particular active purchase
@param percentageState: The percentage state of the particular active purchase
to set
"""
def UpdateActivePurchasePercentageState(self, index: int, percentageState):
self.__activePurchases[index][3] = percentageState
"""
UpdateActivePurchaseReferencePrice
Updates the Reference Price of a particular active purchase
@param index: the index of the particular active purchase
@param reference: The reference price of the particular active purchase
to set
"""
def UpdateActivePurchaseReferencePrice(self, index: int, referencePrice: float):
self.__activePurchases[index][1] = referencePrice
"""
RemoveActivePurchase
Removes an active purchase from the list of active purchases
@param activePurchaseToRemove: the active purchase to remove from the list
"""
def RemoveActivePurchase(self, activePurchaseToRemove):
self.__activePurchases.remove(activePurchaseToRemove)
"""
GetActivePurchases
@return: the list of active purchases
"""
def GetActivePurchases(self):
return self.__activePurchases
"""
GetCryptoSettings
@return: The settings related to this crypto account
"""
def GetCryptoSettings(self):
return self.__cryptoSettings