"""Borrou Partner API: the Python snippets, run against the sandbox. v0.1 DRAFT. pip install requests export BORROU_BASE_URL=https://api.borrou.capital export BORROU_CLIENT_ID=bpc_test_... # your sandbox credential export BORROU_CLIENT_SECRET=... # from your secret store, never from a file you commit python3 quickstart.py Reads your products, a quote, the first page of your events and every one of your loans, and submits one application for a synthetic borrower: an idempotent POST, sent twice with the same key to show the replay. Writes run with a sandbox credential only. """ import os import sys import uuid from itertools import islice from borrou_client import BorrouApiError, BorrouClient def required(name: str) -> str: value = os.environ.get(name) if not value: sys.exit(f"Set {name}.") return value def main() -> None: client_id = required("BORROU_CLIENT_ID") client = BorrouClient(os.environ.get("BORROU_BASE_URL", "https://api.borrou.capital"), client_id, required("BORROU_CLIENT_SECRET")) products = client.get("/v1/products").body["data"] product = next((p for p in products if p["api_lendable"]), None) if product is None: sys.exit("No product can lend through the API yet: ask TFG to activate one.") limits = product["limits"] print(f"Product {product['code']}, {limits['min_principal_usdt']} to {limits['max_principal_usdt']} USDT") quote = client.get("/v1/quote", {"principal_usdt": "1000.00", "product": product["code"]}).body print(f"1000.00 USDT needs {quote['required_collateral_btc']} BTC at {quote['btc_price_usd']} USD (indicative)") if client_id.startswith("bpc_test_"): # One key for this request. A retry after a timeout sends the same key and gets the stored answer. key = str(uuid.uuid4()) application = { "principal_usdt": "1000.00", "external_reference": f"snippet-{key}", "borrower": {"full_name": "Snippet Borrower", "email": f"snippet-{key[:8]}@partner-sandbox.test", "country": "AR"}, } first = client.post("/v1/applications", application, idempotency_key=key) again = client.post("/v1/applications", application, idempotency_key=key) print(f"Application {first.body['id']} is {first.body['status']}; the retry replayed it: {again.replayed and again.body['id'] == first.body['id']}") for event in islice(client.paginate("/v1/events", {"limit": 50}, cursor_param="after"), 5): print(f"Event {event['id']} {event['type']}") loans = sum(1 for _ in client.paginate("/v1/loans", {"limit": 100})) print(f"{loans} loan(s) in all") if __name__ == "__main__": try: main() except BorrouApiError as err: sys.exit(f"{err} (request {err.request_id or 'unknown'})")