From 22aa55e3d61f09e654fa4b23022a193315a9e4e0 Mon Sep 17 00:00:00 2001 From: Shroominic Date: Sat, 2 Aug 2025 22:10:55 -0300 Subject: [PATCH] option to set provider fees --- .env.example | 2 ++ router/payment/price.py | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.env.example b/.env.example index 0137f01e..44782248 100644 --- a/.env.example +++ b/.env.example @@ -4,6 +4,7 @@ DESCRIPTION = "A short Description" # Any openai-compatible api endpoint UPSTREAM_BASE_URL="https://api.openai.com/v1" UPSTREAM_API_KEY="sk-21212121212121212121212121212121" +# UPSTREAM_PROVIDER_FEE=1 # 1 = no fees, 1.05 = 5% fees # Lightning address used to receive funds RECEIVE_LN_ADDRESS="shroominic@walletofsatoshi.com" @@ -20,6 +21,7 @@ MODEL_BASED_PRICING = "true" # COST_PER_REQUEST="10" # COST_PER_1K_INPUT_TOKENS = "0" # COST_PER_1K_OUTPUT_TOKENS = "0" +# EXCHANGE_FEE = "1.005" # 0.5 % currency exchange fee # password used to log into admin interface ADMIN_PASSWORD="CHANGE-THIS" diff --git a/router/payment/price.py b/router/payment/price.py index 588c8094..4f0f4c88 100644 --- a/router/payment/price.py +++ b/router/payment/price.py @@ -9,8 +9,9 @@ logger = get_logger(__name__) # artifical spread to cover conversion fees EXCHANGE_FEE = float(os.environ.get("EXCHANGE_FEE", "1.005")) # 0.5% default - -logger.info("Price module initialized", extra={"exchange_fee": EXCHANGE_FEE}) +UPSTREAM_PROVIDER_FEE = float( + os.environ.get("UPSTREAM_PROVIDER_FEE", "1.05") +) # 5% default (e.g. openrouter charges 5% margin) async def kraken_btc_usd(client: httpx.AsyncClient) -> float | None: @@ -98,7 +99,7 @@ async def btc_usd_ask_price() -> float: raise ValueError("Unable to fetch BTC price from any exchange") max_price = max(valid_prices) - final_price = max_price * EXCHANGE_FEE + final_price = max_price * EXCHANGE_FEE * UPSTREAM_PROVIDER_FEE return final_price