From cb4668f09350fcd74a020e227f9e2bf392a897d4 Mon Sep 17 00:00:00 2001 From: AvishaiW Date: Tue, 6 Mar 2018 00:05:29 +0200 Subject: [PATCH] BUG: #243 added a function which reduces open orders amount from calculated target/amount for target orders --- catalyst/exchange/exchange_algorithm.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/catalyst/exchange/exchange_algorithm.py b/catalyst/exchange/exchange_algorithm.py index b9c319f1..abaaea14 100644 --- a/catalyst/exchange/exchange_algorithm.py +++ b/catalyst/exchange/exchange_algorithm.py @@ -163,6 +163,25 @@ class ExchangeTradingAlgorithmBase(TradingAlgorithm): style) return amount, style + def _calculate_order_target_amount(self, asset, target): + """ + removes order amounts so we won't run into issues + when two orders are placed one after the other. + it then proceeds to removing positions amount at TradingAlgorithm + :param asset: + :param target: + :return: target + """ + if asset in self.blotter.open_orders: + for open_order in self.blotter.open_orders[asset]: + current_amount = open_order.amount + target -= current_amount + + target = super(ExchangeTradingAlgorithmBase, self). \ + _calculate_order_target_amount(asset, target) + + return target + def round_order(self, amount, asset): """ We need fractions with cryptocurrencies