예제 #1
0
def add_coin():
    data = request.get_json()
    percent = 100
    if "symbol" in data and "user_id" in data:
        symbol = data["symbol"]
        user_id = data["user_id"]
    else:
        return jsonify(success=0, results={}, message="Некорректные данные")

    if "percent" in data:
        percent = data["percent"]

    coin = CoinController.from_db(symbol=symbol)
    user = UserController.from_db(user_id)
    if not user:
        return jsonify(success=0, results={}, message="Пользователь не найден")
    if not coin:
        return jsonify(success=0, results={}, message="Монета не найдена")

    wallet = user.add_coin(coin, percent)

    if wallet:
        return jsonify(success=1,
                       results=wallet.to_json(),
                       message="Кошелек получен")
    jsonify(success=0, results={}, message="Кошелек не найден")
예제 #2
0
def overall_balance():
    data = request.get_json()
    if "user_id" in data:
        user_id = data["user_id"]
    else:
        return jsonify(success=0, results={}, message="Отсутствует user_id")

    user = UserController.from_db(user_id)
    if not user:
        return jsonify(success=0, results={}, message="Пользователь не найден")

    balance = user.get_overall_balance()
    return jsonify(success=1, results={"balance": balance}, message="Успешно")
예제 #3
0
def get_user():
    data = request.get_json()
    user_id: int = data["user_id"]
    user = UserController.from_db(user_id)

    if not user:
        return jsonify(success=0, results={}, message="Пользователь не найден")

    user_data = {
        "name": user.name,
        "email": user.email,
        "balance": user.balance
    }
    return jsonify(success=1,
                   results=user_data,
                   message="Пользователь получен успешно")
예제 #4
0
def top_up():
    data = request.get_json()
    if "user_id" in data and "amount":
        user_id = data["user_id"]
        amount = data["amount"]
    else:
        return jsonify(success=0, results={}, message="Отсутствует user_id")

    user = UserController.from_db(user_id)
    if not user:
        return jsonify(success=0, results={}, message="Пользователь не найден")

    user.user.top_up(amount)
    return jsonify(success=1,
                   results={"balance": user.balance},
                   message="Успешно")
예제 #5
0
def get_trades():
    data = request.get_json()

    if "user_id" in data:
        user_id = data["user_id"]
    else:
        return jsonify(success=0, results={}, message="Отсутствует user_id")

    user = UserController.from_db(user_id)
    if not user:
        return jsonify(success=0, results={}, message="Пользователь не найден")

    results = list()
    for trade in user.trades:
        results.append(trade.to_json())

    return jsonify(success=1, results=results, message="Успешно")
예제 #6
0
def get_wallets():
    data = request.get_json()

    if "user_id" in data:
        user_id = data["user_id"]
    else:
        return jsonify(success=0, results={}, message="Некорректные данные")

    user = UserController.from_db(user_id)
    if not user:
        return jsonify(success=0, results={}, message="Пользователь не найден")
    wallets = user.wallets
    results = list()

    for wallet in wallets:
        results.append(wallet.to_json())

    return jsonify(success=1, results=results, message="Успешно")
예제 #7
0
def sell_coin():
    data = request.get_json()
    if "user_id" in data and "symbol" in data:
        user_id = data["user_id"]
        symbol = data["symbol"]
    else:
        return jsonify(success=0,
                       results={},
                       message="Отсутствует ключ 'user_id' или 'user_id'")

    coin = CoinController.from_db(symbol=symbol)
    user = UserController.from_db(user_id)
    if not user:
        return jsonify(success=0, results={}, message="Пользователь не найден")
    if not coin:
        return jsonify(success=0, results={}, message="Монета не найдена")

    wallet = user.get_wallet(coin)

    wallet.sell()

    return jsonify(success=1, results={}, message="Монета продана")
예제 #8
0
 def make_shell_context():
     from app.main.models import User, Coin, Wallet
     from app.controllers.wallet_controller import WalletController
     from app.controllers.coin_controller import CoinController
     from app.controllers.user_controller import UserController
     from app.controllers.model_controller import ModelController
     from app.controllers.binance_controller import BinanceController
     return {
         'db': db,
         'User': User,
         'Coin': Coin,
         "Wallet": Wallet,
         "WC": WalletController,
         "CC": CoinController,
         "UC": UserController,
         "MC": ModelController,
         "BC": BinanceController,
         "oleg": UserController.from_db(1),
         "btc": CoinController.from_db(symbol="BTCUSDT"),
         "eth": CoinController.from_db(symbol="ETHUSDT"),
         "xrp": CoinController.from_db(symbol="XRPUSDT")
     }
예제 #9
0
def get_profit():
    data = request.get_json()

    if "user_id" in data:
        user_id = data["user_id"]
    else:
        return jsonify(success=0,
                       results={},
                       message="Отсутствует ключ 'user_id' или 'user_id'")

    user = UserController.from_db(user_id)
    if not user:
        return jsonify(success=0, results={}, message="Пользователь не найден")

    if "symbol" in data:
        symbol = data["symbol"]
        coin = CoinController.from_db(symbol=symbol)
        wallet = user.get_wallet(coin)
        profit = wallet.get_profit()

    else:
        profit = user.get_profit()

    return jsonify(success=1, results={"profit": profit}, message=f"Профит")