示例#1
0
def get_debt() -> Union[str, Response]:
    lp = LiquidityProvider()
    debts = lp.get_debt()
    serializable_debts = [debt.to_dict() for debt in debts]

    current_app.logger.info(f"Debt info {serializable_debts}")
    return jsonify({"debts": serializable_debts})
示例#2
0
def trade_info(trade_id_param: UUID) -> Union[str, Response]:
    lp = LiquidityProvider()
    trade_id = TradeId(trade_id_param)
    trade_data = lp.trade_info(trade_id=trade_id)
    json = trade_data.to_json()
    current_app.logger.info(f"Trade info {json}")
    return json_response(json)
示例#3
0
def init() -> Flask:
    print("starting init liquidity")
    # make sure to run the LP init only once, even when in debug mode
    with app.app_context():
        app.logger.info("init lp")
        LiquidityProvider.init_lp(app_logger=app.logger)
    return app
示例#4
0
def settle(debt_id_param: UUID) -> Union[str, Response, Tuple[str, int]]:
    settlement_confirmation = request.get_json()["settlement_confirmation"]

    lp = LiquidityProvider()
    try:
        lp.settle(DebtId(debt_id_param), settlement_confirmation)
    except KeyError as e:
        return str(e), 404
    except AlreadySettled as e:
        return str(e), 409

    return "OK"
示例#5
0
def get_quote() -> Union[str, Response]:
    lp = LiquidityProvider()
    data = request.get_json()

    current_app.logger.info(f"request for quote {data}")
    base_currency = Currency[data["base_currency"]]
    quote_currency = Currency[data["quote_currency"]]
    pair = CurrencyPair(base=base_currency, quote=quote_currency)
    quote = lp.get_quote(pair=pair, amount=int(data["amount"]))
    json = quote.to_json()
    current_app.logger.info(f"quote {json}")
    return json_response(json)
示例#6
0
def trade_and_execute() -> Union[str, Response]:
    lp = LiquidityProvider()
    data = request.get_json()
    quote_id = QuoteId(UUID(data["quote_id"]))
    direction = Direction[data["direction"]]
    diem_deposit_address = (
        data["diem_deposit_address"] if "diem_deposit_address" in data else None
    )
    tx_version = int(data["tx_version"]) if "tx_version" in data else None

    trade_id = lp.trade_and_execute(
        quote_id=quote_id,
        direction=direction,
        diem_bech32_deposit_address=diem_deposit_address,
        tx_version=tx_version,
    )
    return jsonify({"trade_id": str(trade_id)})
示例#7
0
def lp_details() -> Union[str, Response]:
    current_app.logger.info(f"/details start")
    lp = LiquidityProvider()
    json = lp.lp_details().to_json()
    current_app.logger.info(f"/details response: {json}")
    return json_response(json)