]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Trader.git/blobdiff - portfolio.py
Add first steps for margin trading
[perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Trader.git] / portfolio.py
index 1fe56b5992222f8eafddae8479ae0fdbb9f1b987..3257bcff8b2d91301ef08f5dc0efe309516f8f0a 100644 (file)
@@ -467,12 +467,13 @@ class Trade:
             print("\t", order, sep="")
 
 class Order:
-    def __init__(self, action, amount, rate, base_currency, market):
+    def __init__(self, action, amount, rate, base_currency, market, account="exchange"):
         self.action = action
         self.amount = amount
         self.rate = rate
         self.base_currency = base_currency
         self.market = market
+        self.account = account
         self.result = None
         self.status = "pending"
 
@@ -498,16 +499,16 @@ class Order:
         amount = self.amount.value
 
         if debug:
-            print("market.create_order('{}', 'limit', '{}', {}, price={})".format(
-                symbol, self.action, amount, self.rate))
+            print("market.create_order('{}', 'limit', '{}', {}, price={}, account={})".format(
+                symbol, self.action, amount, self.rate, self.account))
         else:
             try:
-                self.result = self.market.create_order(symbol, 'limit', self.action, amount, price=self.rate)
+                self.result = self.market.create_order(symbol, 'limit', self.action, amount, price=self.rate, account=self.account)
                 self.status = "open"
             except Exception as e:
                 self.status = "error"
-                print("error when running market.create_order('{}', 'limit', '{}', {}, price={})".format(
-                    symbol, self.action, amount, self.rate))
+                print("error when running market.create_order('{}', 'limit', '{}', {}, price={}, account={})".format(
+                    symbol, self.action, amount, self.rate, self.account))
                 self.error_message = str("{}: {}".format(e.__class__.__name__, e))
                 print(self.error_message)