]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Trader.git/blobdiff - portfolio.py
Merge branch 'dev'
[perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Trader.git] / portfolio.py
index bed43261d70d127c1e4aca08b5b3baf9e9bbdfef..1d291069bfa08c7cb497e90046de010e6d7f2e02 100644 (file)
@@ -4,6 +4,10 @@ from decimal import Decimal as D, ROUND_DOWN
 from ccxt import ExchangeError, InsufficientFunds, ExchangeNotAvailable, InvalidOrder, OrderNotCached, OrderNotFound, RequestTimeout, InvalidNonce
 
 class Computation:
+    @staticmethod
+    def eat_several(market):
+        return lambda x, y: market.ccxt.fetch_nth_order_book(x["symbol"], y, 15)
+
     computations = {
             "default": lambda x, y: x[y],
             "average": lambda x, y: x["average"],
@@ -48,7 +52,7 @@ class Amount:
                     ticker=asset_ticker,
                     rate=rate)
         else:
-            raise Exception("This asset is not available in the chosen market")
+            return Amount(other_currency, 0, linked_to=self, ticker=None, rate=0)
 
     def as_json(self):
         return {
@@ -288,8 +292,12 @@ class Trade:
         if tick in self.tick_actions:
             update, compute_value = self.tick_actions[tick]
         elif tick % 3 == 1:
-            update = "market_adjust"
-            compute_value = "default"
+            if tick < 20:
+                update = "market_adjust"
+                compute_value = "default"
+            else:
+                update = "market_adjust_eat"
+                compute_value = Computation.eat_several(self.market)
         else:
             update = "waiting"
             compute_value = None