Skip to content

qtopie/gofutuapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-futu-api

富途牛牛OpenD Go API【非官方】

go-futu-api

在树莓派(arm64)上运行OpenD

也可以安装Windows/MacOS/Linux(amd64)等版本,开发时推荐使用GUI版本方便调试

使用box64

先运行box64 ./FTUpdate保证软件是最新的, 然后运行box64 ./FutuOpenD

代码示例

更多代码参考cmd/main.go

package main

import (
	"context"
	"fmt"
	"log"
	"os"
	"os/signal"
	"syscall"
	"time"

	"github.com/qtopie/gofutuapi"
	"github.com/qtopie/gofutuapi/gen/common/getuserinfo"
	"google.golang.org/protobuf/proto"
)

func main() {
	ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
	defer cancel()

  // 建立连接
	conn, err := gofutuapi.Open(ctx, gofutuapi.FutuApiOption{
		Address: "localhost:11111",
		Timeout: 5 * time.Second,
	})
	if err != nil {
		log.Fatalf("Failed to connect: %v", err)
	}
	defer conn.Close() // Ensure the connection is closed when done

  // 构造获取用户基本信息请求
	flag := int32(getuserinfo.UserInfoField_UserInfoField_Basic)
	req := getuserinfo.Request{
		C2S: &getuserinfo.C2S{
			Flag: &flag,
		},
	}
  // 发送请求数据包
	conn.SendProto(1005, &req)
  // 读取响应
	reply, err := conn.NextReplyPacket()
	if err != nil {
		log.Println(err)
	} else {
		var resp getuserinfo.Response
		err = proto.Unmarshal(reply.Payload, &resp)
		if err != nil {
			panic(err)
		}
     // 打印结果
		log.Println(resp.String())
	}

	<-ctx.Done()
	fmt.Println("Main goroutine exiting.")
}

K线可视化(Plotly)

运行示例会生成 docs/kl-data.json,并启动内置 Go HTTP 服务展示最近 7 天、30 天、180 天(月K)、3 年(季K)的K线。

go run ./cmd

然后访问:http://localhost:8000/kl-viewer.html

kl

⚖️ 法律声明 (Legal Disclaimer)

本项目是基于富途证券 (Futu Securities) 公开协议文档开发的第三方 Go 语言集成库。

  • 合规性:本项目遵循富途官方关于“自行对接协议”的指引。
  • 协议修改说明:为适配 Go 语言特性,本项目对原始 .proto 定义进行了必要的命名规范调整和技术适配。
  • 免责声明:本项目不提供任何金融投资建议,不对因代码 Bug 或交易导致的亏损负责。使用前请详细阅读 LEGAL_NOTICE.md

alt text

About

FutuOpenD Go API

Topics

Resources

License

Stars

Watchers

Forks