futugg

package module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 15, 2024 License: MIT Imports: 13 Imported by: 0

README

FutuGG

FutuGG是基于FutuOpenD网关实现的Golang的SDK包,项目中使用了原生了proto文件,注意不要更改生成的go文件,修改了import路径。

特别声明

因为futugg是跟金钱打交道的,可能你会用来做交易。如果在使用过程中触发了某个bug,导致金钱损失,一切后果请自行承担!!!

环境依赖

  • 安装Google的protobuf,protoc-gen-go工具
  • Golang1.9及最新版本

使用方式


package main

import (
    "fmt"
    "futugg"
    _ "futugg/handlers"
)

func main() {

    block := make(chan bool)
    cli := futugg.New("0.0.0.0", "11250", "")

    futugg.Cmd("send.GetGlobalState", cli)
    cli.KeepAlive()

    // recv
    go func() {
        fmt.Println("start recv data")
        cli.Recv()
    }()

    // futugg.Cmd("send.Qot_Sub", cli, "HK.01810", "Broker", true, true, "None", false)
    // futugg.Cmd("send.Qot_RegQotPush", cli, "US.BILI", "Basic", true, false)
    // futugg.Cmd("send.Qot_GetSubInfo", cli, true)
    // futugg.Cmd("recv.Qot_UpdateBasicQot", cli, "HK.01810")
    // futugg.Cmd("send.Qot_GetKL", cli, "None", "1Min", "HK.01810", int32(1))
    // futugg.Cmd("recv.Qot_UpdateKL", cli, "HK.01810")
    // futugg.Cmd("send.Qot_GetRT", cli, "HK.01810")
    // futugg.Cmd("recv.Qot_UpdateRT", cli, "HK.01810")
    // futugg.Cmd("send.Qot_GetTicker", cli, "HK.01810", int32(2))
    // futugg.Cmd("send.Qot_GetOrderBook", cli, "HK.01810", int32(2))
    // futugg.Cmd("send.Qot_GetBroker", cli, "HK.01810")
    // futugg.Cmd("send.Qot_RequestHistoryKL", cli, "None", "1Min", "HK.01810", "2019-01-09 16:00:00", "2019-01-09 16:05:00")
    // futugg.Cmd("send.Qot_GetTradeDate", cli, int32(1), "2019-01-08 16:00:00", "2019-01-09 16:00:00")
    // futugg.Cmd("send.Qot_GetStaticInfo", cli, int32(1), int32(3), "HK.01810")
    // futugg.Cmd("send.Qot_GetPlateSet", cli, int32(1), int32(0))
    futugg.Cmd("send.Qot_GetPlateSecurity", cli, "HK.01810")

    <-block
}


使用前,需要启动富途网关OpenD,具体操作详见futu-api-doc介绍

广告

如有需要,可以填写推荐人牛牛号:7189075,谢谢哟!

文档简介

ProtoId 名称 说明
1001 InitConnect 初始化连接
1002 GetGlobalState 获取全局状态
1003 Notify 系统通知推送
1004 KeepAlive 保活心跳
2001 Trd_GetAccList 获取业务账户列表
2005 Trd_UnlockTrade 解锁或锁定交易
2008 Trd_SubAccPush 订阅业务账户的交易推送数据
2101 Trd_GetFunds 获取账户资金
2102 Trd_GetPositionList 获取账户持仓
2111 Trd_GetMaxTrdQtys 获取最大交易数量
2201 Trd_GetOrderList 获取订单列表
2202 Trd_PlaceOrder 下单
2205 Trd_ModifyOrder 修改订单
2208 Trd_UpdateOrder 推送订单状态变动通知
2211 Trd_GetOrderFillList 获取成交列表
2218 Trd_UpdateOrderFill 推送成交通知
2221 Trd_GetHistoryOrderList 获取历史订单列表
2222 Trd_GetHistoryOrderFillList 获取历史成交列表
3001 Qot_Sub 订阅或者反订阅
3002 Qot_RegQotPush 注册推送
3003 Qot_GetSubInfo 获取订阅信息
3004 Qot_GetBasicQot 获取股票基本行情
3005 Qot_UpdateBasicQot 推送股票基本行情
3006 Qot_GetKL 获取K线
3007 Qot_UpdateKL 推送K线
3008 Qot_GetRT 获取分时
3009 Qot_UpdateRT 推送分时
3010 Qot_GetTicker 获取逐笔
3011 Qot_UpdateTicker 推送逐笔
3012 Qot_GetOrderBook 获取买卖盘
3013 Qot_UpdateOrderBook 推送买卖盘
3014 Qot_GetBroker 获取经纪队列
3015 Qot_UpdateBroker 推送经纪队列
3100 Qot_GetHistoryKL 从本地下载历史数据获取单只股票一段历史K线
3101 Qot_GetHistoryKLPoints 从本地下载历史数据获取多只股票多点历史K线
3102 Qot_GetRehab 从本地下载历史数据获取复权信息
3103 Qot_RequestHistoryKL 在线获取单只股票一段历史K线
3200 Qot_GetTradeDate 获取市场交易日
3202 Qot_GetStaticInfo 获取股票静态信息
3203 Qot_GetSecuritySnapshot 获取股票快照
3204 Qot_GetPlateSet 获取板块集合下的板块
3205 Qot_GetPlateSecurity 获取板块下的股票
3206 Qot_GetReference 获取正股相关股票
3207 Qot_GetOwnerPlate 获取股票所属板块
3208 Qot_GetHoldingChangeList 获取持股变化列表

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cmd

