Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| developers:chart [2025/03/14 02:48] – created chad | developers:chart [2026/06/24 14:59] (current) – juan | ||
|---|---|---|---|
| Line 5: | Line 5: | ||
| < | < | ||
| All times are in CST. | All times are in CST. | ||
| + | </ | ||
| + | |||
| + | The complete API documentation is available via Swagger UI at: | ||
| + | |||
| + | [[https:// | ||
| + | |||
| + | The Swagger documentation provides: | ||
| + | * Complete list of available endpoints | ||
| + | * Request parameters and response formats | ||
| + | * Interactive testing capability | ||
| + | * Authentication requirements | ||
| + | |||
| + | < | ||
| + | **What changed in this revision** \\ | ||
| + | This page documents the **open-source decoder libraries** that consume the chart API's compact binary response: | ||
| + | * A top-level section **[[# | ||
| + | |||
| + | See **[[# | ||
| </ | </ | ||
| Line 21: | Line 39: | ||
| ^ Header | ^ Header | ||
| | Authorization | | Authorization | ||
| - | | Accept | ||
| **Examples: | **Examples: | ||
| Line 27: | Line 44: | ||
| * To authorize the request, include the bearer token: | * To authorize the request, include the bearer token: | ||
| < | < | ||
| - | |||
| - | * To receive the response in a compact binary format, set the `Accept` header accordingly: | ||
| - | < | ||
| - | or | ||
| - | < | ||
| - | |||
| - | Setting the `Accept` header is optional, and if it is not included, the API will return the response in a JSON format. | ||
| ==== Parameters ==== | ==== Parameters ==== | ||
| Line 171: | Line 181: | ||
| } | } | ||
| </ | </ | ||
| - | |||
| - | |||
| - | |||
| - | |||
| ===== Non-Aggregated Chart Data (Trade History) ===== | ===== Non-Aggregated Chart Data (Trade History) ===== | ||
| Line 187: | Line 193: | ||
| ^ Header | ^ Header | ||
| | Authorization | Bearer < | | Authorization | Bearer < | ||
| - | | Accept | ||
| ==== Parameters ==== | ==== Parameters ==== | ||
| Line 233: | Line 238: | ||
| | time | The specific time when the VWAP is calculated. | | time | The specific time when the VWAP is calculated. | ||
| | vwapPrice | | vwapPrice | ||
| - | |||
| ==== Example JSON Response ==== | ==== Example JSON Response ==== | ||
| Line 270: | Line 274: | ||
| } | } | ||
| </ | </ | ||
| + | |||
| + | The response is structured as a JSON object with various elements containing detailed trade data and related information for the specified contract and exchange within the requested time frame. | ||
| + | |||
| + | ===== Decoder Libraries ===== | ||
| + | |||
| + | Open-source reference decoders are maintained alongside this API so you do not have to implement the binary format by hand. The libraries are line-for-line ports of the original Java ``com.t4login`` chart-data reader and are validated against each other and against the CSV/JSON output. | ||
| + | |||
| + | All of the tools below live in the public **CTS-Futures/ | ||
| + | |||
| + | [[https:// | ||
| + | |||
| + | ^ Language | ||
| + | | JavaScript | ||
| + | | Python | ||
| + | | .NET (C#) | ``T4APIDemo`` (NuGet) | ||
| + | |||
| + | ==== JavaScript: @t4/ | ||
| + | |||
| + | Requires **Node 18+** (uses global ``fetch``) or any modern browser. The only runtime dependency is **decimal.js**. | ||
| + | |||
| + | === Install === | ||
| + | Clone the [[https:// | ||
| + | |||
| + | <code powershell> | ||
| + | git clone https:// | ||
| + | cd t4-api-tools/ | ||
| + | npm install | ||
| + | </ | ||
| + | |||
| + | === Aggregated barchart (push / handler model) === | ||
| + | |||
| + | ``ChartDataStreamReaderAggr`` decodes the whole stream and dispatches each record to a handler. Any subset of callbacks may be supplied; missing callbacks are skipped. | ||
| + | |||
| + | <code javascript> | ||
| + | import { ChartClient } from ' | ||
| + | |||
| + | const client = new ChartClient({ token: ' | ||
| + | |||
| + | await client.getBarchartBinary({ | ||
| + | exchangeId: ' | ||
| + | contractId: ' | ||
| + | barInterval: | ||
| + | barPeriod: | ||
| + | tradeDateStart: | ||
| + | tradeDateEnd: | ||
| + | handler: { | ||
| + | onMarketDefinition(def) { /* def.MarketID, | ||
| + | onBar(bar) | ||
| + | onModeChange(marketId, | ||
| + | onSettlement(marketId, | ||
| + | onOpenInterest(marketId, | ||
| + | }, | ||
| + | }); | ||
| + | </ | ||
| + | |||
| + | The handler interface: | ||
| + | |||
| + | ^ Callback | ||
| + | | ``onMarketDefinition(marketDefinition)`` | ||
| + | | ``onBar(bar)`` | ||
| + | | ``onModeChange(marketId, | ||
| + | | ``onSettlement(marketId, | ||
| + | | ``onOpenInterest(marketId, | ||
| + | |||
| + | === Non-aggregated trade history (pull / state model) === | ||
| + | |||
| + | ``ChartDataStreamReader`` is a sequential cursor. Each ``read()`` consumes one record and mutates the public ``reader.state`` object; ``read()`` returns ``false`` at end-of-stream. Branch on ``state.Change``: | ||
| + | |||
| + | <code javascript> | ||
| + | import { ChartClient, | ||
| + | |||
| + | const reader = await client.getTradehistoryBinary({ | ||
| + | exchangeId: ' | ||
| + | contractId: ' | ||
| + | tradeDateStart: | ||
| + | tradeDateEnd: | ||
| + | }); | ||
| + | |||
| + | while (reader.read()) { | ||
| + | const s = reader.state; | ||
| + | switch (s.Change) { | ||
| + | case ChartDataChange.Trade: | ||
| + | console.log(s.LastTimeTicks, | ||
| + | break; | ||
| + | case ChartDataChange.Quote: | ||
| + | console.log(' | ||
| + | break; | ||
| + | case ChartDataChange.Settlement: | ||
| + | console.log(' | ||
| + | break; | ||
| + | // ... MarketMode, OpenInterest, | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | === Lower-level / advanced usage === | ||
| + | |||
| + | You can also decode bytes you already have (e.g. from a saved file) without the HTTP client: | ||
| + | |||
| + | <code javascript> | ||
| + | import { | ||
| + | ByteReader, NDateTime, ChartDataType, | ||
| + | ChartDataStreamReader, | ||
| + | extractT4BinPayload, | ||
| + | } from ' | ||
| + | |||
| + | // Aggregated: | ||
| + | ChartDataStreamReaderAggr.read(extractT4BinPayload(bytes), | ||
| + | |||
| + | // Non-aggregated: | ||
| + | const reader = new ChartDataStreamReader({ | ||
| + | data: new ByteReader(extractT4BinPayload(bytes)), | ||
| + | tradeDate: new NDateTime(0n), | ||
| + | marketId: ' | ||
| + | dataType: ChartDataType.get(0), | ||
| + | }); | ||
| + | </ | ||
| + | |||
| + | === Browser (no bundler) === | ||
| + | |||
| + | The JSDemo copy ships a ``decoder/ | ||
| + | |||
| + | <code html> | ||
| + | <script type=" | ||
| + | < | ||
| + | window.addEventListener(' | ||
| + | const { ChartDataStreamReaderAggr, | ||
| + | // ... | ||
| + | }); | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ==== Python: t4login ==== | ||
| + | |||
| + | The Python package mirrors the JavaScript API one-to-one (same class names, same field names). It is the original conversion the JavaScript port was derived from. | ||
| + | |||
| + | === Install === | ||
| + | Clone the [[https:// | ||
| + | |||
| + | <code powershell> | ||
| + | git clone https:// | ||
| + | cd t4-api-tools/ | ||
| + | pip install -e . # installs from pyproject.toml | ||
| + | </ | ||
| + | |||
| + | === Usage === | ||
| + | |||
| + | <code python> | ||
| + | from t4login.client.chart_client import ChartClient | ||
| + | from t4login.definitions.chartdata.chart_data_change import ChartDataChange | ||
| + | |||
| + | client = ChartClient(token=" | ||
| + | |||
| + | # Aggregated (handler model) | ||
| + | client.get_barchart_binary( | ||
| + | exchange_id=" | ||
| + | trade_date_start=" | ||
| + | handler=my_handler, | ||
| + | ) | ||
| + | |||
| + | # Non-aggregated (state model) | ||
| + | reader = client.get_tradehistory_binary( | ||
| + | exchange_id=" | ||
| + | trade_date_start=" | ||
| + | ) | ||
| + | while reader.read(): | ||
| + | s = reader.state | ||
| + | if s.Change == ChartDataChange.Trade: | ||
| + | print(s.LastTradePrice, | ||
| + | </ | ||
| + | |||
| + | ==== .NET: T4APIDemo ==== | ||
| + | |||
| + | The .NET reference decoder ships as the ``T4APIDemo`` NuGet package in the same repository, under ``tools/ | ||
| + | |||
| + | === Install === | ||
| + | Clone the [[https:// | ||
| + | |||
| + | <code powershell> | ||
| + | git clone https:// | ||
| + | cd t4-api-tools/ | ||
| + | dotnet restore | ||
| + | dotnet build | ||
| + | </ | ||
| + | |||
| + | ==== ChartDataState field reference (T4Bin) ==== | ||
| + | |||
| + | Populated by ``ChartDataStreamReader``. Field names are PascalCase for parity across Java/ | ||
| + | |||
| + | ^ Group ^ Fields | ||
| + | | Change | ||
| + | | Trade date | ``TradeDate``, | ||
| + | | Market def. | ``MarketDefined``, | ||
| + | | Last trade | ``LastTradePrice``, | ||
| + | | Bar | ``BarStartTime``, | ||
| + | | TPO | ``TPOStartTime``, | ||
| + | | Quote | ``BidPrice``, | ||
| + | | Session | ||
| + | | RFQ | ``RFQBuySell`` (**[[# | ||
| + | |||
| + | ==== Enumerations ==== | ||
| + | |||
| + | === ChartDataChange === | ||
| + | The ``state.Change`` discriminator after each ``read()``. | ||
| + | |||
| + | ^ Value ^ Name | ||
| + | | 0 | ``NONE`` | ||
| + | | 1 | ``Trade`` | ||
| + | | 2 | ``Quote`` | ||
| + | | 3 | ``MarketMode`` | ||
| + | | 4 | ``Settlement`` | ||
| + | | 5 | ``TradeBar`` | ||
| + | | 6 | ``TradeDate`` | ||
| + | | 7 | ``TPO`` | ||
| + | |||
| + | === MarketMode === | ||
| + | Exchange session lifecycle state (the ``marketMode`` field in JSON, and ``state.Mode`` / ``onModeChange`` in binary). | ||
| + | |||
| + | ^ Value ^ Name | ||
| + | | 0 | ``Undefined`` | ||
| + | | 1 | ``PreOpen`` | ||
| + | | 2 | ``Open`` | ||
| + | | 3 | ``RestrictedOpen`` | | 11 | ``Expired`` | ||
| + | | 4 | ``PreClosed`` | ||
| + | | 5 | ``Closed`` | ||
| + | | 6 | ``Suspended`` | ||
| + | | 7 | ``Halted`` | ||
| + | |||
| + | === BidOffer === | ||
| + | Which side of the market a trade/RFQ executed against (mirrors the JSON ``aggressorSide``). | ||
| + | |||
| + | ^ Value ^ Name ^ | ||
| + | | 1 | ``Bid`` | ||
| + | | 0 | ``Undefined`` | | ||
| + | | -1 | ``Offer`` | ||
| + | |||
| + | ===== Revision Notes / Changelog ===== | ||
| + | |||
| + | ^ Area ^ Change ^ | ||
| + | | New section | **Decoder Libraries** — JavaScript (``@t4/ | ||
| + | |||
| + | **Source of truth:** the field and enumeration tables above are generated from the decoder source under | ||
| + | ``tools/ | ||
| + | ``tools/ | ||
| + | |||
| The response is structured as a JSON object with various elements containing detailed trade data and related information for the specified contract and exchange within the requested time frame. | The response is structured as a JSON object with various elements containing detailed trade data and related information for the specified contract and exchange within the requested time frame. | ||