{"id":21493255,"url":"https://github.com/hyperjiang/futu","last_synced_at":"2025-03-17T11:41:26.211Z","repository":{"id":263098107,"uuid":"871102547","full_name":"hyperjiang/futu","owner":"hyperjiang","description":"Futu open api golang client. 富途Open API最好用的Golang客户端","archived":false,"fork":false,"pushed_at":"2025-02-10T11:14:56.000Z","size":447,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-10T12:24:54.578Z","etag":null,"topics":["client","futu","golang","sdk"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hyperjiang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-11T09:21:03.000Z","updated_at":"2025-02-10T11:15:00.000Z","dependencies_parsed_at":"2025-02-10T12:23:23.463Z","dependency_job_id":"3094f796-aadb-4dce-b66b-5a27e5bf36f7","html_url":"https://github.com/hyperjiang/futu","commit_stats":null,"previous_names":["hyperjiang/futu"],"tags_count":2,"template":false,"template_full_name":"hyperjiang/go-tpl","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperjiang%2Ffutu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperjiang%2Ffutu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperjiang%2Ffutu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperjiang%2Ffutu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hyperjiang","download_url":"https://codeload.github.com/hyperjiang/futu/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244029466,"owners_count":20386413,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["client","futu","golang","sdk"],"created_at":"2024-11-23T15:41:03.181Z","updated_at":"2025-03-17T11:41:26.186Z","avatar_url":"https://github.com/hyperjiang.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Futu open api golang client\n\n[![GoDoc](https://pkg.go.dev/badge/github.com/hyperjiang/futu)](https://pkg.go.dev/github.com/hyperjiang/futu)\n[![CI](https://github.com/hyperjiang/futu/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/hyperjiang/futu/actions/workflows/ci.yml)\n[![](https://goreportcard.com/badge/github.com/hyperjiang/futu)](https://goreportcard.com/report/github.com/hyperjiang/futu)\n[![codecov](https://codecov.io/gh/hyperjiang/futu/graph/badge.svg?token=iI7hyTEenz)](https://codecov.io/gh/hyperjiang/futu)\n[![Release](https://img.shields.io/github/release/hyperjiang/futu.svg)](https://github.com/hyperjiang/futu/releases)\n\n富途牛牛 OpenAPI Golang 客户端，要求Golang版本 \u003e= 1.21\n\nFutu Open API 官方文档: https://openapi.futunn.com/futu-api-doc/\n\n## 代码目录说明\n\n- `根目录`: 提供用户友好的客户端SDK，对底层的`client`包做了一层用法包装\n- `client`: 基础客户端，拥有所有功能，需要用pb定义的结构体传参，可以直接使用，但是使用起来略繁琐\n- `.proto`: protobuf 定义文件\n- `adapt`: protobuf 结构体和普通类型的适配层\n- `infra`: 底层支持库，使用者无需关心\n- `pb`: 基于 protobuf 文件生成的 golang 代码\n- `protoid`: 接口ID常量列表\n\n## 使用说明\n\n本SDK跟`FutuOpenD`的通信协议格式是protobuf，使用`FutuOpenD`的默认配置即可，不要改成json格式。\n\n具体用法可以参考单元测试，里面每个接口都有用例。\n\n方法设计的原则是，必填参数显式要求传递，可选参数放在可变参数`adapt.Option`传递。但有部分必填参数实际上可以有默认值，这种情况不会显式要求传递。\n\n每个接口都有一对方法，其中结尾有`WithContext`的方法是方便让使用者可以自己通过context设置超时时间，不带`WithContext`的方法使用了默认超时时间5s。\n\n以下是一个简单示例：\n\n```go\nimport \"github.com/hyperjiang/futu\"\n\nsdk, err := futu.NewSDK()\nif err != nil {\n    log.Fatal(err)\n}\n\nres, err := client.GetGlobalState()\nfmt.Println(res)\n```\n\n对于系统推送过来的数据，需要调用`RegisterHandler(protoID uint32, h Handler)`来注册自己的处理逻辑。\n如果没有设置，SDK会使用默认的Handler，只打印收到的消息到日志。\n可以设置推送Handler的协议ID如下:\n\n- protoid.Notify // 1003\n- protoid.TrdUpdateOrder // 2208\n- protoid.TrdUpdateOrderFill // 2218\n- protoid.QotUpdateBasicQot // 3005\n- protoid.QotUpdateKL // 3007\n- protoid.QotUpdateRT // 3009\n- protoid.QotUpdateTicker // 3011\n- protoid.QotUpdateOrderBook // 3013\n- protoid.QotUpdateBroker // 3015\n- protoid.QotUpdatePriceReminder // 3019\n\n设置其他ID没有任何作用，因为永远不可能触发到。\n\n## 支持的功能\n\n### 基础功能（用户无需调用）\n- [x] 支持使用RSA和AES加解密\n- [x] 初始化连接\n- [x] 获取全局状态\n- [x] 事件通知推送\n- [x] 保活心跳\n\n### 行情接口\n- [x] QotSub                     = 3001 // 订阅或者反订阅\n- [x] QotGetSubInfo              = 3003 // 获取订阅信息\n- [x] QotGetBasicQot             = 3004 // 获取股票基本报价\n- [x] QotUpdateBasicQot          = 3005 // 推送股票基本报价\n- [x] QotGetKL                   = 3006 // 获取K线\n- [x] QotUpdateKL                = 3007 // 推送K线\n- [x] QotGetRT                   = 3008 // 获取分时\n- [x] QotUpdateRT                = 3009 // 推送分时\n- [x] QotGetTicker               = 3010 // 获取逐笔\n- [x] QotUpdateTicker            = 3011 // 推送逐笔\n- [x] QotGetOrderBook            = 3012 // 获取买卖盘\n- [x] QotUpdateOrderBook         = 3013 // 推送买卖盘\n- [x] QotGetBroker               = 3014 // 获取经纪队列\n- [x] QotUpdateBroker            = 3015 // 推送经纪队列\n- [x] QotUpdatePriceReminder     = 3019 // 到价提醒通知\n- [x] QotRequestHistoryKL        = 3103 // 在线获取单只股票一段历史K线\n- [x] QotRequestHistoryKLQuota   = 3104 // 获取历史K线额度\n- [x] QotRequestRehab            = 3105 // 在线获取单只股票复权信息\n- [x] QotGetStaticInfo           = 3202 // 获取股票静态信息\n- [x] QotGetSecuritySnapshot     = 3203 // 获取股票快照\n- [x] QotGetPlateSet             = 3204 // 获取板块集合下的板块\n- [x] QotGetPlateSecurity        = 3205 // 获取板块下的股票\n- [x] QotGetReference            = 3206 // 获取正股相关股票\n- [x] QotGetOwnerPlate           = 3207 // 获取股票所属板块\n- [x] QotGetOptionChain          = 3209 // 获取期权链\n- [x] QotGetWarrant              = 3210 // 获取窝轮\n- [x] QotGetCapitalFlow          = 3211 // 获取资金流向\n- [x] QotGetCapitalDistribution  = 3212 // 获取资金分布\n- [x] QotGetUserSecurity         = 3213 // 获取自选股分组下的股票\n- [x] QotModifyUserSecurity      = 3214 // 修改自选股分组下的股票\n- [x] QotStockFilter             = 3215 // 获取条件选股\n- [x] QotGetIpoList              = 3217 // 获取新股\n- [x] QotGetFutureInfo           = 3218 // 获取期货合约资料\n- [x] QotRequestTradeDate        = 3219 // 获取市场交易日，在线拉取不在本地计算\n- [x] QotSetPriceReminder        = 3220 // 设置到价提醒\n- [x] QotGetPriceReminder        = 3221 // 获取到价提醒\n- [x] QotGetUserSecurityGroup    = 3222 // 获取自选股分组列表\n- [x] QotGetMarketState          = 3223 // 获取指定品种的市场状态\n- [x] QotGetOptionExpirationDate = 3224 // 获取期权到期日\n\n### 交易接口\n- [x] TrdGetAccList              = 2001 // 获取交易业务账户列表\n- [x] TrdUnlockTrade             = 2005 // 解锁或锁定交易\n- [x] TrdSubAccPush              = 2008 // 订阅业务账户的交易推送数据\n- [x] TrdGetFunds                = 2101 // 获取账户资金\n- [x] TrdGetPositionList         = 2102 // 获取账户持仓\n- [x] TrdGetMaxTrdQtys           = 2111 // 获取最大交易数量\n- [x] TrdGetOrderList            = 2201 // 获取订单列表\n- [x] TrdPlaceOrder              = 2202 // 下单\n- [x] TrdModifyOrder             = 2205 // 修改订单\n- [x] TrdUpdateOrder             = 2208 // 推送订单状态变动通知\n- [x] TrdGetOrderFillList        = 2211 // 获取成交列表\n- [x] TrdUpdateOrderFill         = 2218 // 推送成交通知\n- [x] TrdGetHistoryOrderList     = 2221 // 获取历史订单列表\n- [x] TrdGetHistoryOrderFillList = 2222 // 获取历史成交列表\n- [x] TrdGetMarginRatio          = 2223 // 获取融资融券数据\n- [x] TrdGetOrderFee             = 2225 // 获取订单费用\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyperjiang%2Ffutu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhyperjiang%2Ffutu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyperjiang%2Ffutu/lists"}