func Cmd(name string, params ...interface{}) error

func HasHandler

func HasHandler(name string) bool

func On

func On(name string, fn interface{}) error

func SetHandlerId

func SetHandlerId(id uint32, name string)

func TransHandlerId

func TransHandlerId(id uint32) (string, bool)

Types

type FutuGG

type FutuGG struct {
	Host              string
	Port              string
	Pass              string
	Conn              net.Conn
	SyncMode          bool
	ServerVer         int32
	ConnID            uint64
	LoginUserID       uint64
	ConnAESKey        string
	KeepAliveInterval int32
}

func New

func New(host string, port string, pass string) *FutuGG

func (*FutuGG) Close

func (c *FutuGG) Close()

func (*FutuGG) KeepAlive

func (c *FutuGG) KeepAlive()

func (*FutuGG) Recv

func (c *FutuGG) Recv() []byte

func (*FutuGG) Send

func (c *FutuGG) Send(pack *FutuPack) error

type FutuPack

type FutuPack struct {
	HeaderFlag    [2]uint8  // [0]"F" [1]"T"
	ProtoId       uint32    // proto id
	ProtoType     uint8     // proto 类型,0 proto,1 json
	ProtoVer      uint8     // proto version 用于迭代 默认0
	SeqNo         uint32    // seq number 用于回包
	BodyLen       uint32    // body length
	BodySha1      [20]uint8 // body sha1
	ReservedField [8]uint8  // 预留8位
	Body          []byte    // body content
}

func (*FutuPack) Decode

func (p *FutuPack) Decode(recv []byte) error

func (*FutuPack) Encode

func (p *FutuPack) Encode() ([]byte, error)

func (*FutuPack) SetBody

func (p *FutuPack) SetBody(c2sBody []byte)

func (*FutuPack) SetProto

func (p *FutuPack) SetProto(protoId uint32)

func (*FutuPack) ToString

func (p *FutuPack) ToString() string

Directories

Path Synopsis
pb
Qot_Common
Package Qot_Common is a generated protocol buffer package.
Package Qot_Common is a generated protocol buffer package.
Qot_GetHoldingChangeList
Package Qot_GetHoldingChangeList is a generated protocol buffer package.
Package Qot_GetHoldingChangeList is a generated protocol buffer package.
Qot_GetOwnerPlate
Package Qot_GetOwnerPlate is a generated protocol buffer package.
Package Qot_GetOwnerPlate is a generated protocol buffer package.
Qot_GetReference
Package Qot_GetReference is a generated protocol buffer package.
Package Qot_GetReference is a generated protocol buffer package.
Qot_GetStaticInfo
Package Qot_GetStaticInfo is a generated protocol buffer package.
Package Qot_GetStaticInfo is a generated protocol buffer package.
Qot_RequestHistoryKL
Package Qot_RequestHistoryKL is a generated protocol buffer package.
Package Qot_RequestHistoryKL is a generated protocol buffer package.
Trd_GetMaxTrdQtys
Package Trd_GetMaxTrdQtys is a generated protocol buffer package.
Package Trd_GetMaxTrdQtys is a generated protocol buffer package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL