diff options
Diffstat (limited to 'market.py')
-rw-r--r-- | market.py | 24 |
1 files changed, 19 insertions, 5 deletions
@@ -210,18 +210,32 @@ class Market: | |||
210 | self.report.log_stage("follow_orders_end") | 210 | self.report.log_stage("follow_orders_end") |
211 | 211 | ||
212 | def prepare_trades(self, base_currency="BTC", liquidity="medium", | 212 | def prepare_trades(self, base_currency="BTC", liquidity="medium", |
213 | compute_value="average", repartition=None, only=None): | 213 | compute_value="average", repartition=None, only=None, |
214 | available_balance_only=False): | ||
214 | 215 | ||
215 | self.report.log_stage("prepare_trades", | 216 | self.report.log_stage("prepare_trades", |
216 | base_currency=base_currency, liquidity=liquidity, | 217 | base_currency=base_currency, liquidity=liquidity, |
217 | compute_value=compute_value, only=only, | 218 | compute_value=compute_value, only=only, |
218 | repartition=repartition) | 219 | repartition=repartition, available_balance_only=available_balance_only) |
219 | 220 | ||
220 | values_in_base = self.balances.in_currency(base_currency, | 221 | values_in_base = self.balances.in_currency(base_currency, |
221 | compute_value=compute_value) | 222 | compute_value=compute_value) |
222 | total_base_value = sum(values_in_base.values()) | 223 | if available_balance_only: |
224 | balance = self.balances.all.get(base_currency) | ||
225 | if balance is None: | ||
226 | total_base_value = portfolio.Amount(base_currency, 0) | ||
227 | else: | ||
228 | total_base_value = balance.exchange_free + balance.margin_available | ||
229 | else: | ||
230 | total_base_value = sum(values_in_base.values()) | ||
223 | new_repartition = self.balances.dispatch_assets(total_base_value, | 231 | new_repartition = self.balances.dispatch_assets(total_base_value, |
224 | liquidity=liquidity, repartition=repartition) | 232 | liquidity=liquidity, repartition=repartition) |
233 | if available_balance_only: | ||
234 | for currency, amount in values_in_base.items(): | ||
235 | if currency != base_currency: | ||
236 | new_repartition.setdefault(currency, portfolio.Amount(base_currency, 0)) | ||
237 | new_repartition[currency] += amount | ||
238 | |||
225 | self.trades.compute_trades(values_in_base, new_repartition, only=only) | 239 | self.trades.compute_trades(values_in_base, new_repartition, only=only) |
226 | 240 | ||
227 | def print_tickers(self, base_currency="BTC"): | 241 | def print_tickers(self, base_currency="BTC"): |
@@ -292,7 +306,7 @@ class Processor: | |||
292 | "before": False, | 306 | "before": False, |
293 | "after": True, | 307 | "after": True, |
294 | "fetch_balances": ["begin", "end"], | 308 | "fetch_balances": ["begin", "end"], |
295 | "prepare_trades": { "only": "acquire" }, | 309 | "prepare_trades": { "only": "acquire", "available_balance_only": True }, |
296 | "prepare_orders": { "only": "acquire", "compute_value": "average" }, | 310 | "prepare_orders": { "only": "acquire", "compute_value": "average" }, |
297 | "move_balances": {}, | 311 | "move_balances": {}, |
298 | "run_orders": {}, | 312 | "run_orders": {}, |
@@ -326,7 +340,7 @@ class Processor: | |||
326 | "before": False, | 340 | "before": False, |
327 | "after": True, | 341 | "after": True, |
328 | "fetch_balances": ["begin", "end"], | 342 | "fetch_balances": ["begin", "end"], |
329 | "prepare_trades": {}, | 343 | "prepare_trades": { "available_balance_only": True }, |
330 | "prepare_orders": { "compute_value": "average" }, | 344 | "prepare_orders": { "compute_value": "average" }, |
331 | "move_balances": {}, | 345 | "move_balances": {}, |
332 | "run_orders": {}, | 346 | "run_orders": {}, |