aboutsummaryrefslogtreecommitdiff
path: root/portfolio.py
diff options
context:
space:
mode:
Diffstat (limited to 'portfolio.py')
-rw-r--r--portfolio.py28
1 files changed, 20 insertions, 8 deletions
diff --git a/portfolio.py b/portfolio.py
index e98689e..17a17ba 100644
--- a/portfolio.py
+++ b/portfolio.py
@@ -3,6 +3,7 @@ from datetime import datetime
3from decimal import Decimal as D, ROUND_DOWN 3from decimal import Decimal as D, ROUND_DOWN
4# Put your poloniex api key in market.py 4# Put your poloniex api key in market.py
5from json import JSONDecodeError 5from json import JSONDecodeError
6from ccxt import ExchangeError, ExchangeNotAvailable
6import requests 7import requests
7import helper as h 8import helper as h
8from store import * 9from store import *
@@ -463,6 +464,11 @@ class Order:
463 else: 464 else:
464 try: 465 try:
465 self.results.append(self.market.create_order(symbol, 'limit', self.action, amount, price=self.rate, account=self.account)) 466 self.results.append(self.market.create_order(symbol, 'limit', self.action, amount, price=self.rate, account=self.account))
467 except ExchangeNotAvailable:
468 # Impossible to honor the order (dust amount)
469 self.status = "closed"
470 self.mark_finished_order()
471 return
466 except Exception as e: 472 except Exception as e:
467 self.status = "error" 473 self.status = "error"
468 print("error when running market.create_order('{}', 'limit', '{}', {}, price={}, account={})".format( 474 print("error when running market.create_order('{}', 'limit', '{}', {}, price={}, account={})".format(
@@ -526,7 +532,10 @@ class Order:
526 return filled_amount 532 return filled_amount
527 533
528 def fetch_mouvements(self): 534 def fetch_mouvements(self):
529 mouvements = self.market.privatePostReturnOrderTrades({"orderNumber": self.id}) 535 try:
536 mouvements = self.market.privatePostReturnOrderTrades({"orderNumber": self.id})
537 except ExchangeError:
538 mouvements = []
530 self.mouvements = [] 539 self.mouvements = []
531 540
532 for mouvement_hash in mouvements: 541 for mouvement_hash in mouvements:
@@ -544,14 +553,17 @@ class Mouvement:
544 def __init__(self, currency, base_currency, hash_): 553 def __init__(self, currency, base_currency, hash_):
545 self.currency = currency 554 self.currency = currency
546 self.base_currency = base_currency 555 self.base_currency = base_currency
547 self.id = hash_["id"] 556 self.id = hash_.get("tradeID")
548 self.action = hash_["type"] 557 self.action = hash_.get("type")
549 self.fee_rate = D(hash_["fee"]) 558 self.fee_rate = D(hash_.get("fee", -1))
550 self.date = datetime.strptime(hash_["date"], '%Y-%m-%d %H:%M:%S') 559 try:
551 self.rate = D(hash_["rate"]) 560 self.date = datetime.strptime(hash_.get("date", ""), '%Y-%m-%d %H:%M:%S')
552 self.total = Amount(currency, hash_["amount"]) 561 except ValueError:
562 self.date = None
563 self.rate = D(hash_.get("rate", 0))
564 self.total = Amount(currency, hash_.get("amount", 0))
553 # rate * total = total_in_base 565 # rate * total = total_in_base
554 self.total_in_base = Amount(base_currency, hash_["total"]) 566 self.total_in_base = Amount(base_currency, hash_.get("total", 0))
555 567
556if __name__ == '__main__': # pragma: no cover 568if __name__ == '__main__': # pragma: no cover
557 from market import market 569 from market import market