mirror of
https://github.com/valentineus/go-metatrader4.git
synced 2025-06-08 18:13:34 +03:00
Compare commits
10 Commits
42e56fe0cb
...
e287424387
Author | SHA1 | Date | |
---|---|---|---|
e287424387 | |||
3b579b3bab | |||
67ea5c1c87 | |||
b139fd5838 | |||
711a5a0348 | |||
949d77e2cf | |||
084efb9167 | |||
![]() |
e76b35c45e | ||
78e99bdb75 | |||
5d9af62383 |
10
.github/dependabot.yml
vendored
Normal file
10
.github/dependabot.yml
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: "gomod"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "weekly"
|
||||||
|
- package-ecosystem: "github-actions"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "weekly"
|
31
.github/renovate.json
vendored
Normal file
31
.github/renovate.json
vendored
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||||
|
"extends": [
|
||||||
|
"config:recommended",
|
||||||
|
":disableDependencyDashboard"
|
||||||
|
],
|
||||||
|
"assignees": [
|
||||||
|
"valentineus"
|
||||||
|
],
|
||||||
|
"labels": [
|
||||||
|
"dependencies",
|
||||||
|
"automated"
|
||||||
|
],
|
||||||
|
"packageRules": [
|
||||||
|
{
|
||||||
|
"description": "Group patch & minor updates together",
|
||||||
|
"groupName": "all digest updates",
|
||||||
|
"groupSlug": "all-digest",
|
||||||
|
"matchUpdateTypes": [
|
||||||
|
"minor",
|
||||||
|
"patch",
|
||||||
|
"pin",
|
||||||
|
"digest"
|
||||||
|
],
|
||||||
|
"matchPackageNames": [
|
||||||
|
"*"
|
||||||
|
],
|
||||||
|
"automerge": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
12
.github/workflows/ci.yml
vendored
12
.github/workflows/ci.yml
vendored
@ -2,9 +2,9 @@ name: CI
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ master ]
|
branches: [master]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ master ]
|
branches: [master]
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
@ -19,7 +19,7 @@ jobs:
|
|||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v5
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: '1.24.2'
|
go-version: "1.24.3"
|
||||||
- name: Cache Go modules
|
- name: Cache Go modules
|
||||||
uses: actions/cache@v4
|
uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
@ -37,6 +37,10 @@ jobs:
|
|||||||
run: go vet ./...
|
run: go vet ./...
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: go test -race -coverprofile=coverage.out -covermode=atomic ./...
|
run: go test -race -coverprofile=coverage.out -covermode=atomic ./...
|
||||||
|
- name: Upload coverage reports
|
||||||
|
uses: codecov/codecov-action@v5
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.CODECOV_TOKEN }}
|
||||||
|
|
||||||
lint:
|
lint:
|
||||||
name: Lint
|
name: Lint
|
||||||
@ -47,7 +51,7 @@ jobs:
|
|||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v5
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: '1.24.2'
|
go-version: "1.24.3"
|
||||||
- name: Run golangci-lint
|
- name: Run golangci-lint
|
||||||
uses: golangci/golangci-lint-action@v8
|
uses: golangci/golangci-lint-action@v8
|
||||||
with:
|
with:
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
# MT4 Client Library
|
# MT4 Client Library
|
||||||
|
|
||||||
|
[](https://pkg.go.dev/go.popov.link/metatrader4)
|
||||||
|
[](https://codecov.io/gh/valentineus/go-metatrader4)
|
||||||
|
|
||||||
A lightweight Go client library for interacting with a MetaTrader 4 (MT4) trading server over TCP.
|
A lightweight Go client library for interacting with a MetaTrader 4 (MT4) trading server over TCP.
|
||||||
|
|
||||||
## Example Usage
|
## Example Usage
|
||||||
@ -34,7 +37,7 @@ Use `WithAutoClose(false)` if you want to reuse the connection manually via `cli
|
|||||||
- Go 1.24 or later
|
- Go 1.24 or later
|
||||||
- MetaTrader 4 server with TCP access
|
- MetaTrader 4 server with TCP access
|
||||||
|
|
||||||
## Maintainer & Project Info
|
## Project Info
|
||||||
|
|
||||||
- Vanity import path: `go.popov.link/metatrader4`
|
- Vanity import path: `go.popov.link/metatrader4`
|
||||||
- Source mirror (read-only): [code.popov.link](https://code.popov.link/valentineus/go-metatrader4)
|
- Source mirror (read-only): [code.popov.link](https://code.popov.link/valentineus/go-metatrader4)
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Conn is a wrapper around net.Conn with convenience helpers.
|
||||||
type Conn struct {
|
type Conn struct {
|
||||||
netConn net.Conn
|
netConn net.Conn
|
||||||
}
|
}
|
||||||
@ -14,6 +15,7 @@ type Conn struct {
|
|||||||
// FromNetConn wraps an existing net.Conn. Useful for tests.
|
// FromNetConn wraps an existing net.Conn. Useful for tests.
|
||||||
func FromNetConn(n net.Conn) *Conn { return &Conn{netConn: n} }
|
func FromNetConn(n net.Conn) *Conn { return &Conn{netConn: n} }
|
||||||
|
|
||||||
|
// Dial opens a TCP connection to addr using the given timeout.
|
||||||
func Dial(ctx context.Context, addr string, timeout time.Duration) (*Conn, error) {
|
func Dial(ctx context.Context, addr string, timeout time.Duration) (*Conn, error) {
|
||||||
d := net.Dialer{Timeout: timeout}
|
d := net.Dialer{Timeout: timeout}
|
||||||
c, err := d.DialContext(ctx, "tcp", addr)
|
c, err := d.DialContext(ctx, "tcp", addr)
|
||||||
@ -23,6 +25,7 @@ func Dial(ctx context.Context, addr string, timeout time.Duration) (*Conn, error
|
|||||||
return &Conn{netConn: c}, nil
|
return &Conn{netConn: c}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close closes the underlying network connection.
|
||||||
func (c *Conn) Close() error {
|
func (c *Conn) Close() error {
|
||||||
if c.netConn == nil {
|
if c.netConn == nil {
|
||||||
return nil
|
return nil
|
||||||
@ -30,6 +33,7 @@ func (c *Conn) Close() error {
|
|||||||
return c.netConn.Close()
|
return c.netConn.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Send writes data to the connection with the provided timeout.
|
||||||
func (c *Conn) Send(ctx context.Context, data []byte, timeout time.Duration) error {
|
func (c *Conn) Send(ctx context.Context, data []byte, timeout time.Duration) error {
|
||||||
if dl, ok := ctx.Deadline(); ok {
|
if dl, ok := ctx.Deadline(); ok {
|
||||||
if err := c.netConn.SetWriteDeadline(dl); err != nil {
|
if err := c.netConn.SetWriteDeadline(dl); err != nil {
|
||||||
@ -44,6 +48,7 @@ func (c *Conn) Send(ctx context.Context, data []byte, timeout time.Duration) err
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Receive reads all data from the connection with the provided timeout.
|
||||||
func (c *Conn) Receive(ctx context.Context, timeout time.Duration) ([]byte, error) {
|
func (c *Conn) Receive(ctx context.Context, timeout time.Duration) ([]byte, error) {
|
||||||
if dl, ok := ctx.Deadline(); ok {
|
if dl, ok := ctx.Deadline(); ok {
|
||||||
if err := c.netConn.SetReadDeadline(dl); err != nil {
|
if err := c.netConn.SetReadDeadline(dl); err != nil {
|
||||||
|
2
internal/conn/doc.go
Normal file
2
internal/conn/doc.go
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
// Package conn wraps net.Conn with simple timeout helpers.
|
||||||
|
package conn
|
2
internal/proto/doc.go
Normal file
2
internal/proto/doc.go
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
// Package proto provides helpers for encoding requests and decoding responses.
|
||||||
|
package proto
|
5
mt4/doc.go
Normal file
5
mt4/doc.go
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
// Package mt4 provides a lightweight client for MetaTrader 4 servers.
|
||||||
|
//
|
||||||
|
// It establishes a TCP connection, sends commands, and returns the decoded
|
||||||
|
// server response.
|
||||||
|
package mt4
|
Loading…
x
Reference in New Issue
Block a user