A lightweight and fast MT5 module that keeps a local SQLite mirror of the models.dev LLM registry.
Fetches the full catalog (orgs + models: cost, context windows, modalities, flags) via WebRequest, persists it to a shared SQLite database, and notifies subscribed charts on every update.

--- ## Main Features - **Self-updating registry**: on init, downloads `https://models.dev/api.json` and upserts every org/model into a local SQLite database (`llm_orgs`, `llm_models`) - **Scheduled refresh**: configurable update interval (`InpHorasUpdate`), re-syncs automatically via `OnTimer` - **Retry with backoff**: failed fetches/writes are retried up to `InpMaxIntentos` times, waiting `InpSegundosTry` seconds between attempts, before falling back to the next full cycle - **Shared or local storage**: files can live in the MT5 common folder (`InpFilesInCommonFolder`) so multiple charts/EAs share one database - **Cross-chart notifications**: on a successful sync, emits `EventChartCustom` (`LLMREG_ON_UPDATE`) to every chart registered in the `charts_id` table - **Compact model schema**: cost (in/out), release/update dates, context window/input/output, and bitflags for `tools`, `temperature`, `reasoning`, `open_weights`, `structured_output`, plus input/output modalities (`text`, `audio`, `video`, `image`, `pdf`) ### Registry service (drop-in EA/module) ```mql5 input string InpFolderNameBase = "LLmRegistery\\"; input bool InpFilesInCommonFolder = true; input int InpHorasUpdate = 8; input int InpMaxIntentos = 5; input int InpSegundosTry = 100; input int InpTimeoutWebReqeuestMs = 60000; input ENUM_VERBOSE_LOG_LEVEL InpLogLevel = VERBOSE_LOG_LEVEL_ALL; TSN::CLlmRegistery g_llm_registery; int OnInit() { g_llm_registery.AddLogFlags(InpLogLevel); if(!g_llm_registery.Init(InpFolderNameBase, InpFilesInCommonFolder, InpHorasUpdate, InpMaxIntentos, InpSegundosTry, InpTimeoutWebReqeuestMs)) return INIT_FAILED; return(INIT_SUCCEEDED); } void OnTimer() { g_llm_registery.OnTimerEvent(); } ``` ### Subscribing to updates from another chart ```mql5 #include int g_sql_handle = INVALID_HANDLE; const long g_my = ChartID(); int OnInit() { g_sql_handle = DatabaseOpen(InpEaServerFoderName + LLMREG_FILENAME_SQL, DATABASE_OPEN_READWRITE | (InpEaFilesInCommonFolder ? DATABASE_OPEN_COMMON : 0)); DatabaseExecute(g_sql_handle, StringFormat("INSERT OR IGNORE INTO charts_id (chart_id) VALUES(%I64d)", g_my)); return(INIT_SUCCEEDED); } void OnChartEvent(const int32_t id, const long &lparam, const double &dparam, const string &sparam) { if(id == CHARTEVENT_CUSTOM + LLMREG_ON_UPDATE) Print("Base de datos de modelos ha sido actulizada"); } void OnDeinit(const int reason) { DatabaseExecute(g_sql_handle, StringFormat("DELETE FROM charts_id WHERE chart_id = %I64d;", g_my)); DatabaseClose(g_sql_handle); } ``` ### Querying the registry (SQL) ```sql SELECT m.name, m.cost_in, m.cost_out, m.context_window FROM llm_models m JOIN llm_orgs o ON o.id = m.org_id WHERE o.id = 'anthropic' ORDER BY m.last_update_date DESC; ``` --- ## Schema ``` llm_orgs ├── id (PK) ├── name ├── doc └── updated_at llm_models ├── id, org_id (PK, FK -> llm_orgs.id) ├── name, description ├── cost_in, cost_out ├── release_date, last_update_date ├── flags (tools | temperature | open_weights | reasoning | structured_output) ├── in_modals / out_modals (text | audio | video | image | pdf) ├── context_window / context_output / context_input └── updated_at charts_id └── chart_id (PK) -- charts subscribed to update notifications ``` Full definition in [Src/Init.sql](Src/Init.sql). --- ## Repository Structure ``` LLmRegiteryByLeo/ ├── Src/ │ ├── Main.mqh # CLlmRegistery: fetch, parse, upsert, notify, retry logic │ ├── Def.mqh # Structs, flags, modal defines, index constants │ ├── Init.sql # SQLite schema (orgs, models, charts_id) │ └── EnumReg/ # Modal string -> flag enum registry ├── Test/ │ └── TestHooks.mq5 # Minimal subscriber example (chart hook) └── RegisteryService.mq5 # Main EA/module entry point ``` --- ## License **[Read Full License](./LICENSE)** By downloading or using this repository, you accept the license terms. --- ## Requirements See [dependencies.json](./dependencies.json) for the full list. - MetaTrader 5, build 5430+ - WebRequest access enabled for `https://models.dev` (Tools → Options → Expert Advisors) --- ## Installation ```bash cd "C:\Users\YOUR_USER\AppData\Roaming\MetaQuotes\Terminal\YOUR_ID\MQL5\Shared Projects" tsndep install "https://forge.mql5.io/nique_372/LLmRegiteryByLeo.git" ``` Requires the `tsndep` package, available on [PyPI](https://pypi.org/project/tsndep). It automatically downloads and installs all declared dependencies. --- ## Quick Start **1. Add the URL to WebRequest allowed list:** ``` https://models.dev ``` **2. Attach `RegisteryService.mq5` to a chart** (once, as a background service). It creates/updates `LLmRegistery.db` and `Registery.json` in the shared folder. **3. From any other EA, open the shared database and query it directly**, or subscribe to `LLMREG_ON_UPDATE` via `OnChartEvent` as shown in [Subscribing to updates](#subscribing-to-updates-from-another-chart). --- ## Contact - **Platform:** [MQL5 Community](https://www.mql5.com/es/users/nique_372) - **Profile:** https://www.mql5.com/es/users/nique_372 - **Articles:** https://www.mql5.com/es/users/nique_372/publications