{"id":21001181,"url":"https://github.com/waxdred/bybit_websocket_go","last_synced_at":"2025-06-23T06:33:43.293Z","repository":{"id":142257692,"uuid":"611172620","full_name":"waxdred/bybit_websocket_go","owner":"waxdred","description":"Library for bybit websocket","archived":false,"fork":false,"pushed_at":"2023-03-12T09:12:33.000Z","size":51,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-14T23:37:21.561Z","etag":null,"topics":["bybit","bybit-websocket","cryptocurrency","go","library","trading","websocket"],"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/waxdred.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":"2023-03-08T09:16:20.000Z","updated_at":"2023-07-29T07:13:52.000Z","dependencies_parsed_at":"2023-05-02T05:02:52.084Z","dependency_job_id":null,"html_url":"https://github.com/waxdred/bybit_websocket_go","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/waxdred/bybit_websocket_go","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waxdred%2Fbybit_websocket_go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waxdred%2Fbybit_websocket_go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waxdred%2Fbybit_websocket_go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waxdred%2Fbybit_websocket_go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/waxdred","download_url":"https://codeload.github.com/waxdred/bybit_websocket_go/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waxdred%2Fbybit_websocket_go/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261429283,"owners_count":23157003,"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":["bybit","bybit-websocket","cryptocurrency","go","library","trading","websocket"],"created_at":"2024-11-19T08:14:06.099Z","updated_at":"2025-06-23T06:33:38.278Z","avatar_url":"https://github.com/waxdred.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bybit WebSocket Go Library\n![GitHub Workflow Status](https://github.com/waxdred/bybit_websocket_go/actions/workflows/go.yml/badge.svg)\n![GoDoc](https://godoc.org/github.com/golang/gddo?status.svg)\n### This is a Go package for connecting to Bybit's WebSocket API. It provides a simple way to connect to both public and private streams, and includes support for subscribing to and processing real-time market data, trading information, and account information.\n\n## Table of Contents\n- [Installation](#Installation)\n- [Usage](#Usage)\n- [Connection](#Connection)\n- [Public streams](#Public_streams)\n- [Private streams](#Private_streams)\n- [Testnet vs Mainnet](#Testnet_vs_Mainnet)\n- [Contributing](#Contributing)\n- [License](#License)\n\n# Installation\nTo use this package, you need to have Go installed on your system. You can then install the package by running:\n\n```go\ngo get github.com/waxdred/bybit_websocket_go\n```\n# Usage\nTo use the package, first import it:\n\n```go\nimport Bwss \"github.com/waxdred/bybit_websocket_go\"\n```\n## Connection\nTo create a new connection to the Bybit WebSocket API, use the New function of the WssBybit struct:\n\n```go\nwss := new(Bwss.WssBybit).New(true)\n```\nYou can pass a boolean parameter to enable or disable debugging messages.\n\nTo close all open connections, you can use the Close function:\n\n```go\ndefer wss.Close()\n```\n## Public_streams\nTo subscribe to a public stream, use the AddConnPublic function of the WssBybit struct, which takes the URL of the stream as its parameter:\n\n```go\n\nid, _ := wss.AddConnPublic(wss.WssUrl.Perpetual(Bwss.Mainnet))\n```\nThe function returns an ID that can be used to close the connection later.\n\nTo subscribe to a channel on the stream, use the AddPublicSubs function, which takes a list of channel names and a handler function as its parameters:\n\n```go\nwss.AddPublicSubs([]string{\"orderBookL2_25.BTCUSD\"}, func(wss *Bwss.WssBybit, sockk *Bwss.SocketMessage) {\n    fmt.Println(string(sockk.Msg))\n})\n```\n## Private_streams\nTo subscribe to a private stream, use the AddConnPrivate function of the WssBybit struct, which takes the URL of the stream, your API key, and your API secret as its parameters:\n\n```go\nwss.AddConnPrivate(wss.WssUrl.Private(Bwss.Testnet), apiKey, apiSecret)\n```\nTo subscribe to a channel on the stream, use the AddPrivateSubs function, which takes a list of channel names and a handler function for each channel as its parameters:\n\n```go\nwss.AddPrivateSubs([]string{\"wallet\", \"position\"}, func(wss *Bwss.WssBybit, sockk *Bwss.SocketMessage) {\n    wallet := Bwss.Wallet{}\n    sockk.Unmarshal(\u0026wallet)\n    log.Println(wallet.PrettyFormat())\n}, func(wss *Bwss.WssBybit, sockk *Bwss.SocketMessage) {\n    position := Bwss.Position{}\n    sockk.Unmarshal(\u0026position)\n    log.Println(position.PrettyFormat())\n})\n```\n\n## Testnet_vs_Mainnet\nBybit offers two separate environments for testing and live trading: Testnet and Mainnet. The Testnet environment allows you to test your strategies and code without risking real funds, while the Mainnet environment is for actual trading.\n\nIn the code, you can select which environment to use by passing either Bwss.Testnet or Bwss.Mainnet as the parameter to the WssUrl functions:\n\n```go\nwss.WssUrl.Perpetual(Bwss.Testnet) // for Testnet\nwss.WssUrl.Perpetual(Bwss\n```\nTestnet and Mainnet are two separate environments provided by Bybit for testing and live trading, respectively. Testnet is a sandbox environment that allows you to test your code and strategies without risking real funds, while Mainnet is the production environment used for actual trading.\n\nIn the provided code, you can select which environment to use by passing either Bwss.Testnet or Bwss.Mainnet as a parameter to the WssUrl functions. For example, to connect to the Testnet perpetual contract endpoint, you can use:\n\n```go\nwss.AddConnPublic(wss.WssUrl.Perpetual(Bwss.Testnet)).\n```\nAnd to connect to the Mainnet spot trading endpoint, you can use:\n\n```go\nwss.AddConnPublic(wss.WssUrl.Spot(Bwss.Mainnet)).\n````\n\nTestnet and Mainnet are two separate environments provided by Bybit for testing and live trading, respectively. Testnet is a sandbox environment that allows you to test your code and strategies without risking real funds, while Mainnet is the production environment used for actual trading.\nIt's important to note that different API keys are required for the Testnet and Mainnet environments. Be sure to generate separate API keys for each environment and use them accordingly.\n\n## Exemple\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\t\"os\"\n\t\"os/signal\"\n\t\"time\"\n\n\t// \"log\"\n\tBwss \"github.com/waxdred/bybit_websocket_go\"\n)\n\nfunc main() {\n\tapiKey := \"XXXXXXXXXXXXXX\"\n\tapiSecret := \"XXXXXXXXXXXXXXXX\"\n\twss := new(Bwss.WssBybit).New(true)\n\t// close all connection open\n\tdefer wss.Close()\n\n\twss.AddConnPrivate(wss.WssUrl.Private(Bwss.Testnet), apiKey, apiSecret).\n\t\tAddPrivateSubs([]string{\"wallet\", \"position\"},\n\t\t\tfunc(wss *Bwss.WssBybit, sockk *Bwss.SocketMessage) {\n\t\t\t\t// handler function\n\t\t\t\twallet := Bwss.Wallet{}\n\t\t\t\tsockk.Unmarshal(\u0026wallet)\n\t\t\t\tlog.Println(wallet.PrettyFormat())\n\t\t\t},\n\t\t\tfunc(wss *Bwss.WssBybit, sockk *Bwss.SocketMessage) {\n\t\t\t\tfmt.Println(\"handle postion start\")\n\t\t\t\tposition := Bwss.Position{}\n\t\t\t\tsockk.Unmarshal(\u0026position)\n\t\t\t\tlog.Println(position.PrettyFormat())\n\t\t\t}).Listen()\n            \n\tid, _ := wss.AddConnPublic(wss.WssUrl.Perpetual(Bwss.Mainnet)).\n\t\tAddPublicSubs([]string{\"orderbook.1.BTCUSDT\"},\n\t\t\tfunc(wss *Bwss.WssBybit, sockk *Bwss.SocketMessage) {\n\t\t\t\tfmt.Println(string(sockk.Msg))\n\t\t\t}).Listen()\n\ttime.Sleep(time.Duration(time.Second * 10))\n\twss.CloseConn(id)\n\tstop := make(chan os.Signal, 1)\n\tsignal.Notify(stop, os.Interrupt)\n\t\u003c-stop\n}\n```\n\nFor more examples and detailed usage instructions, please see the GoDoc [documentation](https://pkg.go.dev/github.com/waxdred/bybit_websocket_go?utm_source=godoc).\n\n## Contributing\nIf you find a bug or would like to contribute to this library, please open an issue or pull request on the GitHub repository.\n\n## License\nThis library is licensed under the MIT License. See the LICENSE file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwaxdred%2Fbybit_websocket_go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwaxdred%2Fbybit_websocket_go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwaxdred%2Fbybit_websocket_go/lists"}