{"id":18895638,"url":"https://github.com/binance/binance-connector-go","last_synced_at":"2025-05-16T05:07:27.782Z","repository":{"id":149994912,"uuid":"621815083","full_name":"binance/binance-connector-go","owner":"binance","description":"Simple GO connector to Binance API","archived":false,"fork":false,"pushed_at":"2024-11-21T01:39:25.000Z","size":186,"stargazers_count":235,"open_issues_count":17,"forks_count":87,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-04-12T04:44:25.164Z","etag":null,"topics":["binance-api","connector","crypto","golang","library","market-data","real-time","trading"],"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/binance.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","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":"2023-03-31T12:53:50.000Z","updated_at":"2025-04-11T06:02:30.000Z","dependencies_parsed_at":"2024-06-19T14:03:49.605Z","dependency_job_id":"b1bb1100-c32f-438e-ae7a-d56c15af3c30","html_url":"https://github.com/binance/binance-connector-go","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binance%2Fbinance-connector-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binance%2Fbinance-connector-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binance%2Fbinance-connector-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binance%2Fbinance-connector-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/binance","download_url":"https://codeload.github.com/binance/binance-connector-go/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254471060,"owners_count":22076585,"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":["binance-api","connector","crypto","golang","library","market-data","real-time","trading"],"created_at":"2024-11-08T08:29:11.513Z","updated_at":"2025-05-16T05:07:22.768Z","avatar_url":"https://github.com/binance.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Binance Spot Go Connector\n\nThis is a lightweight library that works as a connector to [Binance public API](https://github.com/binance/binance-spot-api-docs)\n\n## Supported API Endpoints:\n- Account/Trade: `account.go`\n- Wallet: `wallet.go`\n- Margin Account/Trade: `margin.go`\n- Market Data: `market.go`\n- Sub-Accounts: `subaccount.go`\n- Staking: `staking.go`\n- Websocket Market/User Data Stream: `websocket.go`\n- Websocket User Data Stream: `user_stream.go`\n\n## Installation\n```shell\ngo get github.com/binance/binance-connector-go\n```\n\nTo reference the package in your code, use the following import statement:\n```golang\nimport (\n    \"github.com/binance/binance-connector-go\"\n)\n```\n## Authentication\n```go\n// The Client can be initiated with apiKey, secretKey and baseURL.\n// The baseURL is optional. If not specified, it will default to \"https://api.binance.com\".\nclient := binance_connector.NewClient(\"yourApiKey\", \"yourSecretKey\")\n```\n\n## Extra Options\n```go\nclient := binance_connector.NewClient(\"yourApiKey\", \"yourSecretKey\", \"https://api.binance.com\")\n\n// Debug Mode\nclient.Debug = true\n\n// TimeOffset (in milliseconds) - used to adjust the request timestamp by subtracting/adding the current time with it:\nclient.TimeOffset = -1000 // implies adding: request timestamp = current time - (-1000)\n```\n\n## REST API\n\nCreate an order example\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\tbinance_connector \"github.com/binance/binance-connector-go\"\n)\n\nfunc main() {\n\tapiKey := \"yourApiKey\"\n\tsecretKey := \"yourSecretKey\"\n\tbaseURL := \"https://testnet.binance.vision\"\n\n\t// Initialise the client\n\tclient := binance_connector.NewClient(apiKey, secretKey, baseURL)\n\n\t// Create new order\n\tnewOrder, err := client.NewCreateOrderService().Symbol(\"BTCUSDT\").\n\t\tSide(\"BUY\").Type(\"MARKET\").Quantity(0.001).\n\t\tDo(context.Background())\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\tfmt.Println(binance_connector.PrettyPrint(newOrder))\n}\n```\n\nPlease find more examples for each supported endpoint in the `examples` folder.\n\n## Websocket Stream\nInitialising Websocket Client\n- Websocket Client can be initialized with 2 parameters, `NewWebsocketStreamClient(isCombined, baseURL)`:\n- `isCombined` is a MANDATORY boolean value that specifies whether you are calling a combined stream or not.\n  - If `isCombined` is set to `true`, `\"/stream?streams=\"` will be appended to the `baseURL` to allow for Combining streams.\n  - Otherwise, if set to `false`, `\"/ws/\"` will be appended to the `baseURL`.\n- `baseURL` is an OPTIONAL string value that determines the base URL to use for the websocket connection.\n  - If `baseURL` is not set, it will default to the Live Exchange URL: `\"wss://stream.binance.com:9443\"`.\n\n```go\n// Initialise Websocket Client with Production baseURL and false for \"isCombined\" parameter\n\nwebsocketStreamClient := binance_connector.NewWebsocketStreamClient(false, \"wss://stream.testnet.binance.vision\")\n\n// Initialise Websocket Client with Production baseURL and true for \"isCombined\" parameter\n\nwebsocketStreamClient := binance_connector.NewWebsocketStreamClient(true)\n```\n\nDiff. Depth Stream Example\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\tbinance_connector \"github.com/binance/binance-connector-go\"\n)\n\nfunc main() {\n\t// Initialise Websocket Client with Testnet BaseURL and false for \"isCombined\" parameter\n\twebsocketStreamClient := binance_connector.NewWebsocketStreamClient(false, \"wss://stream.testnet.binance.vision\")\n\n\twsDepthHandler := func(event *binance_connector.WsDepthEvent) {\n\t\tfmt.Println(binance_connector.PrettyPrint(event))\n\t}\n\n\terrHandler := func(err error) {\n\t\tfmt.Println(err)\n\t}\n\n\t// Depth stream subscription\n\tdoneCh, stopCh, err := websocketStreamClient.WsDepthServe(\"BNBUSDT\", wsDepthHandler, errHandler)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\n\tgo func() {\n\t\ttime.Sleep(30 * time.Second)\n\t\tstopCh \u003c- struct{}{} // use stopCh to stop streaming\n\t}()\n\n\t\u003c-doneCh\n}\n```\n\nCombined Diff. Depth Stream Example\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\tbinance_connector \"github.com/binance/binance-connector-go\"\n)\n\nfunc main() {\n\t// Set isCombined parameter to true as we are using Combined Depth Stream\n\twebsocketStreamClient := binance_connector.NewWebsocketStreamClient(true)\n\n\twsCombinedDepthHandler := func(event *binance_connector.WsDepthEvent) {\n\t\tfmt.Println(binance_connector.PrettyPrint(event))\n\t}\n\terrHandler := func(err error) {\n\t\tfmt.Println(err)\n\t}\n\t// Use WsCombinedDepthServe to subscribe to multiple streams\n\tdoneCh, stopCh, err := websocketStreamClient.WsCombinedDepthServe([]string{\"LTCBTC\", \"BTCUSDT\", \"MATICUSDT\"}, wsCombinedDepthHandler, errHandler)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\tgo func() {\n\t\ttime.Sleep(5 * time.Second)\n\t\tstopCh \u003c- struct{}{}\n\t}()\n\t\u003c-doneCh\n}\n```\n\n## Websocket API\n\n```go\nfunc OCOHistoryExample() {\n\t// Initialise Websocket API Client\n\tclient := binance_connector.NewWebsocketAPIClient(\"api_key\", \"secret_key\")\n\t// Connect to Websocket API\n\terr := client.Connect()\n\tif err != nil {\n\t\tlog.Printf(\"Error: %v\", err)\n\t\treturn\n\t}\n\tdefer client.Close()\n\n\t// Send request to Websocket API\n\tresponse, err := client.NewAccountOCOHistoryService().Do(context.Background())\n\tif err != nil {\n\t\tlog.Printf(\"Error: %v\", err)\n\t\treturn\n\t}\n\n\t// Print the response\n\tfmt.Println(binance_connector.PrettyPrint(response))\n\n\tclient.WaitForCloseSignal()\n}\n```\n\n## Base URL\n- Binance provides alternative Production URLs in case of performance issues:\n  - https://api1.binance.com\n  - https://api2.binance.com\n  - https://api3.binance.com\n\n## Testnet Support\n- In order to use the Testnet, simply set the `baseURL` to \"https://testnet.binance.vision\"\n- You can find step-by-step instructions on how to use the get a Testnet API and Secret Key [here](https://dev.binance.vision/t/binance-testnet-environments/99)\n\n## Pretty Print vs PrintLn\n- The `fmt.Println(\u003cresponse\u003e)` function will print the struct in a single line, which is not very readable.\n- The `fmt.Println(binance_connector.PrettyPrint(\u003cresponse\u003e))` function will print the struct, including both the key and value, in a multi-line format which is more easily readable.\n\n### Regular PrintLn Example Output\n```bash\n\u0026{depthUpdate 1680092520368 LTCBTC 1989614201 1989614210 [{0.00322300 70.96700000} {0.00322200 52.57100000} {0.00322000 248.64000000} {0.00321900 34.98300000}] [{0.00322600 71.52600000} {0.00323400 53.88900000} {0.00323500 27.37000000}]}\n\u0026{depthUpdate 1680092521368 LTCBTC 1989614211 1989614212 [{0.00320700 197.10100000} {0.00320100 15.76800000}] []}\n\u0026{depthUpdate 1680092522368 LTCBTC 1989614213 1989614224 [{0.00322300 86.15400000} {0.00322200 37.38400000} {0.00322100 252.53900000} {0.00322000 60.01300000}] [{0.00322800 75.48400000} {0.00322900 254.84500000} {0.00323000 8.74700000} {0.00323100 37.42800000}]}\n\u0026{depthUpdate 1680092523369 LTCBTC 1989614225 1989614226 [{0.00322300 103.57400000}] [{0.00399500 11.75400000}]}\n\u0026{depthUpdate 1680092524369 LTCBTC 1989614227 1989614276 [{0.00322500 0.00000000} {0.00322400 101.32700000} {0.00322300 138.82600000} {0.00322200 58.49100000} {0.00322100 249.65400000} {0.00321900 47.34800000} {0.00317800 16.08500000} {0.00317500 38.36500000}] [{0.00322500 75.14300000} {0.00322600 48.19100000} {0.00322700 44.97900000} {0.00322800 242.74300000} {0.00322900 20.73400000} {0.00532700 0.18900000} {0.00779700 0.05600000}]}\n```\n\n### binance_connector.PrettyPrint Example Output\n```bash\n{\n\t\"e\": \"depthUpdate\",\n\t\"E\": 1680092041346,\n\t\"s\": \"LTCBTC\",\n    \"U\": 1989606566,\n\t\"u\": 1989606596,\n\t\"b\": [\n\t\t{\n\t\t\t\"Price\": \"0.00322800\",\n\t\t\t\"Quantity\": \"83.05100000\"\n\t\t},\n\t\t{\n\t\t\t\"Price\": \"0.00322700\",\n\t\t\t\"Quantity\": \"12.50200000\"\n\t\t},\n\t\t{\n\t\t\t\"Price\": \"0.00322500\",\n\t\t\t\"Quantity\": \"48.53700000\"\n\t\t},\n\t\t{\n\t\t\t\"Price\": \"0.00322400\",\n\t\t\t\"Quantity\": \"244.13500000\"\n\t\t}\n\t],\n\t\"a\": [\n\t\t{\n\t\t\t\"Price\": \"0.00322900\",\n\t\t\t\"Quantity\": \"79.52900000\"\n\t\t},\n\t\t{\n\t\t\t\"Price\": \"0.00323000\",\n\t\t\t\"Quantity\": \"42.68400000\"\n\t\t},\n\t\t{\n\t\t\t\"Price\": \"0.00323100\",\n\t\t\t\"Quantity\": \"68.75500000\"\n\t\t}\n\t]\n}\n{\n\t\"e\": \"depthUpdate\",\n\t\"E\": 1680092042346,\n\t\"s\": \"LTCBTC\",\n\t\"U\": 1989606597,\n\t\"u\": 1989606611,\n\t\"b\": [\n\t\t{\n\t\t\t\"Price\": \"0.00321400\",\n\t\t\t\"Quantity\": \"0.24700000\"\n\t\t},\n\t\t{\n\t\t\t\"Price\": \"0.00318000\",\n\t\t\t\"Quantity\": \"1.91600000\"\n\t\t}\n\t],\n\t\"a\": [\n\t\t{\n\t\t\t\"Price\": \"0.00322900\",\n\t\t\t\"Quantity\": \"79.27900000\"\n\t\t}\n\t]\n}\n```\n\n## Limitations\nFutures and European Options APIs are not supported:\n- /fapi/*\n- /dapi/*\n- /vapi/*\n- Associated Websocket Market and User Data Streams\n\n## Contributing\nContributions are welcome.\u003cbr/\u003e\nIf you've found a bug within this project, please open an issue to discuss what you would like to change.\u003cbr/\u003e\nIf it's an issue with the API, please open a topic at [Binance Developer Community](https://dev.binance.vision)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinance%2Fbinance-connector-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbinance%2Fbinance-connector-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinance%2Fbinance-connector-go/lists"}