aboutsummaryrefslogtreecommitdiff
path: root/portfolio.py
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2018-01-26 00:10:03 +0100
committerIsmaël Bouya <ismael.bouya@normalesup.org>2018-01-26 00:13:23 +0100
commitecba11139e357567c46f7ba2a0cf8dbd98266fe8 (patch)
treed75d352988833038c3243f1e3e961434ded1bdc6 /portfolio.py
parent66c8b3dd07f4e45be2242d06f8f357adefeb2a4c (diff)
downloadTrader-ecba11139e357567c46f7ba2a0cf8dbd98266fe8.tar.gz
Trader-ecba11139e357567c46f7ba2a0cf8dbd98266fe8.tar.zst
Trader-ecba11139e357567c46f7ba2a0cf8dbd98266fe8.zip
Add first steps for margin trading
Diffstat (limited to 'portfolio.py')
-rw-r--r--portfolio.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/portfolio.py b/portfolio.py
index 1fe56b5..3257bcf 100644
--- a/portfolio.py
+++ b/portfolio.py
@@ -467,12 +467,13 @@ class Trade:
467 print("\t", order, sep="") 467 print("\t", order, sep="")
468 468
469class Order: 469class Order:
470 def __init__(self, action, amount, rate, base_currency, market): 470 def __init__(self, action, amount, rate, base_currency, market, account="exchange"):
471 self.action = action 471 self.action = action
472 self.amount = amount 472 self.amount = amount
473 self.rate = rate 473 self.rate = rate
474 self.base_currency = base_currency 474 self.base_currency = base_currency
475 self.market = market 475 self.market = market
476 self.account = account
476 self.result = None 477 self.result = None
477 self.status = "pending" 478 self.status = "pending"
478 479
@@ -498,16 +499,16 @@ class Order:
498 amount = self.amount.value 499 amount = self.amount.value
499 500
500 if debug: 501 if debug:
501 print("market.create_order('{}', 'limit', '{}', {}, price={})".format( 502 print("market.create_order('{}', 'limit', '{}', {}, price={}, account={})".format(
502 symbol, self.action, amount, self.rate)) 503 symbol, self.action, amount, self.rate, self.account))
503 else: 504 else:
504 try: 505 try:
505 self.result = self.market.create_order(symbol, 'limit', self.action, amount, price=self.rate) 506 self.result = self.market.create_order(symbol, 'limit', self.action, amount, price=self.rate, account=self.account)
506 self.status = "open" 507 self.status = "open"
507 except Exception as e: 508 except Exception as e:
508 self.status = "error" 509 self.status = "error"
509 print("error when running market.create_order('{}', 'limit', '{}', {}, price={})".format( 510 print("error when running market.create_order('{}', 'limit', '{}', {}, price={}, account={})".format(
510 symbol, self.action, amount, self.rate)) 511 symbol, self.action, amount, self.rate, self.account))
511 self.error_message = str("{}: {}".format(e.__class__.__name__, e)) 512 self.error_message = str("{}: {}".format(e.__class__.__name__, e))
512 print(self.error_message) 513 print(self.error_message)
513 514