aboutsummaryrefslogtreecommitdiff
path: root/portfolio.py
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2018-01-18 01:00:57 +0100
committerIsmaël Bouya <ismael.bouya@normalesup.org>2018-01-18 01:00:57 +0100
commitf2da658998b6e6605c6ae27ff338ef23b96dce25 (patch)
treed6b720cdb6af89859c8bdde9b13bdf8d634b4ee8 /portfolio.py
parent183a53e3be74fabf501eaff19a39a47f1a6c9af5 (diff)
downloadTrader-f2da658998b6e6605c6ae27ff338ef23b96dce25.tar.gz
Trader-f2da658998b6e6605c6ae27ff338ef23b96dce25.tar.zst
Trader-f2da658998b6e6605c6ae27ff338ef23b96dce25.zip
Add Balance class tests
Diffstat (limited to 'portfolio.py')
-rw-r--r--portfolio.py11
1 files changed, 4 insertions, 7 deletions
diff --git a/portfolio.py b/portfolio.py
index a4fbf94..1d8bfd5 100644
--- a/portfolio.py
+++ b/portfolio.py
@@ -221,6 +221,10 @@ class Balance:
221 self.used = Amount(currency, used_value) 221 self.used = Amount(currency, used_value)
222 222
223 @classmethod 223 @classmethod
224 def from_hash(cls, currency, hash_):
225 return cls(currency, hash_["total"], hash_["free"], hash_["used"])
226
227 @classmethod
224 def in_currency(cls, other_currency, market, action="average", type="total"): 228 def in_currency(cls, other_currency, market, action="average", type="total"):
225 amounts = {} 229 amounts = {}
226 for currency in cls.known_balances: 230 for currency in cls.known_balances:
@@ -235,10 +239,6 @@ class Balance:
235 return cls.known_balances.keys() 239 return cls.known_balances.keys()
236 240
237 @classmethod 241 @classmethod
238 def from_hash(cls, currency, hash_):
239 return cls(currency, hash_["total"], hash_["free"], hash_["used"])
240
241 @classmethod
242 def _fill_balances(cls, hash_): 242 def _fill_balances(cls, hash_):
243 for key in hash_: 243 for key in hash_:
244 if key in ["info", "free", "used", "total"]: 244 if key in ["info", "free", "used", "total"]:
@@ -270,9 +270,6 @@ class Balance:
270 new_repartition = cls.dispatch_assets(total_base_value) 270 new_repartition = cls.dispatch_assets(total_base_value)
271 Trade.compute_trades(values_in_base, new_repartition, market=market) 271 Trade.compute_trades(values_in_base, new_repartition, market=market)
272 272
273 def __int__(self):
274 return int(self.total)
275
276 def __repr__(self): 273 def __repr__(self):
277 return "Balance({} [{}/{}/{}])".format(self.currency, str(self.free), str(self.used), str(self.total)) 274 return "Balance({} [{}/{}/{}])".format(self.currency, str(self.free), str(self.used), str(self.total))
278 275