aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: b47cc4f4a437206f54e3c5a6255146f9524e43c1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# MT4 Client Library

[![Go Reference](https://pkg.go.dev/badge/go.popov.link/metatrader4.svg)](https://pkg.go.dev/go.popov.link/metatrader4)
[![codecov](https://codecov.io/gh/valentineus/go-metatrader4/graph/badge.svg?token=6ZE32TQERQ)](https://codecov.io/gh/valentineus/go-metatrader4)

A lightweight Go client library for interacting with a MetaTrader 4 (MT4) trading server over TCP.

## Example Usage

```go
import "go.popov.link/metatrader4/mt4"

client := mt4.NewClient("127.0.0.1", 443,
    mt4.WithDialTimeout(3*time.Second),
    mt4.WithAutoClose(true),
)
ctx := context.Background()
params := map[string]string{
    "login":    "55555",
    "password": "_some_password_",
}
res, err := client.Execute(ctx, "WWAPUSER", params)
```

The `Execute` method sends a raw MT4 command. Parameters are encoded using base64 and Windows-1251.
Use `WithAutoClose(false)` if you want to reuse the connection manually via `client.Close()`.

## Options

- `WithDialTimeout(d time.Duration)`: Sets the timeout for establishing a TCP connection. Default: 5s.
- `WithReadTimeout(d time.Duration)`: Sets the maximum time to wait for a server response. Default: 5s.
- `WithWriteTimeout(d time.Duration)`: Sets the maximum time to complete sending a request. Default: 5s.
- `WithAutoClose(enabled bool)`: If `true`, closes the connection after each `Execute` (default). Use `false` to reuse the session manually via `client.Close()`.

## Requirements

- Go 1.24 or later
- MetaTrader 4 server with TCP access

## Maintainer & Project Info

- Vanity import path: `go.popov.link/metatrader4`
- Source mirror (read-only): [code.popov.link](https://code.popov.link/valentineus/go-metatrader4)
- Issues and contributions: [GitHub](https://github.com/valentineus/go-metatrader4/issues)

Maintained by [Valentin Popov](mailto:valentin@popov.link).

## License

This project is licensed under the [MIT License](LICENSE.txt).