{
  "nbformat": 4,
  "nbformat_minor": 5,
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Try the SiftingIO Python SDK in Google Colab\n",
        "Download this notebook, then choose **File \u2192 Upload notebook** at https://colab.research.google.com/ and **Runtime \u2192 Run all**. Everything runs in the hosted notebook, with no local setup.\n",
        "\n",
        "The default mock demo runs the real SDK against clearly synthetic responses. No API key is required. To make one live request, set `LIVE = True` and enter your key in the hidden prompt. Live mode sends the key only to the official SiftingIO API through the SDK; your key stays out of notebook output. Review Google's handling of your hosted session before using credentials.\n"
      ],
      "id": "sdk-demo-0"
    },
    {
      "cell_type": "code",
      "metadata": {},
      "execution_count": null,
      "outputs": [],
      "source": [
        "%pip -q install siftingio==0.2.0"
      ],
      "id": "sdk-demo-1"
    },
    {
      "cell_type": "code",
      "metadata": {},
      "execution_count": null,
      "outputs": [],
      "source": [
        "from getpass import getpass\n",
        "from datetime import datetime, timezone\n",
        "import httpx\n",
        "from siftingio import SiftingClient\n",
        "\n",
        "LIVE = False\n",
        "SYMBOL = \"BTCUSD\"\n"
      ],
      "id": "sdk-demo-2"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## One SDK call, two ways to try it\n",
        "The mocked response below is synthetic. Live mode makes one current-price request; it uses your plan's access and allowance. Symbol coverage: https://sifting.io/symbols\n"
      ],
      "id": "sdk-demo-3"
    },
    {
      "cell_type": "code",
      "metadata": {},
      "execution_count": null,
      "outputs": [],
      "source": [
        "if LIVE:\n",
        "    api_key = getpass(\"SiftingIO API key (hidden): \")\n",
        "    with SiftingClient(api_key=api_key, max_retries=0) as client:\n",
        "        snapshot = client.last.trade(\"crypto\", SYMBOL)\n",
        "    del api_key\n",
        "    label = \"Live SiftingIO response\"\n",
        "else:\n",
        "    def demo_response(request):\n",
        "        return httpx.Response(200, json={\"s\": SYMBOL, \"p\": 100.0, \"t\": 1790812800000})\n",
        "    with httpx.Client(transport=httpx.MockTransport(demo_response)) as http_client:\n",
        "        with SiftingClient(api_key=\"synthetic-demo-key\", http_client=http_client) as client:\n",
        "            snapshot = client.last.trade(\"crypto\", SYMBOL)\n",
        "    label = \"Synthetic response through the real SDK\"\n",
        "print(label)\n",
        "print(\"Symbol:\", SYMBOL)\n",
        "print(\"Price:\", snapshot[\"p\"])\n",
        "print(\"Value time (UTC):\", datetime.fromtimestamp(snapshot[\"t\"] / 1000, tz=timezone.utc).isoformat())\n"
      ],
      "id": "sdk-demo-4"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Next steps\n",
        "Follow the Python SDK guide at https://sifting.io/sdks/python or explore all clients at https://sifting.io/sdks. Create an API key in https://sifting.io/dashboard. Keep keys out of shared notebook cells and clear your runtime after live testing.\n",
        "\n",
        "For analysis of a downloaded historical CSV without credentials, use the separate OHLCV analysis notebook on https://sifting.io/resources.\n"
      ],
      "id": "sdk-demo-5"
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "name": "python"
    },
    "colab": {
      "provenance": []
    }
  }
}
