Load BloFin data to DuckDB
Build a BloFin to DuckDB pipeline with your coding agent. One prompt scaffolds it with the dltHub AI harness, plus the BloFin API base URL, auth, endpoints, and incremental loading.
BloFin is a cryptocurrency trading platform providing REST and WebSocket APIs for market data, trading operations, and account management. Everything needed to build a working BloFin → DuckDB pipeline is on this page: the API's base URL, authentication, endpoints, pagination and incremental field — plus a prompt that hands the whole job to your coding agent.
Build your BloFin to DuckDB pipeline
Paste this prompt into Claude, Codex, or Cursor. The agent does the rest.
PromptRunuvx dlthub-init@latestto build a pipeline from BloFin to DuckDB and run it on dltHub
That scaffolds a dltHub workspace and installs the dltHub AI harness — the project rules, the secrets-management skill, and the dlt MCP server your agent needs to work safely. From there it reads the BloFin API, proposes the endpoints to load, then writes, runs and validates the pipeline while you review rather than type. Credentials are inspected through MCP tools, so your agent never reads secrets.toml itself. How the LLM-native workflow works →
Prefer to write it yourself? Every fact the agent uses is below.
BloFin API at a glance
| Base URL | https://openapi.blofin.com |
| Example endpoint | GET api/v1/market/instruments |
| Records found at | data |
| Authentication | Authenticated requests require an HMAC-SHA256 signature passed in request headers |
| Also required | ACCESS-KEY, ACCESS-SIGN, ACCESS-TIMESTAMP, ACCESS-NONCE, ACCESS-PASSPHRASE |
| Pagination | Cursor-based via after, before, page size via limit. The pagination cursors 'after' and 'before' represent timestamps (ms) or trade IDs depending on the endpoint. 'after' returns records earlier than the specified value, while 'before' returns records newer than the specified value. Pagination is not uniform across all endpoints; some use 'limit' values of 100 while others allow up to 1440. |
| Incremental field | after |
| API reference | https://docs.blofin.com/index.html |
These values come from the BloFin API reference — the authoritative source if anything here looks out of date.
How do I authenticate with the BloFin API?
All authenticated requests require specific headers: ACCESS-KEY, ACCESS-SIGN (Base64-encoded HMAC-SHA256 signature), ACCESS-TIMESTAMP (Unix milliseconds), ACCESS-NONCE (unique identifier), and ACCESS-PASSPHRASE. The signature is generated by signing a string composed of the request path, method, timestamp, nonce, and request body.
1. Get your credentials
To obtain API credentials for BloFin, follow these steps:
- Log in to your account at the official BloFin website.
- Navigate to the API Management section (typically found via your profile menu).
- Click '+ Create API Key'.
- Provide a descriptive name for the key.
- Configure permissions according to your needs (e.g., 'Trade', 'Read'). For security, avoid enabling 'Withdraw' access unless absolutely necessary.
- Set a strong, unique passphrase. This is mandatory for signing requests and will be required for your application.
- If applicable to your integration, select 'Connect to Third-Party Applications' and choose the relevant partner from the list, or configure IP whitelisting manually if the option is available and required for your setup.
- Complete the security verification (e.g., 2FA, email/SMS code).
- Copy the API Key and Secret Key immediately upon display. The Secret Key is shown only once; store these credentials, along with your passphrase, in a secure location (e.g., a vault or password manager).
2. Add them to .dlt/secrets.toml
[sources.blofin_source] api_key = "your_api_key_here" api_secret = "your_secret_key_here" api_passphrase = "your_passphrase_here"
dlt reads this file automatically at runtime. With the harness, the setup-secrets skill prompts you for the values and never handles the raw credential in chat. For production, see setting up credentials with dlt.
What BloFin data can I load into DuckDB?
These are the BloFin endpoints dlt can load into DuckDB:
| Resource | Endpoint | Method | Data selector | Description |
|---|---|---|---|---|
| instruments | /api/v1/market/instruments | GET | data | List of all tradable instruments |
| tickers | /api/v1/market/tickers | GET | data | Latest market ticker information |
| order_book | /api/v1/market/books | GET | data | Order book depth for an instrument |
| trades | /api/v1/market/trades | GET | data | Recent trade history |
| candlesticks | /api/v1/market/candles | GET | data | OHLCV candlestick data |
| balances | /api/v1/asset/balances | GET | data | Account balance information |
| open_orders | /api/v1/trade/orders/active | GET | data | List of currently active orders |
How do I load only new BloFin records?
BloFin exposes after on api/v1/market/instruments, so dlt can request only the records that changed since the last run. Set it as the cursor_path and dlt tracks the high-water mark for you between runs.
{"name": "instruments", "endpoint": { "path": "api/v1/market/instruments", "data_selector": "data", "incremental": {"cursor_path": "after", "initial_value": "2024-01-01T00:00:00Z"}, }}
On the first run dlt loads everything from initial_value; on every run after that it requests only what changed and appends with write_disposition="merge" if you set a primary key. See incremental loading.
What does the generated BloFin pipeline look like?
A standard dlt REST API pipeline — the same code you would write by hand, loading api/v1/market/instruments and api/v1/asset/balances from the BloFin API into DuckDB:
import dlt from dlt.sources.rest_api import RESTAPIConfig, rest_api_resources @dlt.source def blofin_source(api_key_api_secret_passphrase=dlt.secrets.value): config: RESTAPIConfig = { "client": { "base_url": "https://openapi.blofin.com", "auth": {"type": "api_key", "api_key": api_key_api_secret_passphrase}, }, "resources": [ {"name": "instruments", "endpoint": {"path": "api/v1/market/instruments", "data_selector": "data"}}, {"name": "tickers", "endpoint": {"path": "api/v1/market/tickers", "data_selector": "data"}} ], } yield from rest_api_resources(config) def load_blofin_to_duckdb() -> None: pipeline = dlt.pipeline( pipeline_name="blofin_pipeline", destination="duckdb", dataset_name="blofin_data", ) load_info = pipeline.run(blofin_source()) print(load_info) if __name__ == "__main__": load_blofin_to_duckdb()
Run it with python blofin_pipeline.py. The agent iterates on this until it loads cleanly — you review and approve, rather than write it from scratch.
How do I query BloFin data in DuckDB?
dlt creates one table per resource. Query the loaded data with Python or SQL — or ask your agent to, through the MCP server's execute_sql_query tool.
Python (pandas DataFrame):
import dlt data = dlt.pipeline("blofin_pipeline").dataset() df = data.instruments.df() print(df.head())
SQL:
SELECT * FROM blofin_data.instruments LIMIT 10;
See querying your data with dataset and exploring it in marimo notebooks.
How do I deploy the BloFin to DuckDB pipeline in production?
The pipeline runs locally, which is ideal for prototyping and one-off analysis. When you need it on a schedule, monitored on every load, and shared with your team, deploy the same dlt code on the dltHub platform — no infrastructure to maintain. The prompt above already ends with "run it on dltHub", so your agent can take it there directly.
- Deploy & schedule — run the pipeline as a managed job with automatic retries.
- Monitor — observable job queues, alerting, and load metrics for every run.
- Transform — promote raw BloFin loads into governed, documented models.
- Visualize & share — explore data in notebooks and publish live dashboards instead of static screenshots.
What other destinations can I load BloFin data to?
dlt loads into any of these — only the destination argument changes:
| Destination | Example value |
|---|---|
| PostgreSQL | "postgres" |
| BigQuery | "bigquery" |
| Snowflake | "snowflake" |
| Redshift | "redshift" |
| Databricks | "databricks" |
| Filesystem (S3, GCS, Azure) | "filesystem" |
Set dlt.pipeline(destination="snowflake") and add credentials in .dlt/secrets.toml. On the dltHub platform the same pipeline runs against a managed Iceberg lakehouse. See the full destinations list.
Next steps
Was this page helpful?
Community Hub
Need more dlt context for BloFin to DuckDB?
Request dlt skills, commands, AGENT.md files, and AI-native context.