diff --git a/core/exchanges/mexc.py b/core/exchanges/mexc.py index b04ad17..a07cee8 100644 --- a/core/exchanges/mexc.py +++ b/core/exchanges/mexc.py @@ -1,33 +1,46 @@ +from pymexc import futures, spot + from core.exchanges import BaseExchange, common from core.util import logs -from pymexc import spot, futures - log = logs.get_logger("mexc") class MEXCExchange(BaseExchange): - def call_method(self, request): - ... + # def call_method(self, request): + # ... def connect(self): self.client = spot.HTTP( - api_key=self.account.api_key, - api_secret=self.account.api_key - ) + api_key=self.account.api_key, api_secret=self.account.api_secret + ) def get_account(self): - r = self.client.account_information() + # r = self.client.account_information() + r = self.call("account_information") + # {'makerCommission': None, 'takerCommission': None, + # 'buyerCommission': None, 'sellerCommission': None, + # 'canTrade': True, 'canWithdraw': True, 'canDeposit': True, + # 'updateTime': None, 'accountType': 'SPOT', 'balances': [], + # 'permissions': ['SPOT']} print("ACC INFO", r) + return r def get_instruments(self): - ... + r = self.call("exchange_info") + # {'timezone': 'CST', 'serverTime': 1732007199224, 'rateLimits': [], 'exchangeFilters': [], 'symbols': [{'symbol': 'TRUMP1USDT', 'status': '1', 'baseAsset': 'TRUMP1', 'baseAssetPrecision': 0, 'quoteAsset': 'USDT', 'quotePrecision': 15, 'quoteAssetPrecision': 15, 'baseCommissionPrecision': 0, 'quoteCommissionPrecision': 15, 'orderTypes': ['LIMIT', 'MARKET', 'LIMIT_MAKER'], 'isSpotTradingAllowed': True, 'isMarginTradingAllowed': False, 'quoteAmountPrecision': '1.000000000000000000000000000000', 'baseSizePrecision': '0', 'permissions': ['SPOT'], 'filters': [], 'maxQuoteAmount': '2000000.000000000000000000000000000000', 'makerCommission': '0', 'takerCommission': '0.0002', 'quoteAmountPrecisionMarket': '1.000000000000000000000000000000', 'maxQuoteAmountMarket': '100000.000000000000000000000000000000', 'fullName': 'SIMPSONTRUMP', 'tradeSideType': 1}, {'symbol': 'AESUSDT', 'status': '1', 'baseAsset': 'AES', 'baseAssetPrecision': 2, 'quoteAsset': 'USDT', 'quotePrecision': 7, 'quoteAssetPrecision': 7, 'baseCommissionPrecision': 2, 'quoteCommissionPrecision': 7, 'orderTypes': ['LIMIT', 'MARKET', 'LIMIT_MAKER'], 'isSpotTradingAllowed': True, 'isMarginTradingAllowed': False, 'quoteAmountPrecision': '1.000000000000000000000000000000', 'baseSizePrecision': '0', 'permissions': ['SPOT'], 'filters': [], 'maxQuoteAmount': '2000000.000000000000000000000000000000', 'makerCommission': '0', 'takerCommission': '0.0002', 'quoteAmountPrecisionMarket': '1.000000000000000000000000000000', 'maxQuoteAmountMarket': '100000.000000000000000000000000000000', 'fullName': 'Aree Shards', 'tradeSideType': 1}, {'symbol': 'NCDTUSDT', 'status': '1', 'baseAsset': 'NCDT', 'baseAssetPrecision': 2, 'quoteAsset': 'USDT', 'quotePrecision': 4, 'quoteAssetPrecision': 4, 'baseCommissionPrecision': 2, 'quoteCommissionPrecision': 4, 'orderTypes': ['LIMIT', 'MARKET', 'LIMIT_MAKER'], 'isSpotTradingAllowed': True, 'isMarginTradingAllowed': False, 'quoteAmountPrecision': '1.000000000000000000000000000000', 'baseSizePrecision': '0', 'permissions': ['SPOT'], 'filters': [], 'maxQuoteAmount': '2000000.000000000000000000000000000000', 'makerCommission': '0', 'takerCommission': '0.0002', 'quoteAmountPrecisionMarket': '1.000000000000000000000000000000', 'maxQuoteAmountMarket': '100000.000000000000000000000000000000', 'fullName': 'nuco.cloud', 'tradeSideType': 1}, {'symbol': 'ALEPHUSDT', 'status': '1', 'baseAsset': 'ALEPH', 'baseAssetPrecision': 2, 'quoteAsset': 'USDT', 'quotePrecision': 5, 'quoteAssetPrecision': 5, 'baseCommissionPrecision': 2, 'quoteCommissionPrecision': 5, 'orderTypes': ['LIMIT', 'MARKET', 'LIMIT_MAKER'], 'isSpotTradingAllowed': True, 'isMarginTradingAllowed': False, 'quoteAmountPrecision': '1.000000000000000000000000000000', 'baseSizePrecision': '5', 'permissions': ['SPOT'], 'filters': [], 'maxQuoteAmount': '2000000.000000000000000000000000000000', 'makerCommission': '0', 'takerCommission': '0.0002', 'quoteAmountPrecisionMarket': '1.000000000000000000000000000000', 'maxQuoteAmountMarket': '100000.000000000000000000000000000000', 'fullName': 'Alephim', 'tradeSideType': 1}, {'symbol': 'ORNJUSDT', 'status': '1', 'baseAsset': 'ORNJ', 'baseAssetPrecision': 2, 'quoteAsset': 'USDT', 'quotePrecision': 5, 'quoteAssetPrecision': 5, 'baseCommissionPrecision': 2, 'quoteCommissionPrecision': 5, 'orderTypes': ['LIMIT', 'MARKET', 'LIMIT_MAKER'], 'isSpotTradingAllowed': False, 'isMarginTradingAllowed': False, 'quoteAmountPrecision': '1.000000000000000000000000000000', 'baseSizePrecision': '0', 'permissions': ['SPOT'], 'filters': [], 'maxQuoteAmount': '2000000.000000000000000000000000000000', 'makerCommission': '0', 'takerCommission': '0.0002', 'quoteAmountPrecisionMarket': '1.000000000000000000000000000000', 'maxQuoteAmountMarket': '100000.000000000000000000000000000000', 'fullName': 'Orange', 'tradeSideType': 1}, {'symbol': 'OGNUSDT', 'status': '1', 'baseAsset': 'OGN', 'baseAssetPrecision': 2, 'quoteAsset': 'USDT', 'quotePrecision': 5, 'quoteAssetPrecision': 5, 'baseCommissionPrecision': 2, 'quoteCommissionPrecision': 5, 'orderTypes': ['LIMIT', 'MARKET', 'LIMIT_MAKER'], 'isSpotTradingAllowed': True, 'isMarginTradingAllowed': False, 'quoteAmountPrecision': '1.000000000000000000000000000000', 'baseSizePrecision': '0.01', 'permissions': ['SPOT'], 'filters': [], 'maxQuoteAmount': '2000000.000000000000000000000000000000', 'makerCommission': '0', 'takerCommission': '0.0002', 'quoteAmountPrecisionMarket': '1.000000000000000000000000000000', 'maxQuoteAmountMarket': '100000.000000000000000000000000000000', 'fullName': 'Origin', 'tradeSideType': 1}, {'symbol': 'HCUSDT', 'status': '1', 'baseAsset': 'HC', 'baseAssetPrecision': 2, 'quoteAsset': 'USDT', 'quotePrecision': 5, 'quoteAssetPrecision': 5, 'baseCommissionPrecision': 2, 'quoteCommissionPrecision': 5, 'orderTypes': ['LIMIT', 'MARKET', 'LIMIT_MAKER'], 'isSpotTradingAllowed': True, 'isMarginTradingAllowed': False, 'quoteAmountPrecision': '1.000000000000000000000000000000', 'baseSizePrecision': '0.001', 'permissions': ['SPOT'], 'filters': [], 'maxQuoteAmount': '2000000.000000000000000000000000000000', 'makerCommission': '0', 'takerCommission': '0.0002', 'quoteAmountPrecisionMarket': '1.000000000000000000000000000000', 'maxQuoteAmountMarket': '100000.000000000000000000000000000000', 'fullName': 'Hshare', 'tradeSideType': 1}, + return r def get_currencies(self, currencies): ... def get_supported_assets(self, response=None): - ... + if not response: + response = self.get_instruments() + symbols = response["symbols"] + supported_assets = [x["symbol"] for x in symbols] + return supported_assets + def get_balance(self, return_usd=False): ... diff --git a/core/lib/schemas/__init__.py b/core/lib/schemas/__init__.py index 1cbcc04..c504119 100644 --- a/core/lib/schemas/__init__.py +++ b/core/lib/schemas/__init__.py @@ -1 +1 @@ -from core.lib.schemas import alpaca_s, drakdoo_s, oanda_s # noqa +from core.lib.schemas import alpaca_s, drakdoo_s, oanda_s, mexc_s # noqa diff --git a/core/lib/schemas/mexc_s.py b/core/lib/schemas/mexc_s.py new file mode 100644 index 0000000..9ad3b84 --- /dev/null +++ b/core/lib/schemas/mexc_s.py @@ -0,0 +1 @@ +from pydantic import BaseModel, Field diff --git a/core/models.py b/core/models.py index cc483de..75e8991 100644 --- a/core/models.py +++ b/core/models.py @@ -176,11 +176,13 @@ class Account(models.Model): if client: response = client.get_instruments() supported_symbols = client.get_supported_assets(response) - currency = client.get_account()["currency"] + acct_info = client.get_account() log.debug(f"Supported symbols for {self.name}: {supported_symbols}") self.supported_symbols = supported_symbols self.instruments = response - self.currency = currency + if "currency" in acct_info.keys(): + currency = acct_info["currency"] + self.currency = currency if save: self.save() diff --git a/core/templates/base.html b/core/templates/base.html index de9009a..c2de2af 100644 --- a/core/templates/base.html +++ b/core/templates/base.html @@ -311,7 +311,10 @@ {% endif %} {% if user.is_authenticated %} - Logout +
+ {% csrf_token %} + +
{% endif %} diff --git a/core/views/accounts.py b/core/views/accounts.py index aac7bf1..d3546a7 100644 --- a/core/views/accounts.py +++ b/core/views/accounts.py @@ -30,7 +30,7 @@ class AccountInfo(LoginRequiredMixin, OTPRequiredMixin, ObjectRead): "sandbox", "supported_symbols", "initial_balance", - "instruments", + #"instruments", ] def get_object(self, **kwargs):