Improve posting trades to OANDA and make everything more robust

This commit is contained in:
2022-11-10 19:27:46 +00:00
parent bf863f43b2
commit af9f874209
11 changed files with 267 additions and 30 deletions

View File

@@ -77,6 +77,8 @@ class Account(models.Model):
api_secret = models.CharField(max_length=255)
sandbox = models.BooleanField(default=False)
supported_symbols = models.JSONField(default=list)
instruments = models.JSONField(default=list)
currency = models.CharField(max_length=255, null=True, blank=True)
def __str__(self):
name = f"{self.name} ({self.exchange})"
@@ -90,9 +92,13 @@ class Account(models.Model):
"""
client = self.get_client()
if client:
supported_symbols = client.get_supported_assets()
response = client.get_instruments()
supported_symbols = client.get_supported_assets(response)
currency = client.get_account()["currency"]
log.debug(f"Supported symbols for {self.name}: {supported_symbols}")
self.supported_symbols = supported_symbols
self.instruments = response
self.currency = currency
super().save(*args, **kwargs)
def get_client(self):