Protobuf Inspector - Interactive Type ExplorerΒΆ
Interactive developer utility for exploring MT5 protobuf types, fields, enums, and data structures from the MT5 gRPC API
π― What This Tool DoesΒΆ
The Protobuf Inspector is an interactive command-line tool that helps you explore the structure of the MT5 gRPC API:
- β Interactive search for types, fields, and enums
- β Real-time inspection of protobuf message structures
- β Field-level discovery - find which types contain specific fields
- β Enum value exploration - see all possible enum values
- β Type browsing - list all available types in the API
π Getting StartedΒΆ
Running the InspectorΒΆ
You will see an interactive prompt:
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β β
β π INTERACTIVE PROTOBUF TYPES INSPECTOR π β
β β
β Explore MT5 gRPC API Types, Fields & Enums β
β β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Package: github.com/MetaRPC/GoMT5/package
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β QUICK START GUIDE β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β’ Type 'help' for full command list β
β β’ Type 'list' to see all available types β
β β’ Type a type name to inspect it (e.g., 'PositionInfo') β
β β’ Type 'exit' to quit β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
>
π Available CommandsΒΆ
| Command | Description | Example |
|---|---|---|
list or ls |
Show all available protobuf types | list |
<TypeName> |
Inspect specific type structure | PositionInfo |
search <text> or find <text> |
Search for types whose name contains text | search Order |
field <name> |
Find all types with a field whose name contains <name> |
field Balance |
enum <name> |
Show all enum values | enum BMT5_ENUM_ORDER_TYPE |
help or ? |
Show help message | help |
exit, quit or q |
Exit the inspector | exit |
π‘ Practical ExamplesΒΆ
Example 1: Find out what fields PositionInfo hasΒΆ
Command:
Output:
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β TYPE: PositionInfo β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π Fields (25):
β’ Index : uint32
(protobuf field #1)
β’ Ticket : uint64
(protobuf field #2)
β’ OpenTime : *Timestamp
(protobuf field #3)
β’ OpenTimeUtc : *Timestamp
(protobuf field #21)
β’ Volume : float64
(protobuf field #4)
β’ PriceOpen : float64
(protobuf field #5)
...
β’ Type : BMT5_ENUM_POSITION_TYPE
(protobuf field #12)
β’ MagicNumber : int64
(protobuf field #13)
β’ Identifier : int64
(protobuf field #14)
β’ Reason : BMT5_ENUM_POSITION_REASON
(protobuf field #15)
β’ Symbol : string
(protobuf field #16)
β’ Comment : string
(protobuf field #17)
β’ ExternalId : string
(protobuf field #18)
β’ PositionCommission : float64
(protobuf field #19)
β’ AccountLogin : int64
(protobuf field #20)
π‘ To see field values of an enum, use: enum <EnumName>
The names and types are the Go ones (float64, *Timestamp), exactly as you use them in code. The count in
Fields (N) includes the three internal protobuf fields that are not listed.
Example 2: Find which types have the "Ticket" fieldΒΆ
Command:
Output:
π Searching for field 'Ticket'...
β
Found in 17 type(s):
π¦ DealHistoryData:
ββ Ticket: uint64
π¦ MqlTradeRequest:
ββ OrderTicket: uint64
ββ PositionTicket: uint64
π¦ MqlTradeResult:
ββ DealTicket: uint64
ββ OrderTicket: uint64
...
π¦ OrderCloseRequest:
ββ Ticket: uint64
π¦ OrderModifyRequest:
ββ Ticket: uint64
π¦ PositionHistoryInfo:
ββ PositionTicket: uint64
π¦ PositionInfo:
ββ Ticket: uint64
Example 3: See all ORDER_TYPE enum valuesΒΆ
Command:
Output:
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ENUM: BMT5_ENUM_ORDER_TYPE β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
BMT5_ENUM_ORDER_TYPE_BMT5_ORDER_TYPE_BUY = 0
BMT5_ENUM_ORDER_TYPE_BMT5_ORDER_TYPE_SELL = 1
BMT5_ENUM_ORDER_TYPE_BMT5_ORDER_TYPE_BUY_LIMIT = 2
BMT5_ENUM_ORDER_TYPE_BMT5_ORDER_TYPE_SELL_LIMIT = 3
BMT5_ENUM_ORDER_TYPE_BMT5_ORDER_TYPE_BUY_STOP = 4
BMT5_ENUM_ORDER_TYPE_BMT5_ORDER_TYPE_SELL_STOP = 5
BMT5_ENUM_ORDER_TYPE_BMT5_ORDER_TYPE_BUY_STOP_LIMIT = 6
BMT5_ENUM_ORDER_TYPE_BMT5_ORDER_TYPE_SELL_STOP_LIMIT = 7
BMT5_ENUM_ORDER_TYPE_BMT5_ORDER_TYPE_CLOSE_BY = 8
The value names are the full Go constant names - in code write pb.BMT5_ENUM_ORDER_TYPE_BMT5_ORDER_TYPE_BUY.
Example 4: Find all types related to "Position"ΒΆ
Command:
Output:
π Searching for types containing 'Position'...
β
Found 24 type(s):
[Struct] OnPositionProfitData
[Struct] OnPositionProfitPositionInfo
[Struct] OnPositionProfitReply
...
[Struct] PositionHistoryInfo
[Struct] PositionInfo
[Struct] PositionsHistoryData
[Struct] PositionsHistoryReply
[Struct] PositionsHistoryReply_Data
[Struct] PositionsHistoryReply_Error
[Struct] PositionsHistoryRequest
[Struct] PositionsTotalData
...
π‘ Type a name to inspect it
search looks at type names only (enums are found with enum <name>).
Example 5: Show all available typesΒΆ
Command:
Output:
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ALL PROTOBUF TYPES β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π¦ Found 267 types:
[Type] AccountInfoDoubleData
[Reply] AccountInfoDoubleReply
[Type] AccountInfoDoubleReply_Data
[Type] AccountInfoDoubleReply_Error
[Request] AccountInfoDoubleRequest
...
[Reply] TickValueWithSizeReply
[Request] TickValueWithSizeRequest
π‘ Type a name to inspect it (e.g., 'PositionInfo')
π Common Use CasesΒΆ
USE CASE 1: "Getting 'field not found' error"ΒΆ
Problem: Your code has summary.Balance but it doesn't compile
Solution:
Result: Shows the correct field name and which type has it
β
Found in 3 type(s):
π¦ AccountSummaryData:
ββ AccountBalance: float64
π¦ MrpcMqlTradeCheckResult:
ββ BalanceAfterDeal: float64
π¦ OnEventAccountInfo:
ββ Balance: float64
Fix: Use summary.AccountBalance on the AccountSummaryData returned by account.AccountSummary()
USE CASE 2: "What fields does X have?"ΒΆ
Problem: Don't know what data is in PositionInfo
Solution:
Result: Shows all fields (Ticket, Type, Symbol, Profit, etc.)
USE CASE 3: "What are valid enum values?"ΒΆ
Problem: Don't know what value to use for OrderType
Solution:
Result: Shows all values:
BMT5_ENUM_ORDER_TYPE_BMT5_ORDER_TYPE_BUY = 0
BMT5_ENUM_ORDER_TYPE_BMT5_ORDER_TYPE_SELL = 1
BMT5_ENUM_ORDER_TYPE_BMT5_ORDER_TYPE_BUY_LIMIT = 2
...
USE CASE 4: "Need to find position-related types"ΒΆ
Problem: Exploring the API, need to see all position-related structures
Solution:
Result: Shows all types with "Position" in the name
USE CASE 5: "Want to browse what's available"ΒΆ
Problem: New to the API, want to explore
Solution:
Result: Shows all available types, sorted alphabetically and tagged [Request], [Reply], [Info] or [Type]
π StatisticsΒΆ
- Total Types: 267 (all MT5 gRPC protobuf message types)
- Total Enums: 67 (with 943 enum values)
- Coverage: 100% of MT5 gRPC API
π Important Enums (Frequently Used)ΒΆ
| Enum Name | Description | Common Values |
|---|---|---|
BMT5_ENUM_ORDER_TYPE |
Order types | BUY, SELL, BUY_LIMIT, SELL_LIMIT, BUY_STOP, SELL_STOP |
BMT5_ENUM_ORDER_TYPE_FILLING |
Fill policies | FOK, IOC, Return, BOC |
BMT5_ENUM_ORDER_TYPE_TIME |
Time in force | GTC, Day, Specified, Specified Day |
BMT5_ENUM_DEAL_REASON |
Deal execution reason | Client, Expert, SL, TP, Mobile |
BMT5_ENUM_DEAL_ENTRY_TYPE |
Deal entry type | In, Out, InOut, Out By |
BMT5_ENUM_POSITION_TYPE |
Position direction | BUY, SELL |
BMT5_ENUM_POSITION_REASON |
Why position opened | Client, Expert, Mobile, Web, SL, TP, SO |
MqlErrorCode |
MQL error codes | 211 different error codes |
MqlErrorTradeCode |
Trading operation errors | REQUOTE, REJECT, MARKET_CLOSED, etc. |
SymbolInfoDoubleProperty |
Symbol price properties | BID, ASK, POINT, SWAP_LONG, SWAP_SHORT |
SymbolInfoIntegerProperty |
Symbol integer properties | DIGITS, SPREAD, TRADE_MODE, etc. |
MRPC_ENUM_TRADE_REQUEST_ACTIONS |
Trade actions | DEAL, PENDING, SLTP, MODIFY, REMOVE |
β¨ FeaturesΒΆ
| Feature | Description |
|---|---|
| Case-insensitive search | search Order = search order; type and enum names are matched case-insensitively too |
| Partial field matching | field profit finds both Profit and TakeProfit |
| Type categorization | list shows [Request], [Reply], [Type], [Info] tags |
| Array indicators | π icon for repeated/array fields |
| Protobuf field numbers | Shows field #N for each field |
| Helpful hints | Suggests search <name> / list when a type is not found |
π¬ Example Interactive SessionΒΆ
$ go run main.go inspect
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β π INTERACTIVE PROTOBUF TYPES INSPECTOR π β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
> search Order
π Searching for types containing 'Order'...
β
Found 56 type(s):
[Struct] OnPositionsAndPendingOrdersTicketsData
...
[Struct] OpenedOrderInfo
[Struct] OpenedOrdersData
...
[Struct] OrderSendRequest
...
> OpenedOrderInfo
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β TYPE: OpenedOrderInfo β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π Fields (30):
β’ Index : uint32
(protobuf field #1)
β’ Ticket : uint64
(protobuf field #2)
...
β’ Type : BMT5_ENUM_ORDER_TYPE
β’ State : BMT5_ENUM_ORDER_STATE
...
β’ TypeFilling : BMT5_ENUM_ORDER_TYPE_FILLING
β’ TypeTime : BMT5_ENUM_ORDER_TYPE_TIME
...
> field Magic
π Searching for field 'Magic'...
β
Found in 10 type(s):
π¦ MqlTradeRequest:
ββ Magic: uint64
π¦ MrpcMqlTradeRequest:
ββ ExpertAdvisorMagicNumber: uint64
...
π¦ PositionInfo:
ββ MagicNumber: int64
> enum BMT5_ENUM_ORDER_STATE
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ENUM: BMT5_ENUM_ORDER_STATE β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
BMT5_ENUM_ORDER_STATE_BMT5_ORDER_STATE_STARTED = 0
BMT5_ENUM_ORDER_STATE_BMT5_ORDER_STATE_PLACED = 1
BMT5_ENUM_ORDER_STATE_BMT5_ORDER_STATE_CANCELED = 2
BMT5_ENUM_ORDER_STATE_BMT5_ORDER_STATE_PARTIAL = 3
BMT5_ENUM_ORDER_STATE_BMT5_ORDER_STATE_FILLED = 4
BMT5_ENUM_ORDER_STATE_BMT5_ORDER_STATE_REJECTED = 5
BMT5_ENUM_ORDER_STATE_BMT5_ORDER_STATE_EXPIRED = 6
BMT5_ENUM_ORDER_STATE_BMT5_ORDER_STATE_REQUEST_ADD = 7
BMT5_ENUM_ORDER_STATE_BMT5_ORDER_STATE_REQUEST_MODIFY = 8
BMT5_ENUM_ORDER_STATE_BMT5_ORDER_STATE_REQUEST_CANCEL = 9
> exit
π Goodbye!
π» Implementation DetailsΒΆ
The Protobuf Inspector uses Go reflection to:
- Register all protobuf types at startup
- Build an in-memory index of types, fields, and enums
- Provide instant search and lookup
- Format output with box drawing and emoji markers
Source file: examples/demos/helpers/17_protobuf_inspector.go
Registration: the 267 types are registered from a fixed list of sample values, and all 943 enum values of the 67 enums are written out in the code. A type or enum added to the API later appears only after it is added to that file.
π§ Technical NotesΒΆ
- No MT5 connection required - This is a purely offline tool that inspects type definitions
- Complete coverage - All 267 types and 67 enums from the MT5 gRPC API
- Instant search - In-memory index for fast lookup
- Development only - Not intended for production use
π― When to Use This ToolΒΆ
β Use the inspector when:
- Learning the MT5 gRPC API structure
- Debugging "field not found" errors
- Exploring available protobuf types
- Looking up enum values
- Finding the correct request/response types for API calls
- Understanding message structures before writing code
β Don't use for:
- Inspecting runtime data (use debugger instead)
- Production code (this is a development tool)
- Testing API connectivity (use demo connections instead)
π Tips and TricksΒΆ
- Start with search - If you know the general area, use
search <keyword>first - Use field search - When you see a field name but don't know which type, use
field <name> - Explore enums early - Understanding enum values saves debugging time later
- List is your friend - When stuck, use
listto browse available types - Case doesn't matter - Type commands in lowercase, it's faster
π Quick Start WorkflowΒΆ
Beginner workflow for exploring the API:
# 1. Start the inspector
go run main.go inspect
# 2. Browse what's available
> list
# 3. Search for what you need
> search Position
# 4. Inspect a type
> PositionInfo
# 5. Check enum values
> enum BMT5_ENUM_POSITION_TYPE
# 6. Find related types
> field Ticket
π Learning Session ExampleΒΆ
Goal: "I want to close a position, what do I need?"
> search close
β
Found 7 type(s):
[Struct] CloseChartForSymbolReply
[Struct] CloseChartForSymbolRequest
[Struct] OrderCloseData
[Struct] OrderCloseReply
[Struct] OrderCloseReply_Data
[Struct] OrderCloseReply_Error
[Struct] OrderCloseRequest
> OrderCloseRequest
β’ Ticket : uint64
(protobuf field #1)
β’ Volume : float64
(protobuf field #2)
β’ Slippage : int32
(protobuf field #5)
> OrderCloseData
β’ ReturnedCode : uint32
(protobuf field #1)
β’ ReturnedStringCode : string
(protobuf field #2)
β’ ReturnedCodeDescription : string
(protobuf field #3)
β’ CloseMode : MRPC_ORDER_CLOSE_MODE
(protobuf field #4)
# Now you know:
# - Call account.OrderClose with an OrderCloseRequest (Ticket; Volume for a partial close)
# - You'll get OrderCloseData back
# - Check ReturnedCode == 10009 for success (a refused request comes back as an error instead)
search matches one piece of text: search position close finds nothing, search close does.
π TroubleshootingΒΆ
Q: Type not found
> MyType
β Type 'MyType' not found
π‘ Try: 'search MyType' to find similar types
π‘ Or: 'list' to see all available types
A: Use search with partial name to find similar types
Q: Too many results
A: Be more specific in your search query
Q: What's the difference between OpenedOrderInfo and OrderSendRequest?
A: Use the inspector:
OpenedOrderInfo- Information about an existing (pending) orderOrderSendRequest- Request to create a new order
Rule:
*Request- Input for API method*Data- Output of the API method (what MT5Account methods return)*Reply- gRPC reply wrapper that carries eitherDataorError*Info- Structured data about entities
π SummaryΒΆ
The Protobuf Inspector is your first stop when working with the MT5 gRPC API. Use it to:
- π Discover available types
- π Learn message structures
- π Debug field name issues
- β Verify enum values
- π Speed up development
Remember: Type help at any time for command reference!
Next Steps:
- Run
go run main.go inspectand explore! - Check MT5Account Master Overview for complete API documentation
- Try the demo examples in
examples/demos/