MT5 gRPC Golang client example

Created with Sketch.

MT5 gRPC Golang client example

Table of Contents

Methods browser.

Proto file.

Install go sdk first

Ready to run example

Use commands to run the example:

go build main.go
go run main.go

package main

import (
    "context"
    "crypto/tls"
    "fmt"
    "log"

    mt5grpc "git.mtapi.io/root/grpc-proto.git/mt5/go"
    "google.golang.org/grpc"
    "google.golang.org/grpc/credentials"
)

func main() {
    config := &tls.Config{
        InsecureSkipVerify: false,
    }
    client, err := grpc.Dial("mt5grpc.mtapi.io:443", grpc.WithTransportCredentials(credentials.NewTLS(config)))
    if err != nil {
        log.Fatalf("failed to connect: %v", err)
    }
    defer client.Close()

    connection := mt5grpc.NewConnectionClient(client)
    mt5 := mt5grpc.NewMT5Client(client)
    //trading := mt5grpc.NewTradingClient(client)
    //service := mt5grpc.NewServiceClient(client)
    subscriptions := mt5grpc.NewSubscriptionsClient(client)
    streams := mt5grpc.NewStreamsClient(client)

    resp, err := connection.Connect(context.Background(), &mt5grpc.ConnectRequest{
        Host:     "78.140.180.198",
        Password: "tecimil4",
        Port:     443,
        User:     62333850,
    })
    if err != nil {
        log.Fatalf("gRPC protocol error: %v", err)
    }
    if resp.Error != nil {
        log.Fatalf("Server error: %v", resp.Error.Message)
    }
    fmt.Println(resp)
    id := resp.Result

    response, err := mt5.AccountSummary(context.Background(), &mt5grpc.AccountSummaryRequest{
        Id: id,
    })
    if err != nil {
        log.Fatalf("gRPC protocol error: %v", err)
    }
    if resp.Error != nil {
        log.Fatalf("Server error: %v", resp.Error.Message)
    }
    fmt.Println(response)

    r1, _ := subscriptions.Subscribe(context.Background(), &mt5grpc.SubscribeRequest{
        Id:       id,
        Interval: 0,
        Symbol:   "EURUSD",
    })
    fmt.Println(r1)

    stream, _ := streams.OnQuote(context.Background(), &mt5grpc.OnQuoteRequest{
        Id: id,
    })
    for {
        quote, _ := stream.Recv()
        fmt.Println(quote)
    }
}

4 Responses

  1. googletest says:

    I’ve been exploring for a bit for any high quality
    articles or blog posts on this sort of space .
    Exploring in Yahoo I eventually stumbled upon this web site.
    Reading this info So i’m satisfied to exhibit that I have
    a very good uncanny feeling I found out just what I needed.
    I most without a doubt will make sure to don?t disregard this site
    and provides it a look on a constant basis.

  2. googletest says:

    Do you have any video of that? I’d care to find out some additional information.

Leave a Reply

Your email address will not be published. Required fields are marked *