Connect a market-data source and an LLM API so a research agent is not guessing
Agent series, part 3. A framework is only a shell. Data supplies the facts, and the model supplies the reading. The agent is useful once both pipes are connected.
This is part 3 of the Chinese series on deploying a research agent. The previous part, installing the agent with Docker, is the Docker deploy of TradingAgents-CN. That note is not this article.
Short answer: start with a China model that uses the OpenAI API format, keep the key in .env, prove AKShare by printing one daily bar for 600519, then check every number against a market app before you trust the write-up.
How to choose: A research agent needs two pipes. The data source is the library it can look up, because the model's own market knowledge is already stale. The LLM API is the brain. For a personal start, use a China model with an OpenAI-compatible API: DeepSeek, Zhipu GLM, Kimi, or Tongyi. The Chinese page says signup credit is included and that they cost about an order of magnitude less, and that they read Chinese financial text well. Use GPT or Claude when you need stronger reasoning or a long document and you can pay from overseas. Leave a local model on Ollama until you have a GPU. The 2 vCPU and 2 GB server named in this series cannot run one. Put every key in .env, never in code or a README, and set a balance alert or a spend cap in the vendor console. For data, start free. AKShare needs no key. Tushare gives points on signup, is more regular, and keeps some advanced endpoints behind a points threshold. A project such as TradingAgents-CN already has an A-share data option: fill the token in .env. Restart the service after any change. Then ask about one stock you already know. Check the close and the market cap against a market app, whether the write-up names a source, and whether asking twice still gives the same conclusion. This page is not the tool-order guide, not the site FAQ, not the Docker deploy note, and not the morning brief.
Who it is for: Someone who already has an open-source research agent running, usually in Docker, and still needs a model API and a market-data source so the reports use fresh numbers. What you need is which model to start with, where the key goes, a free data source that prints one daily bar, and three checks before you trust the write-up.
Who it is not for: Someone who still needs to install Docker and the agent, or who wants the morning brief scheduled. Docker deploy is the previous part, in English. The morning brief is the next part, in English. This page is also not the tool-order guide, not the site FAQ, not the Tushare versus AKShare fee comparison, and not the AKShare SQLite walkthrough. A local model on the 2 vCPU and 2 GB server is out of scope. A key does not belong in a public repository or a chat.
The same walkthrough in Chinese is connecting a market-data source and an LLM API. Storing China A-share bars in SQLite is AKShare into SQLite. Fees, the free tier, and why an AKShare interface can fail are how to choose between Tushare and AKShare. That comparison is not this article. The next part of the series, a morning brief on a schedule, is the morning brief. It is the same article as the Chinese note, and it is not this article.
Facts below follow the Chinese walkthrough. The commands were not re-run for this English page. The Chinese page does not publish a model price, and this page does not add one. Usage and prices follow each vendor's own site. This is not investment advice.
01 · The agent's two pipes
Think of the research agent as a new intern. The data source is the library they can actually look up. The market facts the model learned in training are already stale. The LLM API is the brain. If either pipe is wrong, the report is a straight-faced invention.
02 · The LLM API, in one list
- China models (DeepSeek, Zhipu GLM, Kimi, Tongyi). The Chinese page says signup credit is included, the price is about an order of magnitude lower, and Chinese financial text is a strength. The API follows the OpenAI format. This is the personal starting point.
- Overseas models (GPT, Claude). Stronger on complex reasoning and long documents. They need an overseas way to pay, and the unit price is higher. Use them when the budget allows, or for a final close reading.
- A local model (an open model on Ollama). No API bill, and the data does not leave the machine. Quality still trails the cloud flagships, and the 2 vCPU and 2 GB server in this series cannot run one. Wait until you have a GPU.
The signup is the same everywhere: register, create an API key in the console, copy it, and store it. The key is money. Do two things at once. Put it in .env, not in code and not in a README. In the console, set a balance alert or a spend cap.
03 · Market data: start free
# On the server, check that a data source answers. AKShare is the example.
pip3 install akshare -i https://pypi.tuna.tsinghua.edu.cn/simple
python3 -c "import akshare as ak; print(ak.stock_zh_a_hist(symbol='600519', period='daily', start_date='20250801', end_date='20250831').tail())"If that prints Kweichow Moutai daily bars for August 2025, the data pipe is open. How to choose the source:
- AKShare. Free, no key. It aggregates public interfaces, which is enough to start. An interface can change. The worked download into SQLite is AKShare into SQLite.
- Tushare. Signup includes points. The data is more regular, and the API is wider. Some advanced endpoints need a points threshold. It fits once you plan to keep using it. Which one to pay for, and what the free tier can call, is how to choose between Tushare and AKShare. That comparison is not this article.
- Whatever the project already ships. A project such as TradingAgents-CN already offers an A-share data option. Pick one in
.envand fill in the token. You do not write that client yourself.
04 · Give the agent both keys
# .env in the project directory. Names follow that project's README. These two are common.
DEEPSEEK_API_KEY=sk-xxxxxxxx # LLM key
TUSHARE_TOKEN=xxxxxxxxxxxxxxxx # data-source token
# Save, then restart. The new file is not read until you do.
docker compose restartThe rule: every secret lives only in .env. Nothing is hardcoded. A config change takes effect only after a restart. "I changed it and nothing happened" is, about half the time, a forgotten restart.
05 · Check it on a stock you know
Pick a name you have watched for a long time, with a recent event you can point at. Ask the agent for one analysis, then run three checks:
- Are the figures right? Compare the cited close and market cap with a market app. One miss and you do not read the rest.
- Is the source named? A good write-up says which filing or which dataset it used. A page of adjectives with no source is down-weighted.
- Does the conclusion hold still? Ask about the same name twice. If the conclusions are far apart, the temperature or the pipeline is wrong. That is not the market being unpredictable.
06 · Pitfalls
- A leaked key is someone else spending your balance. Do not commit it to a public repository, and do not paste it in a chat. If spend looks wrong, revoke the key and create a new one.
- Free data sources are rate-limited. Pause between calls in a loop. If you are blocked, back off. Retrying harder makes it worse.
- Invented figures. A language model will produce financial numbers that look real. The rule: every number must trace back to the data source. If it does not, do not believe it.
- A runaway bill. A multi-agent project can call the model dozens of times for one analysis. Get the path working on the cheaper model, then swap in an expensive one only for the step that needs it.
The pipes are connected. The last part of the series turns this into a morning brief:
Next: a pre-market brief on a schedule →
This is not investment advice. API usage and prices follow each vendor's own site.
Frequently asked questions
How to choose a model API and a market-data source for a research agent?
A research agent needs two pipes. The data source is the library it can look up, because the model's own market knowledge is already stale. The LLM API is the brain. For a personal start, use a China model with an OpenAI-compatible API: DeepSeek, Zhipu GLM, Kimi, or Tongyi. The Chinese page says signup credit is included and that they cost about an order of magnitude less, and that they read Chinese financial text well. Use GPT or Claude when you need stronger reasoning or a long document and you can pay from overseas. Leave a local model on Ollama until you have a GPU. The 2 vCPU and 2 GB server named in this series cannot run one. Put every key in .env, never in code or a README, and set a balance alert or a spend cap in the vendor console. For data, start free. AKShare needs no key. Tushare gives points on signup, is more regular, and keeps some advanced endpoints behind a points threshold. A project such as TradingAgents-CN already has an A-share data option: fill the token in .env. Restart the service after any change. Then ask about one stock you already know. Check the close and the market cap against a market app, whether the write-up names a source, and whether asking twice still gives the same conclusion. This page is not the tool-order guide, not the site FAQ, not the Docker deploy note, and not the morning brief.
Who it is for?
Someone who already has an open-source research agent running, usually in Docker, and still needs a model API and a market-data source so the reports use fresh numbers. What you need is which model to start with, where the key goes, a free data source that prints one daily bar, and three checks before you trust the write-up.
Who it is not for?
Someone who still needs to install Docker and the agent, or who wants the morning brief scheduled. Docker deploy is the previous part, in English. The morning brief is the next part, in English. This page is also not the tool-order guide, not the site FAQ, not the Tushare versus AKShare fee comparison, and not the AKShare SQLite walkthrough. A local model on the 2 vCPU and 2 GB server is out of scope. A key does not belong in a public repository or a chat.
Which LLM API should you start with?
Start with a China model that speaks the OpenAI API format: DeepSeek, Zhipu GLM, Kimi, or Tongyi. The Chinese page says they include signup credit, cost about an order of magnitude less, and read Chinese financial text well. GPT and Claude are stronger on complex reasoning and long documents, and they need an overseas payment method and a higher unit price. A local model through Ollama has no API bill and the data stays on your machine, but it trails the cloud flagships, and the 2 vCPU and 2 GB server in this series cannot run one. This page does not publish a dollar price. Usage and prices follow each vendor's own site.
How do you check that the data source works?
On the server, install AKShare from the Tsinghua PyPI mirror and print one history. The command on the Chinese page is: pip3 install akshare -i https://pypi.tuna.tsinghua.edu.cn/simple, then python3 -c with ak.stock_zh_a_hist for symbol 600519, period daily, start_date 20250801, end_date 20250831, and .tail(). If that prints Kweichow Moutai daily bars for August 2025, the data pipe is open. AKShare is free and needs no key. It aggregates public interfaces, and an interface can change. Tushare gives points on signup, is more regular, and has a richer API, with some advanced endpoints behind a points threshold. A project such as TradingAgents-CN already offers an A-share source: pick one and put the token in .env. Storing the bars in SQLite is a different article.
Where do the API keys go?
Only in the project .env. The Chinese page shows two common names, and says the real names follow that project's README: DEEPSEEK_API_KEY for the model, and TUSHARE_TOKEN for the data source. Nothing is hardcoded. After you save, docker compose restart. A change that seems to do nothing is often a service that was not restarted. The key is money. Set a balance alert or a spend cap in the console. Do not commit it, and do not paste it in a chat. If spend looks wrong, revoke the key and create a new one.
How do you tell the agent is inventing numbers?
Pick a stock you have watched, with a recent event you can name, and ask for one analysis. Then three checks. The close and the market cap must match a market app. One wrong figure and you stop reading. A useful write-up names the filing or the data it used. A page of adjectives with no source is down-weighted. Ask about the same stock twice. If the conclusions disagree, the temperature or the pipeline is wrong. That is not the market being random. The rule for numbers: if you cannot trace a figure back to the data source, do not believe it.
What pitfalls does this walkthrough call out?
Four. A leaked key is someone else spending your balance. Do not put it in a public repository or a group chat, and revoke it if spend looks wrong. Free data sources are rate-limited. Pause between calls in a loop, and if you are blocked, back off instead of retrying harder. A language model will invent financial figures that look real. Every number has to trace to the data source. A multi-agent project can call the model dozens of times for one analysis. Get the path working on the cheaper model before you swap in an expensive one for a single step. This is not investment advice. API usage and prices follow each vendor's own site.