aboutsummaryrefslogtreecommitdiff
path: root/portfolio.py
diff options
context:
space:
mode:
Diffstat (limited to 'portfolio.py')
-rw-r--r--portfolio.py36
1 files changed, 32 insertions, 4 deletions
diff --git a/portfolio.py b/portfolio.py
index fc468c2..cb14c5d 100644
--- a/portfolio.py
+++ b/portfolio.py
@@ -13,8 +13,8 @@ class Portfolio:
13 def repartition_pertenthousand(cls, liquidity="medium"): 13 def repartition_pertenthousand(cls, liquidity="medium"):
14 cls.parse_cryptoportfolio() 14 cls.parse_cryptoportfolio()
15 liquidities = cls.liquidities[liquidity] 15 liquidities = cls.liquidities[liquidity]
16 last_date = sorted(liquidities.keys())[-1] 16 cls.last_date = sorted(liquidities.keys())[-1]
17 return liquidities[last_date] 17 return liquidities[cls.last_date]
18 18
19 @classmethod 19 @classmethod
20 def get_cryptoportfolio(cls): 20 def get_cryptoportfolio(cls):
@@ -360,24 +360,52 @@ class Trade:
360 if inverted: 360 if inverted:
361 ticker = ticker["original"] 361 ticker = ticker["original"]
362 rate = Trade.compute_value(ticker, self.order_action(inverted), compute_value=compute_value) 362 rate = Trade.compute_value(ticker, self.order_action(inverted), compute_value=compute_value)
363 # 0.1
363 364
364 # We can use that amount of BTC:
365 delta_in_base = abs(self.value_from - self.value_to) 365 delta_in_base = abs(self.value_from - self.value_to)
366 # 9 BTC's worth of move (10 - 1 or 1 - 10 depending on case)
366 367
367 if not inverted: 368 if not inverted:
368 if self.action == "sell": 369 if self.action == "sell":
370 # I have 10 BTC worth of FOO, and I want to sell 9 BTC worth of it
371 # At rate 1 Foo = 0.1 BTC
369 value_from = self.value_from.linked_to 372 value_from = self.value_from.linked_to
373 # value_from = 100 FOO
370 value_to = self.value_to.in_currency(self.currency, self.market, rate=1/self.value_from.rate) 374 value_to = self.value_to.in_currency(self.currency, self.market, rate=1/self.value_from.rate)
375 # value_to = 10 FOO (1 BTC * 1/0.1)
371 delta = abs(value_to - value_from) 376 delta = abs(value_to - value_from)
377 # delta = 90 FOO
378 # Action: "sell" "90 FOO" at rate "0.1" "BTC" on "market"
379
380 # Note: no rounding error possible: if we have value_to == 0, then delta == value_from
372 else: 381 else:
373 delta = delta_in_base.in_currency(self.currency, self.market, rate=1/rate) 382 delta = delta_in_base.in_currency(self.currency, self.market, rate=1/rate)
383 # I want to buy 9 / 0.1 FOO
384 # Action: "buy" "90 FOO" at rate "0.1" "BTC" on "market"
385
386 # FIXME: Need to round up to the correct amount of FOO in case
387 # we want to use all BTC
374 currency = self.base_currency 388 currency = self.base_currency
389 # BTC
375 else: 390 else:
376 if self.action == "sell": 391 if self.action == "sell":
377 delta = delta_in_base.in_currency(self.base_currency, self.market, rate=rate) 392 # I have 10 BTC worth of FOO, and I want to sell 9 BTC worth of it
393 # At rate 1 Foo = 0.1 BTC
394 delta = delta_in_base
395 # Action: "buy" "9 BTC" at rate "1/0.1" "FOO" on market
396
397 # FIXME: Need to round up to the correct amount of FOO in case
398 # we want to sell all
378 else: 399 else:
379 delta = delta_in_base 400 delta = delta_in_base
401 # I want to buy 9 / 0.1 FOO
402 # Action: "sell" "9 BTC" at rate "1/0.1" "FOO" on "market"
403
404 # FIXME: Need to round up to the correct amount of FOO in case
405 # we want to use all BTC
406
380 currency = self.currency 407 currency = self.currency
408 # FOO
381 409
382 self.orders.append(Order(self.order_action(inverted), delta, rate, currency, self.market)) 410 self.orders.append(Order(self.order_action(inverted), delta, rate, currency, self.market))
383 411