Stock API in Practice: Using MCP to Analyze Tech Stocks, Gold, and Forex

TickDB Research ·

Stock API in Practice: Using MCP to Analyze Tech Stocks, Gold, and Forex

Abstract: A stock API gives AI access to real-time U.S. stock market data and historical price bars. Combining those records with gold prices and forex quotes makes cross-market analysis possible. This walkthrough uses actual TickDB MCP requests to examine the October 22, 2026 technology stock selloff, calculate comparable returns, and separate price observations from explanations.

When technology stocks fall, do gold and the yen rise together? Answering that question requires data from several markets, a consistent observation window, and a clear definition of each return.

On October 21, 2026, Meta reported third-quarter results and narrowed its full-year capital expenditure guidance from $130–145 billion to $135–145 billion. It also disclosed a new arrangement involving Class C non-voting common stock. That disclosure should not be read as money already raised. Reuters’ market report the following day linked the technology selloff to concerns about AI spending and financing: Meta fell about 7%, while the Nasdaq Composite declined about 2.6%.

The yen strengthened against the dollar that day, but gold fell. The behavior of a single stock, or the assumption that rising risk lifts every perceived safe haven, cannot describe the whole session.

The following example turns that question into a series of inspectable requests and calculations.

Choose the instruments before drawing conclusions

A stock API returns structured records such as quotes and historical price bars. A cross-market comparison also needs instruments outside equities. This example uses:

  • META.US: Meta shares, quoted in dollars per share, to observe the company reporting results.
  • IXIC: the Nasdaq Composite, to compare the stock with a broader, technology-heavy equity index.
  • XAUUSD: spot gold, quoted in dollars per ounce, to check whether gold moved differently from equities.
  • USDJPY: dollars quoted in yen, to observe the yen’s movement against the dollar.

TickDB exposes these instruments through a common set of market data tools. The request and validation patterns can be reused across markets, while prices still need to be interpreted according to their instrument and quotation convention.

MCP makes those tools available to an AI client. The workflow is straightforward:

Define the question → Select instruments and parameters
→ Call the market data API through MCP → Validate the response
→ Calculate relative changes → Produce a chart and explanation

TickDB supplies market data; the AI client coordinates requests, calculations, and presentation.

Inspect an actual historical data request

TickDB MCP’s get_kline retrieves historical price bars. The following is the actual Meta request used for this example, shown as a tool name and arguments rather than the complete MCP protocol envelope:

{
  "tool": "get_kline",
  "arguments": {
    "symbol": "META.US",
    "type": "stock",
    "interval": "5m",
    "adjust": "none",
    "start_time": 1792675800000,
    "end_time": 1792698900000,
    "limit": 1000
  }
}

interval selects five-minute bars, and adjust: none requests unadjusted stock prices. The millisecond timestamps specify bar start times from October 22 at 13:30 UTC through 19:55 UTC. The last bar ends at 20:00 UTC, or 4:00 p.m. U.S. Eastern time.

The successful response has business code 0, with records under data.klines. This excerpt shows the first bar’s price fields:

{
  "code": 0,
  "data": {
    "symbol": "META.US",
    "interval": "5m",
    "klines": [
      {
        "time": 1792675800000,
        "open": "676.35000000",
        "high": "681.07000000",
        "low": "657.40000000",
        "close": "657.41000000"
      }
    ]
  }
}

Prices arrive as strings and must be converted explicitly for calculation. Check the business code, required fields, and nonempty series first. An error or missing record is not a zero price.

The other three instruments were queried for the same interval and range. IXIC uses type: indices; XAUUSD and USDJPY use type: forex. In this example, adjust applies only to the stock request.

Compare returns rather than price levels

A share price, an index level, and an exchange rate have different units. Their raw levels do not make a meaningful comparison. Instead, calculate each instrument’s percentage change from the start of the selected window:

Change (%) = (current price / starting price − 1) × 100

The window covers the October 22 U.S. regular trading session, 13:30–20:00 UTC. Each response contains 78 five-minute bars. Using the first bar’s opening price and the last bar’s closing price gives:

  • META.US: 676.35 → 648.87, a 4.06% decline.
  • IXIC: 26,308.407 → 26,008.859, a 1.14% decline.
  • XAUUSD: 4,076.61 → 4,027.93, a 1.19% decline.
  • USDJPY: 157.234 → 156.862, a 0.24% decline in the currency pair.

These are returns within the chosen session window. Meta’s approximately 7% drop and the Nasdaq’s approximately 2.6% drop in the news report are previous-close-to-close returns. They also include the price adjustment that had already occurred before the regular session opened.

Relative performance of Meta, the Nasdaq Composite, gold, and the yen against the dollar during the October 22, 2026 U.S. regular session

Chart: Actual five-minute data, with each series measured from its first opening price to subsequent completed bars’ closing prices. No interpolation is used. The yen series is calculated from 1/USDJPY to show the yen’s direction against the dollar directly.

The following Python reproduces the endpoint returns using only the standard library:

from decimal import Decimal

def change_pct(first, last, inverse=False):
    first, last = Decimal(first), Decimal(last)
    if not (first.is_finite() and last.is_finite()):
        raise ValueError("Prices must be finite numbers")
    if first <= 0 or last <= 0:
        raise ValueError("Prices must be positive")
    ratio = first / last if inverse else last / first
    return (ratio - 1) * 100

prices = {
    "META.US": ("676.35", "648.87"),
    "IXIC": ("26308.407", "26008.859"),
    "XAUUSD": ("4076.61", "4027.93"),
    "USDJPY": ("157.234", "156.862"),
}

