Last active
October 22, 2025 05:30
-
-
Save databento-bot/1155f822a404676f681c14d9acbabaf9 to your computer and use it in GitHub Desktop.
Retrieve CME FX Link order book data with Databento
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| # -*- coding: utf-8 -*- | |
| """ | |
| cme_fx_link.py | |
| ============== | |
| Retrieve CME FX Link order book (MBO) data using the Databento API. | |
| Databento API を使用して、CME FX Link のオーダーブック | |
| (マーケット・バイ・オーダー)データを取得します。 | |
| """ | |
| import databento as db | |
| # EN: Initialize Databento historical client | |
| # JP: Databento の履歴データクライアントを初期化 | |
| client = db.Historical() | |
| # EN: Get all instrument definitions for the given date range | |
| # JP: 指定した日付範囲の全銘柄定義を取得 | |
| symbols_dbn = client.timeseries.get_range( | |
| dataset="GLBX.MDP3", | |
| schema="definition", | |
| symbols="ALL_SYMBOLS", | |
| start="2025-04-09", | |
| end="2025-04-10", | |
| ) | |
| df = symbols_dbn.to_df() | |
| # EN: Filter for CME FX Link spreads (exchange code: XFXS) | |
| # Reference: https://cmegroupclientsite.atlassian.net/wiki/spaces/EPICSANDBOX/pages/457419638/CME+FX+Link+Spread | |
| # JP: CME FX Link の銘柄を抽出(取引所コード: XFXS) | |
| # 参考: https://cmegroupclientsite.atlassian.net/wiki/spaces/EPICSANDBOX/pages/457419638/CME+FX+Link+Spread | |
| fx_link_symbols = df.loc[df["exchange"] == "XFXS", "raw_symbol"].to_list() | |
| # EN: Retrieve order book (MBO) data for FX Link instruments | |
| # JP: FX Link 銘柄のマーケット・バイ・オーダーデータを取得 | |
| data = client.timeseries.get_range( | |
| dataset="GLBX.MDP3", | |
| schema="mbo", | |
| symbols=fx_link_symbols, | |
| start="2025-04-09", | |
| end="2025-04-10", | |
| ) | |
| # EN: Convert to pandas DataFrame with timezone awareness | |
| # JP: タイムゾーンを指定して pandas DataFrame に変換 | |
| df = data.to_df(tz="Asia/Tokyo") | |
| # EN: Display the resulting DataFrame | |
| # JP: 結果の DataFrame を表示 | |
| print(df) | |
| """ | |
| ts_event rtype publisher_id instrument_id action side price size channel_id order_id flags ts_in_delta sequence symbol | |
| ts_recv | |
| 2025-04-09 09:00:00+09:00 2025-04-09 08:23:29.672872609+09:00 160 1 42106754 R N NaN 0 4 0 40 0 0 6A:XF:AUDUSD:M5 | |
| 2025-04-09 09:00:00+09:00 2025-04-09 08:23:29.672872609+09:00 160 1 42106754 A B 0.00030 250 4 8819964586725 40 0 123811247 6A:XF:AUDUSD:M5 | |
| 2025-04-09 09:00:00+09:00 2025-04-09 08:23:30.329363903+09:00 160 1 42106754 A B 0.00031 250 4 8819964586806 40 0 123811403 6A:XF:AUDUSD:M5 | |
| 2025-04-09 09:00:00+09:00 2025-04-09 08:23:34.176864603+09:00 160 1 42106754 A B 0.00032 250 4 8819964587323 40 0 123812571 6A:XF:AUDUSD:M5 | |
| 2025-04-09 09:00:00+09:00 2025-04-09 08:23:34.176868059+09:00 160 1 42106754 A A 0.00042 250 4 8819964587324 40 0 123812572 6A:XF:AUDUSD:M5 | |
| ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... | |
| 2025-04-10 08:35:13.007033449+09:00 2025-04-10 08:35:13.006893433+09:00 160 1 42106754 A B 0.00041 250 4 8819991508226 130 17039 183200983 6A:XF:AUDUSD:M5 | |
| 2025-04-10 08:35:48.537911048+09:00 2025-04-10 08:35:48.537784825+09:00 160 1 42106754 C B 0.00038 35 4 8819991507673 130 16216 183208359 6A:XF:AUDUSD:M5 | |
| 2025-04-10 08:35:48.538052814+09:00 2025-04-10 08:35:48.537943773+09:00 160 1 42106754 A B 0.00039 35 4 8819991511945 130 15625 183208360 6A:XF:AUDUSD:M5 | |
| 2025-04-10 08:35:59.275346914+09:00 2025-04-10 08:35:59.275221601+09:00 160 1 42106754 A A 0.00045 35 4 8819991513014 130 16646 183210423 6A:XF:AUDUSD:M5 | |
| 2025-04-10 08:35:59.275356299+09:00 2025-04-10 08:35:59.275226843+09:00 160 1 42106754 C A 0.00048 35 4 8819991507679 130 11961 183210424 6A:XF:AUDUSD:M5 | |
| [156358 rows x 14 columns] | |
| """ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment