Implement closing positions and refuse to post rejected trades
This commit is contained in:
@@ -201,6 +201,7 @@ class Trade(models.Model):
|
||||
trailing_stop_loss = models.FloatField(null=True, blank=True)
|
||||
take_profit = models.FloatField(null=True, blank=True)
|
||||
status = models.CharField(max_length=255, null=True, blank=True)
|
||||
information = models.JSONField(null=True, blank=True)
|
||||
direction = models.CharField(choices=DIRECTION_CHOICES, max_length=255)
|
||||
|
||||
# To populate from the trade
|
||||
@@ -213,7 +214,11 @@ class Trade(models.Model):
|
||||
self._original = self
|
||||
|
||||
def post(self):
|
||||
return self.account.client.post_trade(self)
|
||||
if self.status in ["rejected", "close"]:
|
||||
log.debug(f"Trade {self.id} rejected. Not posting.")
|
||||
log.debug(f"Trade {self.id} information: {self.information}")
|
||||
else:
|
||||
return self.account.client.post_trade(self)
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
# close the trade
|
||||
|
||||
Reference in New Issue
Block a user