def trade_info(trade_id_param: UUID) -> Union[str, Response]: lp = create_liquidity_provider() 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)
def get_debt() -> Union[str, Response]: lp = create_liquidity_provider() 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})
def test_dd_liquidity_provider_factory_for_premainnet(patch_liquidity, monkeypatch) -> None: monkeypatch.setenv("CHAIN_ID", str(chain_ids.PREMAINNET.value)) monkeypatch.setenv("CUSTODY_PRIVATE_KEYS", CUSTODY_PRIVATE_KEYS) init_liquidity_provider() lp = create_liquidity_provider() assert isinstance(lp, DDLiquidityProvider)
def test_dd_liquidity_provider_factory_for_testnet_with_custody_private_keys( patch_liquidity, monkeypatch) -> None: monkeypatch.setenv("CHAIN_ID", str(chain_ids.TESTNET.value)) monkeypatch.setenv("CUSTODY_PRIVATE_KEYS", CUSTODY_PRIVATE_KEYS) init_liquidity_provider() lp = create_liquidity_provider() assert isinstance(lp, DDLiquidityProvider)
def settle(debt_id_param: UUID) -> Union[str, Response, Tuple[str, int]]: settlement_confirmation = request.get_json()["settlement_confirmation"] lp = create_liquidity_provider() 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"
def get_quote() -> Union[str, Response]: lp = create_liquidity_provider() 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)
def trade_and_execute() -> Union[str, Response]: lp = create_liquidity_provider() 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)})
def lp_details() -> Union[str, Response]: current_app.logger.info("/details start") lp = create_liquidity_provider() json = lp.lp_details().to_json() current_app.logger.info(f"/details response: {json}") return json_response(json)