diff options
author | Valentin Popov <valentin@popov.link> | 2025-06-04 11:08:19 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-04 11:08:19 +0300 |
commit | 7240595478fedec02e9e47c704976cf56a66d3e8 (patch) | |
tree | 300165d4ecf00fed03d33b36863370384cbdc7ce /examples/info | |
parent | 76dc648f33a9f96e68d5c9000032c2b986bd5a3d (diff) | |
download | go-metatrader4-7240595478fedec02e9e47c704976cf56a66d3e8.tar.xz go-metatrader4-7240595478fedec02e9e47c704976cf56a66d3e8.zip |
First version
Diffstat (limited to 'examples/info')
-rw-r--r-- | examples/info/README.md | 53 | ||||
-rw-r--r-- | examples/info/main.go | 25 |
2 files changed, 78 insertions, 0 deletions
diff --git a/examples/info/README.md b/examples/info/README.md new file mode 100644 index 0000000..e6ac4d4 --- /dev/null +++ b/examples/info/README.md @@ -0,0 +1,53 @@ +# Example: INFO Command + +This example demonstrates how to use the [`go-metatrader4`](https://github.com/valentineus/go-metatrader4) library to send the `INFO` command to a MetaTrader 4 (MT4) server and retrieve server information. + +The `INFO` command requests basic server details such as build version and company name. + +## Usage + +To run this example: + +```bash +go run main.go +``` + +Make sure you are connected to an MT4 server that accepts TCP connections on the configured host and port. + +## Code Overview + +```go +client := mt4.NewClient("127.0.0.1", 443, + mt4.WithDialTimeout(3*time.Second), + mt4.WithReadTimeout(5*time.Second), + mt4.WithWriteTimeout(5*time.Second), +) +ctx := context.Background() +resp, err := client.Execute(ctx, "INFO", nil) + +``` + +This code creates an MT4 client, sends the INFO command without parameters, and prints the response to stdout. + +## Expected Response Format + +The response typically looks like this: + +```text +MetaTrader 4 Server 4.00 build 1380 +Some Broker Company Name +``` + +Where: + +- `build 1380` — current server build number +- `Some Broker Company Name` — name of the White Label owner of the server + +## Requirements + +- Go 1.24 or later +- Access to a running MetaTrader 4 server + +## License + +This example is provided under the MIT License. See the [main project license](../../LICENSE.txt) for details.
\ No newline at end of file diff --git a/examples/info/main.go b/examples/info/main.go new file mode 100644 index 0000000..260ecba --- /dev/null +++ b/examples/info/main.go @@ -0,0 +1,25 @@ +package main + +import ( + "context" + "fmt" + "log" + "time" + + "go.popov.link/metatrader4/mt4" +) + +func main() { + client := mt4.NewClient("127.0.0.1", 443, + mt4.WithDialTimeout(3*time.Second), + mt4.WithReadTimeout(5*time.Second), + mt4.WithWriteTimeout(5*time.Second), + ) + ctx := context.Background() + // INFO does not require parameters + resp, err := client.Execute(ctx, "INFO", nil) + if err != nil { + log.Fatal(err) + } + fmt.Println(resp) +} |