{"id":19036125,"url":"https://github.com/tx7do/huobi_futures_golang","last_synced_at":"2025-07-15T11:33:28.769Z","repository":{"id":57583542,"uuid":"371550794","full_name":"tx7do/huobi_futures_golang","owner":"tx7do","description":null,"archived":false,"fork":false,"pushed_at":"2021-05-28T02:27:56.000Z","size":57,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-13T06:44:05.125Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tx7do.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}},"created_at":"2021-05-28T01:50:27.000Z","updated_at":"2021-05-28T02:27:58.000Z","dependencies_parsed_at":"2022-08-30T21:21:42.637Z","dependency_job_id":null,"html_url":"https://github.com/tx7do/huobi_futures_golang","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/tx7do/huobi_futures_golang","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tx7do%2Fhuobi_futures_golang","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tx7do%2Fhuobi_futures_golang/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tx7do%2Fhuobi_futures_golang/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tx7do%2Fhuobi_futures_golang/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tx7do","download_url":"https://codeload.github.com/tx7do/huobi_futures_golang/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tx7do%2Fhuobi_futures_golang/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265432118,"owners_count":23764035,"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":[],"created_at":"2024-11-08T21:53:29.398Z","updated_at":"2025-07-15T11:33:28.703Z","avatar_url":"https://github.com/tx7do.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Huobi Futures Golang SDK (but only supports linearswap now)\n\nThis is Huobi Golang SDK, you can import it to your package.\n\nThe SDK API supports both RESTful and websocket to get/sub the market, account and order infomation.\n\n## Table of Contents\n\n- [Quick Start](#Quick-Start)\n\n- [Usage](#Usage)\n\n  - [Configuration](#Configuration)\n  - [Folder structure](#Folder-Structure)\n  - [Client](#Client)\n  - [Response](#Response)\n  \n- [Request examples](#Request-examples)\n  - [Market data](#Market-data)\n\n- [Subscription examples](#Subscription-examples)\n  - [Subscribe trade update](#Subscribe-trade-update)\n\n  \n\n## Quick Start\n\nThe SDK is run and test in go1.15.4, you can import the source code from remote or local what shuold be dowload first.\n\nThe package **sdk** is core code source as SDK API.\nThe package **test** is a unit test what you can find usage of each API interface in.\n\nIf you want to create your own application, you can follow below steps:\n\n* Create a client (xxxClient/WSxxxClient) instance.\n* Call the method of client instance.\n\n```go\n// RESTful api\nacClient := restful.AccountClient{}\nacClient.Init(\"AccessKey\", \"SecretKey\", \"\")\n\ndata := make(chan account.GetAccountAssetsResponse)\ngo acClient.GetAccountAssetsAsync(data, \"BTC-USDT\", 0)\nx, ok := \u003c-data\nif !ok || x.Status != \"ok\" {\n\t// fail\n} else {\n\t// success\n}\n\n// websocker api\nwsmkClient := new(ws.WSMarketClient).Init(\"\")\nwsmkClient.SubKLine(\"BTC-USDT\", \"15min\", func(m *market.SubKLineResponse) {\n\t// show response data with *m\n}, \"\")\ntime.Sleep(time.Duration(10) * time.Second)\nwsmkClient.UnsubKLine(\"BTC-USDT\", \"15min\", \"\")\ntime.Sleep(time.Duration(10) * time.Second)\n```\n\n## Usage\n\n### Configuration\n\nThe client Init function must set AccessKey/SecretKey two value when you access private data. And it not need to set AccessKey/SecretKey value when you access public data such as market data.\n\nYou can create config.json in your package for config AccessKey/SecretKey and other input data.\n\n```json\n{\n  \"Host\": \"api.hbdm.com\",\n  \"AccessKey\": \"x-x-x-x\",\n  \"SecretKey\": \"x-x-x-x\",\n  \"AccountId\": 10000000,\n  \"SubUid\": 10000000\n}\n```\nThen create config.go file to read the config.json file\n\n```go\nimport (\n\t\"encoding/json\"\n\t\"os\"\n)\n\ntype Config struct {\n\tHost      string\n\tAccessKey string\n\tSecretKey string\n\tAccountId int64\n\tSubUid    int64\n}\n\nvar config *Config\n\nfunc init() {\n\n\tfilePtr, err := os.Open(\"config.json\")\n\tif err != nil {\n\t\treturn\n\t}\n\tdefer filePtr.Close()\n\n\tconfig = new(Config)\n\tdecoder := json.NewDecoder(filePtr)\n\terr = decoder.Decode(config)\n}\n ```\n\nAnd use it as follow:\n```go\naccessKey := config.AccessKey\nsecretKey := config.SecretKey\n```\n\n### Folder Structure\n\nThis is the folder and namespace structure of SDK source code and the description\n\n- **sdk**: The SDK API package\n  - **linearswap**: the linear swap api src inclue RESTful and websocket\n  - **requestbuilder**: Responsible to build the request with the signature\n  - **log**: The internal logger interface and implementations\n  - **wsbase**: The websocket data model\n- **test**: The unit test package\n  - **xxx_test.go**: The golang unit test file\n\nYou can find all demo in xxx_test.go to get/sub linear swap private/public data\n\n### Client\n\nIn this SDK, the client is the object to access the Huobi API. All the client are listed in below table. Each client is very small and simple.\n\n| Access Type | Client | Privacy | Data Category  |\n| ----------- | -------| ------- | ------------ |\n| RESTful     | AccountClient | Private | account info |\n|             | MarketClient | Public | market info |\n|             | OrderClient | Private | about order |\n|             | TransferClient | Private | transfer assets |\n|             | TriggerOrderClient | Private | about trigger order |\n| Websocket   | WSIndexClinet | Public | index info |\n|             | WSMarketClinet | Public | market info |\n|             | WSNotifyClinet | Public/Private | market info/ account info |\n|             |                |         |              |\n\n#### Public vs. Private\n\nThere are two types of privacy that is correspondent with privacy of API:\n\n**Public client**: It invokes public API to get public data (Common data and Market data), therefore you can create a new instance without applying an API Key.\n\n```go\nmkClient := restful.MarketClient{}\nmkClient.Init(\"\")\n```\n\n**Private client**: It invokes private API to access private data, you need to follow the API document to apply an API Key first, and pass the API Key to the Init.\n\n```go\nacClient := restful.AccountClient{}\nacClient.Init(\"AccessKey\", \"SecretKey\", \"\")\n```\n\nThe API key is used for authentication. If the authentication cannot pass, the invoking of private interface will fail.\n\n#### Rest vs. WebSocket\n\n**Rest Client**: It invokes Rest API and get once-off response.\n\n```go\nacClient := restful.AccountClient{}\nacClient.Init(\"AccessKey\", \"SecretKey\", \"\")\n\ndata := make(chan account.GetAccountAssetsResponse)\ngo acClient.GetAccountAssetsAsync(data, \"BTC-USDT\", 0)\nx, ok := \u003c-data\nif !ok || x.Status != \"ok\" {\n\t// fail\n} else {\n\t// success\n}\n```\n\n**WebSocket Client**: It establishes WebSocket connection with server and data will be pushed from server actively. There are two types of method for WebSocket client:\n\n- Request method: The method name starts with \"Req\", it will receive the once-off data after sending the request.\n- Subscription: The method name starts with \"Sub\", it will receive update after sending the subscription.\n\n```go\nwsmkClient := new(ws.WSMarketClient).Init(\"\")\n\n// Reqxxx\nwsmkClient.ReqKLine(\"BTC-USDT\", \"1min\", func(m *market.ReqKLineResponse) {\n\t// show response data with *m\n}, 1604395758, 1604396758, \"\")\n\n// Subxxx\nwsmkClient.SubKLine(\"BTC-USDT\", \"15min\", func(m *market.SubKLineResponse) {\n\t// show response data with *m\n}, \"\")\ntime.Sleep(time.Duration(10) * time.Second)\nwsmkClient.UnsubKLine(\"BTC-USDT\", \"15min\", \"\")\ntime.Sleep(time.Duration(10) * time.Second)\n```\n\n#### Custom host\n\nEach client Init support an optional host parameter, by default it is \"api.btcgateway.pro\". If you need to use different host, you can specify the custom host. \n\n```go\nacClient := restful.AccountClient{}\nacClient.Init(\"AccessKey\", \"SecretKey\", \"Host\")\n\nwsmkClient := new(ws.WSMarketClient).Init(\"Host\")\n```\n\n### Response\n\nAll response data are defined as follow:\n- **huobi_futures_Golang.sdk.linearswap.restful.response**: all RESTful response data\n- **huobi_futures_Golang.sdk.linearswap.ws.response**: all websockt response data\n\n## Request Examples\n### Market data\n```go\nmkClient := restful.MarketClient{}\nmkClient.Init(\"\")\n\ndata := make(chan market.GetContractInfoResponse)\n\ngo mkClient.GetContractInfoAsync(data, \"\")\nx, ok := \u003c-data\nif !ok || x.Status != \"ok\" {\n\t// fail\n} else {\n\t// show data with x\n}\n```\n\n## Subscription Examples\n### Subscribe trade update\n```go\nwsnfClient := new(ws.WSNotifyClient).Init(\"AccessKey\", \"SecretKey\", \"\")\n\nwsnfClient.SubOrders(\"*\", func(m *notify.SubOrdersResponse) {\n\t// show dat with *m\n}, \"\")\ntime.Sleep(time.Duration(50) * time.Second)\nwsnfClient.UnsubOrders(\"*\", \"\")\ntime.Sleep(time.Duration(50) * time.Second)\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftx7do%2Fhuobi_futures_golang","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftx7do%2Fhuobi_futures_golang","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftx7do%2Fhuobi_futures_golang/lists"}