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:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
MT5 PROTOBUF TYPE INSPECTOR
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Available: 267 types, 67 enums
Type 'help' for available commands
Type 'list' to see all types
Type a type name to inspect it
>
π 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 containing text | search Order |
field <name> |
Find all types with a specific field | field Balance |
enum <name> |
Show all enum values | enum BMT5_ENUM_ORDER_TYPE |
help or ? |
Show help message | help |
exit or quit |
Exit the inspector | exit |
π‘ Practical ExamplesΒΆ
Example 1: Find out what fields PositionInfo hasΒΆ
Command:
Output:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
TYPE: PositionInfo
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Fields:
Index: uint32 (#1)
Ticket: uint64 (#2)
OpenTime: google.protobuf.Timestamp (#3)
Volume: double (#4)
PriceOpen: double (#5)
StopLoss: double (#6)
TakeProfit: double (#7)
PriceCurrent: double (#8)
Swap: double (#9)
Profit: double (#10)
LastUpdateTime: google.protobuf.Timestamp (#11)
Type: BMT5_ENUM_POSITION_TYPE (#12)
MagicNumber: int64 (#13)
Identifier: int64 (#14)
Reason: BMT5_ENUM_POSITION_REASON (#15)
Symbol: string (#16)
Comment: string (#17)
ExternalId: string (#18)
PositionCommission: double (#19)
AccountLogin: int64 (#20)
Example 2: Find which types have the "Ticket" fieldΒΆ
Command:
Output:
Field 'Ticket' found in 15 types:
β’ PositionInfo
β’ OrderInfo
β’ DealInfo
β’ HistoryOrdersGetByTicketRequest
β’ HistoryDealsGetByTicketRequest
β’ OrderCloseRequest
β’ OrderModifyRequest
β’ PositionCloseRequest
β’ PositionModifyRequest
...
Example 3: See all ORDER_TYPE enum valuesΒΆ
Command:
Output:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ENUM: BMT5_ENUM_ORDER_TYPE
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Values:
BMT5_ORDER_TYPE_BUY = 0
BMT5_ORDER_TYPE_SELL = 1
BMT5_ORDER_TYPE_BUY_LIMIT = 2
BMT5_ORDER_TYPE_SELL_LIMIT = 3
BMT5_ORDER_TYPE_BUY_STOP = 4
BMT5_ORDER_TYPE_SELL_STOP = 5
BMT5_ORDER_TYPE_BUY_STOP_LIMIT = 6
BMT5_ORDER_TYPE_SELL_STOP_LIMIT = 7
BMT5_ORDER_TYPE_CLOSE_BY = 8
Total: 9 values
Example 4: Find all types related to "Position"ΒΆ
Command:
Output:
Found 8 types matching 'Position':
β’ PositionInfo
β’ PositionsGetRequest
β’ PositionsGetData
β’ PositionCloseRequest
β’ PositionCloseData
β’ PositionModifyRequest
β’ PositionModifyData
β’ BMT5_ENUM_POSITION_TYPE
Example 5: Show all available typesΒΆ
Command:
Output:
All available types (267):
[A]
β’ AccountInfo
β’ AccountSummaryData
β’ AccountSummaryRequest
...
[B]
β’ BalanceOperationData
β’ BookInfoRequest
...
[C]
β’ ChartPriceCurrentData
β’ ChartPriceCurrentRequest
...
π Common Use CasesΒΆ
USE CASE 1: "Getting 'field not found' error"ΒΆ
Problem: Your code has position.Ballance but it doesn't work
Solution:
Result: Shows the correct field name and which type has it
Fix: Use accountInfo.Balance, not position.Balance
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:
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, grouped alphabetically (actual count displayed by tool)
π StatisticsΒΆ
- Total Types: 267 (all MT5 gRPC protobuf message types)
- Total Enums: 67 (with 1400+ 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, Dealer, Mobile |
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 |
| Partial field matching | field profit finds both Profit and TakeProfit |
| Type categorization | Shows [Request], [Reply], [Type], [Info] tags |
| Array indicators | π icon for repeated/array fields |
| Protobuf field numbers | Shows field #N for each field |
| Smart error messages | Suggests alternatives when type not found |
π¬ Example Interactive SessionΒΆ
$ go run main.go inspect
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
MT5 PROTOBUF TYPE INSPECTOR
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
> search Order
Found 42 types matching 'Order':
β’ OrderInfo
β’ OrderSendRequest
β’ OrderSendData
β’ OrderCheckRequest
β’ OrderCalcMarginRequest
...
> OrderInfo
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
TYPE: OrderInfo
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Fields:
Ticket: uint64 (#1)
Type: BMT5_ENUM_ORDER_TYPE (#2)
State: BMT5_ENUM_ORDER_STATE (#3)
TypeFilling: BMT5_ENUM_ORDER_TYPE_FILLING (#4)
...
> field Magic
Field 'Magic' found in 8 types:
β’ OrderInfo
β’ PositionInfo
β’ DealInfo
β’ MqlTradeRequest
...
> enum BMT5_ENUM_ORDER_STATE
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ENUM: BMT5_ENUM_ORDER_STATE
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Values:
BMT5_ORDER_STATE_STARTED = 0
BMT5_ORDER_STATE_PLACED = 1
BMT5_ORDER_STATE_CANCELED = 2
BMT5_ORDER_STATE_PARTIAL = 3
BMT5_ORDER_STATE_FILLED = 4
BMT5_ORDER_STATE_REJECTED = 5
BMT5_ORDER_STATE_EXPIRED = 6
BMT5_ORDER_STATE_REQUEST_ADD = 7
BMT5_ORDER_STATE_REQUEST_MODIFY = 8
BMT5_ORDER_STATE_REQUEST_CANCEL = 9
Total: 10 values
> 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 color and structure
Source file: examples/demos/helpers/17_protobuf_inspector.go
Enum registration: All 1400+ enum values across 67 enums are manually registered in the code (Go protobuf doesn't support automatic enum value discovery via reflection).
π§ 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 position close
Found 2 types:
β’ PositionCloseRequest
β’ PositionCloseData
> PositionCloseRequest
Fields:
Ticket: uint64 (#1)
Deviation: uint64 (#2)
Comment: string (#3)
> PositionCloseData
Fields:
ReturnedCode: uint32 (#1)
OrderTicket: uint64 (#2)
# Now you know:
# - Use PositionCloseRequest with Ticket field
# - You'll get PositionCloseData back
# - Check ReturnedCode == 10009 for success
π TroubleshootingΒΆ
Q: Type not found
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 OrderInfo and OrderSendRequest?
A: Use the inspector:
OrderInfo- Information about an existing orderOrderSendRequest- Request to create a new order
Rule:
*Request- Input for API method*Reply/*Data- Output from API method*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/