8000 GitHub - yjkt/mt5-go · GitHub
[go: up one dir, main page]

Skip to content
yjktPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

go-mt5

通过 Windows 命名管道与 MetaTrader 5 (MT5) 终端通信的 Go 客户端库。

功能

  • 通过 Windows 命名管道连接到 MT5 终端
  • 获取账户信息(余额、预付款、盈亏等)
  • 获取终端信息(连接状态、Ping延迟、路径等)
  • 获取报价数据
  • 获取品种信息

安装

go get github.com/your-repo/go-mt5

使用示例

package main

import (
    "fmt"
    "github.com/your-repo/go-mt5"
)

func main() {
    client, err := mt5.NewClient()
    if err != nil {
        panic(err)
    }
    defer client.Disconnect()

    // 初始化连接
    err = client.Initialize("")
    if err != nil {
        panic(err)
    }

    // 获取账户信息
    account, err := client.AccountInfo()
    if err != nil {
        panic(err)
    }
    fmt.Printf("Balance: %.2f\n", account.Balance)

    // 获取终端信息
    terminal, err := client.TerminalInfo()
    if err != nil {
        panic(err)
    }
    fmt.Printf("Ping: %d ms\n", terminal.PingLast)
}

协议说明

MT5 终端通过 Windows 命名管道暴露服务,通信协议基于自定义二进制格式:

  • 使用 UTF-16LE 编码的字符串
  • 数值类型包括 i32、u16、f64 等
  • 布尔值使用 1 字节存储
  • 字符串长度使用 4 字节 u32 前缀

测试

go test -v ./...

注意事项

  • 仅支持 Windows 平台
  • 需要有正在运行的 MT5 终端
  • 某些功能需要 MT5 终端处于连接状态才能正常返回数据

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0