Fix Redis, begin implementing MEXC
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import os
|
||||
|
||||
import stripe
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
69
core/exchanges/mexc.py
Normal file
69
core/exchanges/mexc.py
Normal file
@@ -0,0 +1,69 @@
|
||||
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 connect(self):
|
||||
self.client = spot.HTTP(
|
||||
api_key=self.account.api_key,
|
||||
api_secret=self.account.api_key
|
||||
)
|
||||
|
||||
def get_account(self):
|
||||
r = self.client.account_information()
|
||||
print("ACC INFO", r)
|
||||
|
||||
def get_instruments(self):
|
||||
...
|
||||
|
||||
def get_currencies(self, currencies):
|
||||
...
|
||||
|
||||
def get_supported_assets(self, response=None):
|
||||
...
|
||||
|
||||
def get_balance(self, return_usd=False):
|
||||
...
|
||||
|
||||
def get_market_value(self, symbol):
|
||||
raise NotImplementedError
|
||||
|
||||
def post_trade(self, trade):
|
||||
...
|
||||
|
||||
def get_trade_precision(self, symbol):
|
||||
...
|
||||
|
||||
def close_trade(self, trade_id, units=None, symbol=None):
|
||||
...
|
||||
|
||||
def get_trade(self, trade_id):
|
||||
...
|
||||
|
||||
def update_trade(self, trade_id, take_profit_price, stop_loss_price):
|
||||
...
|
||||
|
||||
def cancel_trade(self, trade_id):
|
||||
...
|
||||
|
||||
def get_position_info(self, symbol):
|
||||
...
|
||||
|
||||
def get_all_positions(self):
|
||||
...
|
||||
|
||||
def get_all_open_trades(self):
|
||||
...
|
||||
|
||||
def close_position(self, side, symbol):
|
||||
...
|
||||
|
||||
def close_all_positions(self):
|
||||
...
|
||||
@@ -23,15 +23,16 @@ def initialise_elasticsearch():
|
||||
|
||||
|
||||
def store_msg(index, msg):
|
||||
global client
|
||||
if not client:
|
||||
client = initialise_elasticsearch()
|
||||
if "ts" not in msg:
|
||||
msg["ts"] = datetime.utcnow().isoformat()
|
||||
try:
|
||||
result = client.index(index=index, body=msg)
|
||||
except ConnectionError as e:
|
||||
log.error(f"Error indexing '{msg}': {e}")
|
||||
return
|
||||
if not result["result"] == "created":
|
||||
log.error(f"Indexing of '{msg}' failed: {result}")
|
||||
return
|
||||
# global client
|
||||
# if not client:
|
||||
# client = initialise_elasticsearch()
|
||||
# if "ts" not in msg:
|
||||
# msg["ts"] = datetime.utcnow().isoformat()
|
||||
# try:
|
||||
# result = client.index(index=index, body=msg)
|
||||
# except ConnectionError as e:
|
||||
# log.error(f"Error indexing '{msg}': {e}")
|
||||
# return
|
||||
# if not result["result"] == "created":
|
||||
# log.error(f"Indexing of '{msg}' failed: {result}")
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
from decimal import Decimal as D
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel
|
||||
from typing import Optional
|
||||
|
||||
|
||||
class PositionLong(BaseModel):
|
||||
units: str
|
||||
@@ -373,7 +374,9 @@ class Instrument(BaseModel):
|
||||
guaranteedStopLossOrderMode: str
|
||||
tags: list[InstrumentTag]
|
||||
financing: InstrumentFinancing
|
||||
guaranteedStopLossOrderLevelRestriction: Optional[InstrumentGuaranteedRestriction] = None
|
||||
guaranteedStopLossOrderLevelRestriction: Optional[
|
||||
InstrumentGuaranteedRestriction
|
||||
] = None
|
||||
|
||||
|
||||
class AccountInstruments(BaseModel):
|
||||
|
||||
@@ -8,6 +8,7 @@ from django.db import models
|
||||
|
||||
from core.exchanges.alpaca import AlpacaExchange
|
||||
from core.exchanges.fake import FakeExchange
|
||||
from core.exchanges.mexc import MEXCExchange
|
||||
from core.exchanges.oanda import OANDAExchange
|
||||
|
||||
# from core.lib.customers import get_or_create, update_customer_fields
|
||||
@@ -15,7 +16,12 @@ from core.lib import billing
|
||||
from core.util import logs
|
||||
|
||||
log = logs.get_logger(__name__)
|
||||
EXCHANGE_MAP = {"alpaca": AlpacaExchange, "oanda": OANDAExchange, "fake": FakeExchange}
|
||||
EXCHANGE_MAP = {
|
||||
"alpaca": AlpacaExchange,
|
||||
"oanda": OANDAExchange,
|
||||
"mexc": MEXCExchange,
|
||||
"fake": FakeExchange,
|
||||
}
|
||||
TYPE_CHOICES = (
|
||||
("market", "Market"),
|
||||
("limit", "Limit"),
|
||||
@@ -141,7 +147,12 @@ class User(AbstractUser):
|
||||
|
||||
|
||||
class Account(models.Model):
|
||||
EXCHANGE_CHOICES = (("alpaca", "Alpaca"), ("oanda", "OANDA"), ("fake", "Fake"))
|
||||
EXCHANGE_CHOICES = (
|
||||
("alpaca", "Alpaca"),
|
||||
("oanda", "OANDA"),
|
||||
("mexc", "MEXC"),
|
||||
("fake", "Fake"),
|
||||
)
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
name = models.CharField(max_length=255)
|
||||
exchange = models.CharField(choices=EXCHANGE_CHOICES, max_length=255)
|
||||
|
||||
Reference in New Issue
Block a user