for symbol, pair in prices.items():
    print(f"{symbol}: {change_pct(*pair):+.2f}%")

print(f"JPY vs. USD: {change_pct(*prices['USDJPY'], inverse=True):+.2f}%")

Output:

META.US: -4.06%
IXIC: -1.14%
XAUUSD: -1.19%
USDJPY: -0.24%
JPY vs. USD: +0.24%

What the comparison establishes

Three observations follow from these records.

Meta fell more than the Nasdaq during the selected session. Querying both the stock and the index shows whether their directions match and how their magnitudes differ. It does not isolate how much of the decline came from company news, sector conditions, or other factors.

Gold and the yen diverged. Gold fell approximately 1.19%, while the yen gained approximately 0.24% against the dollar. A falling USDJPY means fewer yen are required to buy one dollar. The inverse calculation makes that direction explicit; other currency pairs require the same attention to quotation order.

Intraday losses and daily losses answer different questions. One describes the move after the opening price; the other measures the move from the previous close. Preserving the prices and baseline keeps the AI’s explanation tied to a reproducible calculation.

Reuters also reported a move into U.S. Treasuries and a substantial decline in the 10-year yield. Oil faced a separate event involving Middle East supply risks. These observations provide context, but the four price series alone cannot establish why every asset moved or prove a single causal chain.

Continue from historical bars to a quote update

Historical bars describe a selected period. TickDB MCP’s get_ticker can retrieve a subsequent quote snapshot. The following multi-instrument request was also executed:

{
  "tool": "get_ticker",
  "arguments": {
    "symbols": "META.US,IXIC,XAUUSD,USDJPY"
  }
}

The response includes these regular-session fields for Meta:

{
  "symbol": "META.US",
  "last_price": "648.85",
  "prev_close": "697.52",
  "price_change_percent_24h": "-6.98",
  "timestamp": 1792699200000
}

The reported −6.98% corresponds to the approximately 7% daily decline. Its timestamp is October 22 at 20:00 UTC. When queried on October 23, the next U.S. regular session had not started, so these fields still described the previous session. The response separately included overnight quotes, which need to be read with their corresponding fields and timestamps.

The ticker’s 648.85 also differs slightly from the final five-minute bar’s 648.87; all session returns above consistently use the historical bars.

An AI client connected through MCP can continue with a follow-up such as:

Check the latest quotes for those instruments. How have they changed since the end of that window?

This is a suggested follow-up, rather than a transcript of an additional executed conversation. The client can reuse the instrument list, retrieve fresh records, and compare them with the stored endpoints while checking when each quote was recorded.

The TickDB MCP server is open source. Its repository contains tool definitions, connection instructions, and deployment files, allowing developers to inspect how queries map to the market data API or deploy the server themselves. Access to market data remains subject to the permissions of the API key in use.

Market data provided by TickDB.ai. Source code and setup instructions: TickDB MCP on GitHub.

Related articles

Forex WebSocket API in Python: Is EURUSD Still Updating?

For Python developers building a forex quote monitor, this guide uses TickDB to subscribe to EURUSD and save each quote with its data timestamp and local receipt time. A bounded script writes raw messages, a quote CSV and a run summary. Quote counts, receipt gaps and changes in data timestamps help distinguish an open connection from continuing quote updates. The recorded 30-second observation received 38 EURUSD messages. The same code lets you inspect a new sample in your own environment.

TickDB Research ·

Integrate a Stock API in Python: Fetch Quotes, Validate Responses, Preserve Timestamps

How do you turn a stock API response into a usable quote display? Keep the key on the server, validate the response, match records by symbol, and show the price with its quote time. A live TickDB request for AAPL.US and MSFT.US returned both symbols successfully, but its top-level quote timestamps were older than its pre-market timestamps. The runnable Python example below makes that distinction visible and handles missing or malformed records.

TickDB Research ·

Integrating a Forex Real-Time Market Data API: How to Avoid Displaying Stale Quotes After a WebSocket Reconnection

After integrating real-time market data into a forex dashboard, exchange-rate monitor, or price alert, when should the page resume showing that it is “updating normally” once the connection is restored? This article is aimed at developers responsible for these features. Using TickDB’s actual EUR/USD subscription as an example, it walks through the full process of connecting, subscribing, deliberately disconnecting, and reconnecting, and explains how quote timestamps, heartbeats, and page status work together to keep teams from being misled by stale data. Product managers and technical colleagues can use the recovery sequence and acceptance checklist in the article to jointly review the page behavior.

TickDB Research ·

Forex Tick Data API: Live Quotes, Historical Downloads, and Access Costs

For quant teams choosing an FX data supplier, a working live feed answers only part of the purchasing question. Research may need historical bid and ask updates, while a dashboard may need current quotes and charts. This guide explains how to distinguish quotes, trades, and bars, check historical access, and compare costs against a specific job. It includes a dated EUR/USD quote sample, three actual TickDB historical queries, and a supplier questionnaire you can copy into an enquiry.

TickDB Research ·

Forex WebSocket API Tutorial: Stream EUR/USD and Check Quotes After Reconnecting

For developers building an FX dashboard or price alert, a reopened connection is only part of recovery. The application also needs a valid quote for the right currency pair, a usable data timestamp, and a visible record of the interruption. This tutorial uses a real TickDB EURUSD stream to show the first subscription, a controlled disconnect, resubscription, and quote checks. The download includes the bounded Node.js runner, original messages, event logs, and an offline checker.

TickDB Research ·