diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-01-22 01:06:39 +0100 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-01-22 01:06:39 +0100 |
commit | 272b3cfb11aea4160f0e40588e18dea44c6b028a (patch) | |
tree | 40464d1e2068b6560f1cecbe9908db719574272e | |
parent | b83d489771c1c4f482a711cffc572f23a1599b4d (diff) | |
download | Trader-272b3cfb11aea4160f0e40588e18dea44c6b028a.tar.gz Trader-272b3cfb11aea4160f0e40588e18dea44c6b028a.tar.zst Trader-272b3cfb11aea4160f0e40588e18dea44c6b028a.zip |
Add method to print orders
-rw-r--r-- | portfolio.py | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/portfolio.py b/portfolio.py index 00beab0..1041df1 100644 --- a/portfolio.py +++ b/portfolio.py | |||
@@ -407,6 +407,11 @@ class Trade: | |||
407 | if verbose: | 407 | if verbose: |
408 | print("All orders finished") | 408 | print("All orders finished") |
409 | 409 | ||
410 | @classmethod | ||
411 | def update_all_orders_status(cls): | ||
412 | for order in cls.all_orders(state="open"): | ||
413 | order.get_status() | ||
414 | |||
410 | def __repr__(self): | 415 | def __repr__(self): |
411 | return "Trade({} -> {} in {}, {})".format( | 416 | return "Trade({} -> {} in {}, {})".format( |
412 | self.value_from, | 417 | self.value_from, |
@@ -414,8 +419,17 @@ class Trade: | |||
414 | self.currency, | 419 | self.currency, |
415 | self.action) | 420 | self.action) |
416 | 421 | ||
417 | class Order: | 422 | @classmethod |
423 | def print_all_with_order(cls): | ||
424 | for trade in cls.trades.values(): | ||
425 | trade.print_with_order() | ||
426 | |||
427 | def print_with_order(self): | ||
428 | print(self) | ||
429 | for order in self.orders: | ||
430 | print("\t", order, sep="") | ||
418 | 431 | ||
432 | class Order: | ||
419 | def __init__(self, action, amount, rate, base_currency, market): | 433 | def __init__(self, action, amount, rate, base_currency, market): |
420 | self.action = action | 434 | self.action = action |
421 | self.amount = amount | 435 | self.amount = amount |
@@ -463,15 +477,15 @@ class Order: | |||
463 | self.status = result["status"] | 477 | self.status = result["status"] |
464 | return self.status | 478 | return self.status |
465 | 479 | ||
480 | def cancel(self): | ||
481 | self.market.cancel_order(self.result['id']) | ||
482 | |||
466 | def print_orders(market, base_currency="BTC"): | 483 | def print_orders(market, base_currency="BTC"): |
467 | Balance.prepare_trades(market, base_currency=base_currency, compute_value="average") | 484 | Balance.prepare_trades(market, base_currency=base_currency, compute_value="average") |
468 | Trade.prepare_orders(compute_value="average") | 485 | Trade.prepare_orders(compute_value="average") |
469 | for currency, balance in Balance.known_balances.items(): | 486 | for currency, balance in Balance.known_balances.items(): |
470 | print(balance) | 487 | print(balance) |
471 | for currency, trade in Trade.trades.items(): | 488 | portfolio.Trade.print_all_with_order() |
472 | print(trade) | ||
473 | for order in trade.orders: | ||
474 | print("\t", order, sep="") | ||
475 | 489 | ||
476 | def make_orders(market, base_currency="BTC"): | 490 | def make_orders(market, base_currency="BTC"): |
477 | Balance.prepare_trades(market, base_currency=base_currency) | 491 | Balance.prepare_trades(market, base_currency=base_currency) |