Implement closing positions and refuse to post rejected trades

This commit is contained in:
2022-12-01 20:36:58 +00:00
parent 5c2eeae043
commit 66a18a6406
3 changed files with 34 additions and 2 deletions

View File

@@ -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