{"id":17725669,"url":"https://github.com/hirokisan/bybit","last_synced_at":"2025-04-13T00:46:57.914Z","repository":{"id":38386487,"uuid":"344978398","full_name":"hirokisan/bybit","owner":"hirokisan","description":"Bybit client library for Go","archived":false,"fork":false,"pushed_at":"2025-02-10T03:34:29.000Z","size":753,"stargazers_count":125,"open_issues_count":6,"forks_count":76,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-13T00:46:43.715Z","etag":null,"topics":["bybit-api","bybit-api-client","bybit-go","bybit-websocket","github","go","golang","trading"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/hirokisan/bybit/v2","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/hirokisan.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},"funding":{"github":"hirokisan","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2021-03-06T01:33:13.000Z","updated_at":"2025-04-10T10:50:10.000Z","dependencies_parsed_at":"2023-10-05T06:25:13.055Z","dependency_job_id":"165f247a-79e3-4bd9-b3df-21a1048aadc1","html_url":"https://github.com/hirokisan/bybit","commit_stats":{"total_commits":382,"total_committers":27,"mean_commits":"14.148148148148149","dds":"0.16753926701570676","last_synced_commit":"f7be9d96cc7c40c6d28843306d3fde1cf698a3c0"},"previous_names":[],"tags_count":59,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hirokisan%2Fbybit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hirokisan%2Fbybit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hirokisan%2Fbybit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hirokisan%2Fbybit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hirokisan","download_url":"https://codeload.github.com/hirokisan/bybit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248650434,"owners_count":21139672,"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-api","bybit-api-client","bybit-go","bybit-websocket","github","go","golang","trading"],"created_at":"2024-10-25T16:05:16.422Z","updated_at":"2025-04-13T00:46:57.895Z","avatar_url":"https://github.com/hirokisan.png","language":"Go","readme":"[![Go Report Card](https://goreportcard.com/badge/github.com/hirokisan/bybit)](https://goreportcard.com/report/github.com/hirokisan/bybit)\n[![golangci-lint](https://github.com/hirokisan/bybit/actions/workflows/golangci-lint.yml/badge.svg)](https://github.com/hirokisan/bybit/actions/workflows/golangci-lint.yml)\n[![test](https://github.com/hirokisan/bybit/actions/workflows/test.yml/badge.svg)](https://github.com/hirokisan/bybit/actions/workflows/test.yml)\n\n# bybit\n\nbybit is a bybit client for the Go programming language.\n\n## Usage\n\n### REST API\n\n```golang\nimport \"github.com/hirokisan/bybit/v2\"\n\nclient := bybit.NewClient().WithAuth(\"your api key\", \"your api secret\")\nres, err := client.Future().InversePerpetual().Balance(bybit.CoinBTC)\n// do as you want\n```\n\n### WebSocket API\n\nfor single use\n```golang\nimport \"github.com/hirokisan/bybit/v2\"\n\nwsClient := bybit.NewWebsocketClient()\nsvc, err := wsClient.Spot().V1().PublicV1()\nif err != nil {\n\treturn err\n}\n_, err = svc.SubscribeTrade(bybit.SymbolSpotBTCUSDT, func(response bybit.SpotWebsocketV1PublicV1TradeResponse) error {\n\t// do as you want\n})\nif err != nil {\n\treturn err\n}\nsvc.Start(context.Background())\n```\n\nfor multiple use\n```golang\nimport \"github.com/hirokisan/bybit/v2\"\n\nwsClient := bybit.NewWebsocketClient()\n\nexecutors := []bybit.WebsocketExecutor{}\n\nsvcRoot := wsClient.Spot().V1()\n{\n\tsvc, err := svcRoot.PublicV1()\n\tif err != nil {\n\t\treturn err\n\t}\n\t_, err = svc.SubscribeTrade(bybit.SymbolSpotBTCUSDT, func(response bybit.SpotWebsocketV1PublicV1TradeResponse) error {\n\t\t// do as you want\n\t})\n\tif err != nil {\n\t\treturn err\n\t}\n\texecutors = append(executors, svc)\n}\n{\n\tsvc, err := svcRoot.PublicV2()\n\tif err != nil {\n\t\treturn err\n\t}\n\t_, err = svc.SubscribeTrade(bybit.SymbolSpotBTCUSDT, func(response bybit.SpotWebsocketV1PublicV2TradeResponse) error {\n\t\t// do as you want\n\t})\n\tif err != nil {\n\t\treturn err\n\t}\n\texecutors = append(executors, svc)\n}\n\nwsClient.Start(context.Background(), executors)\n```\n\nV5 usage\n```golang\nimport \"github.com/hirokisan/bybit/v2\"\n\nwsClient := bybit.NewWebsocketClient().WithBaseURL(\"wss://stream-testnet.bybit.com\").WithAuth(\"key\", \"secret\")\nsvc, err := wsClient.V5().Private()\nif err != nil {\n\t// handle dialing error\n}\n\nerr = svc.Subscribe()\nif err != nil {\n\t// handle subscription error\n}\n\nerr = svc.SubscribePosition(func(position bybit.V5WebsocketPrivatePositionResponse) error {\n\t// handle new position information\n})\nif err != nil {\n\t// handle registration error\n}\n\nerrHandler := func(isWebsocketClosed bool, err error) {\n\t// Connection issue (timeout, etc.).\n\n\t// At this point, the connection is dead and you must handle the reconnection yourself\n}\n\nerr = svc.Start(context.Background(), errHandler)\nif err != nil {\n\t// handle reconnection (ping issue, etc.). Probably can be ignored as the errHandler would be notified too\n}\n```\n\n## Implemented\n\nThe following API endpoints have been implemented\n\n### REST API V5\n\n#### Market\n\n- [`/v5/market/kline` Get Kline](https://bybit-exchange.github.io/docs/v5/market/kline)\n- [`/v5/market/mark-price-kline` Get Mark Price Kline](https://bybit-exchange.github.io/docs/v5/market/mark-kline)\n- [`/v5/market/index-price-kline` Get Index Price Kline](https://bybit-exchange.github.io/docs/v5/market/index-kline)\n- [`/v5/market/premium-index-price-kline` Get Premium Index Price Kline](https://bybit-exchange.github.io/docs/v5/market/preimum-index-kline)\n- [`/v5/market/instruments-info` Get Instruments Info](https://bybit-exchange.github.io/docs/v5/market/instrument)\n- [`/v5/market/orderbook` Get Orderbook](https://bybit-exchange.github.io/docs/v5/market/orderbook)\n- [`/v5/market/tickers` Get Tickers](https://bybit-exchange.github.io/docs/v5/market/tickers)\n- [`/v5/market/funding/history` Get Funding Rate History](https://bybit-exchange.github.io/docs/v5/market/history-fund-rate)\n- [`/v5/market/recent-trade` Get Public Trading History](https://bybit-exchange.github.io/docs/v5/market/recent-trade)\n- [`/v5/market/open-interest` Get Open Interest](https://bybit-exchange.github.io/docs/v5/market/open-interest)\n- [`/v5/market/historical-volatility` Get Historical Volatility](https://bybit-exchange.github.io/docs/v5/market/iv)\n- [`/v5/market/insurance` Get Insurance](https://bybit-exchange.github.io/docs/v5/market/insurance)\n- [`/v5/market/risk-limit` Get Risk Limit](https://bybit-exchange.github.io/docs/v5/market/risk-limit)\n\n#### Position\n\n- [`/v5/position/list` Get Position Info](https://bybit-exchange.github.io/docs/v5/position)\n- [`/v5/position/set-leverage` Set Leverage](https://bybit-exchange.github.io/docs/v5/position/leverage)\n- [`/v5/position/switch-isolated` Switch Cross/Isolated Margin](https://bybit-exchange.github.io/docs/v5/position/cross-isolate)\n- [`/v5/position/trading-stop` Set Trading Stop](https://bybit-exchange.github.io/docs/v5/position/trading-stop)\n- [`/v5/position/switch-mode` Switch Position Mode](https://bybit-exchange.github.io/docs/v5/position/position-mode)\n- [`/v5/position/set-tpsl-mode` Set TP/SL Mode](https://bybit-exchange.github.io/docs/v5/position/tpsl-mode)\n- [`/v5/position/closed-pnl` Get Closed PnL](https://bybit-exchange.github.io/docs/v5/position/close-pnl)\n- [`/v5/position/set-risk-limit` Set Risk Limit](https://bybit-exchange.github.io/docs/v5/position/set-risk-limit)\n- [`/v5/execution/list` Get Execution](https://bybit-exchange.github.io/docs/v5/position/execution)\n\n#### Order\n\n- [`/v5/order/create` Place Order](https://bybit-exchange.github.io/docs/v5/order/create-order)\n- [`/v5/order/amend` Amend Order](https://bybit-exchange.github.io/docs/v5/order/amend-order)\n- [`/v5/order/cancel` Cancel Order](https://bybit-exchange.github.io/docs/v5/order/cancel-order)\n- [`/v5/order/realtime` Get Open Orders](https://bybit-exchange.github.io/docs/v5/order/open-order)\n- [`/v5/order/cancel-all` Cancel All Orders](https://bybit-exchange.github.io/docs/v5/order/cancel-all)\n- [`/v5/order/history` Get Order History](https://bybit-exchange.github.io/docs/v5/order/order-list)\n\n#### Account\n\n- [`/v5/account/wallet-balance` Get Wallet Balance](https://bybit-exchange.github.io/docs/v5/account/wallet-balance)\n- [`/v5/account/account-info` Get Account Info](https://bybit-exchange.github.io/docs/v5/account/account-info)\n- [`/v5/account/transaction-log` Get Transaction Log](https://bybit-exchange.github.io/docs/v5/account/transaction-log)\n- [`/v5/account/collateral-info` Get Collateral Info](https://bybit-exchange.github.io/docs/v5/account/collateral-info)\n- [`/v5/account/set-collateral-switch` Set Collateral Coin](https://bybit-exchange.github.io/docs/v5/account/set-collateral)\n- [`/v5/account/batch-set-collateral` Batch Set Collateral Coin](https://bybit-exchange.github.io/docs/v5/account/batch-set-collateral)\n- [`/v5/account/fee-rate` Get Fee Rate](https://bybit-exchange.github.io/docs/v5/account/fee-rate)\n\n#### Asset\n\n- [`/v5/asset/transfer/inter-transfer` Create Internal Transfer](https://bybit-exchange.github.io/docs/v5/asset/create-inter-transfer)\n- [`/v5/asset/transfer/query-inter-transfer-list` Get Internal Transfer Records](https://bybit-exchange.github.io/docs/v5/asset/inter-transfer-list)\n- [`/v5/asset/transfer/query-account-coins-balance` Get All Coins Balance](https://bybit-exchange.github.io/docs/v5/asset/all-balance)\n- [`/v5/asset/deposit/query-record` Get Deposit Records](https://bybit-exchange.github.io/docs/v5/asset/deposit-record)\n- [`/v5/asset/deposit/query-sub-member-record` Get Sub Deposit Records](https://bybit-exchange.github.io/docs/v5/asset/sub-deposit-record)\n- [`/v5/asset/deposit/query-internal-record` Get Internal Deposit Records](https://bybit-exchange.github.io/docs/v5/asset/internal-deposit-record)\n- [`/v5/asset/deposit/query-address` Get Master Deposit Address](https://bybit-exchange.github.io/docs/v5/asset/master-deposit-addr)\n- [`/v5/asset/withdraw/query-record` Get Withdrawal Records](https://bybit-exchange.github.io/docs/v5/asset/withdraw-record)\n- [`/v5/asset/coin/query-info` Get Coin Info](https://bybit-exchange.github.io/docs/v5/asset/coin-info)\n- [`/v5/asset/withdraw/create` Withdraw](https://bybit-exchange.github.io/docs/v5/asset/withdraw)\n- [`/v5/asset/transfer/universal-transfer` Create Universal Transfer](https://bybit-exchange.github.io/docs/v5/asset/unitransfer)\n- [`/v5/asset/transfer/query-universal-transfer-list` Get Universal Transfer Records](https://bybit-exchange.github.io/docs/v5/asset/unitransfer-list)\n\n#### User\n\n- [`/v5/user/query-api` Get API Key Information](https://bybit-exchange.github.io/docs/v5/user/apikey-info)\n\n\n### [deprecated] REST API\n\n#### [Derivatives Unified Margin](https://bybit-exchange.github.io/docs/derivativesV3/unified_margin)\n\n##### Market Data Endpoints\n\n- `/derivatives/v3/public/order-book/L2` Get Order Book\n- `/derivatives/v3/public/kline` Get Kline\n- `/derivatives/v3/public/tickers` Get Latest Information For Symbol\n- `/derivatives/v3/public/instruments-info` Get Instrument Info\n- `/derivatives/v3/public/mark-price-kline` Get Mark Price Kline\n- `/derivatives/v3/public/index-price-kline` Get Index Price Kline\n\n#### [Derivatives Contract](https://bybit-exchange.github.io/docs/derivativesV3/contract)\n\n##### Market Data Endpoints\n\n- `/derivatives/v3/public/order-book/L2` Get Order Book\n- `/derivatives/v3/public/kline` Get Kline\n- `/derivatives/v3/public/tickers` Get Latest Information For Symbol\n- `/derivatives/v3/public/instruments-info` Get Instrument Info\n- `/derivatives/v3/public/mark-price-kline` Get Mark Price Kline\n- `/derivatives/v3/public/index-price-kline` Get Index Price Kline\n\n#### [Inverse Perpetual](https://bybit-exchange.github.io/docs/futuresV2/inverse)\n\n##### Market Data Endpoints\n\n- `/v2/public/orderBook/L2` Order Book\n- `/v2/public/kline/list` Query Kline\n- `/v2/public/tickers` Latest Information for Symbol\n- `/v2/public/trading-records` Public Trading Records\n- `/v2/public/symbols` Query Symbol\n- `/v2/public/mark-price-kline` Query Mark Price Kline\n- `/v2/public/index-price-kline` Query Index Price Kline\n- `/v2/public/premium-index-kline` Query Premium Index Kline\n- `/v2/public/open-interest` Open Interest\n- `/v2/public/big-deal` Latest Big Deal\n- `/v2/public/account-ratio` Long-Short Ratio\n\n##### Account Data Endpoints\n\n- `/v2/private/order/create` Place Active Order\n- `/v2/private/order/list` Get Active Order\n- `/v2/private/order/cancel` Cancel Active Order\n- `/v2/private/order/cancelAll` Cancel All Active Orders\n- `/v2/private/order` Query Active Order (real-time)\n- `/v2/private/stop-order/create` Place Conditional Order\n- `/v2/private/stop-order/list` Get Conditional Order\n- `/v2/private/stop-order/cancel` Cancel Conditional Order\n- `/v2/private/stop-order/cancelAll` Cancel All Conditional Orders\n- `/v2/private/stop-order` Query Conditional Order (real-time)\n- `/v2/private/position/list` My Position\n- `/v2/private/position/trading-stop` Set Trading-Stop\n- `/v2/private/position/leverage/save` Set Leverage\n- `/v2/private/account/api-key` API Key info\n\n##### Wallet Data Endpoints\n\n- `/v2/private/wallet/balance` Get Wallet Balance\n\n#### [USDT Perpetual](https://bybit-exchange.github.io/docs/futuresV2/linear)\n\n##### Market Data Endpoints\n\n- `/v2/public/orderBook/L2` Order Book\n- `/public/linear/kline` Query Kline\n- `/v2/public/tickers` Latest Information for Symbol\n- `/v2/public/symbols` Query Symbol\n- `/v2/public/open-interest` Open Interest\n- `/v2/public/big-deal` Latest Big Deal\n- `/v2/public/account-ratio` Long-Short Ratio\n\n##### Account Data Endpoints\n\n- `/private/linear/order/create` Place Active Order\n- `/private/linear/order/list` Get Active Order\n- `/private/linear/order/cancel` Cancel Active Order\n- `/private/linear/order/cancel-all` Cancel All Active Orders\n- `/private/linear/order/replace` Replace Active Order\n- `/private/linear/order/search` Query Active Order (real-time)\n- `/private/linear/stop-order/create` Place Conditional Order\n- `/private/linear/stop-order/list` Get Conditional Order\n- `/private/linear/stop-order/cancel` Cancel Conditional Order\n- `/private/linear/stop-order/cancel-all` Cancel All Conditional Orders\n- `/private/linear/stop-order/search` Query Conditional Order (real-time)\n- `/private/linear/position/list` My Position\n- `/private/linear/position/set-leverage` Set Leverage\n- `/private/linear/position/trading-stop` Set Trading-Stop\n- `/private/linear/trade/execution/list` User Trade Records\n- `/v2/private/account/api-key` API Key info\n\n##### Wallet Data Endpoints\n\n- `/v2/private/wallet/balance` Get Wallet Balance\n\n#### [Inverse Future](https://bybit-exchange.github.io/docs/futuresV2/inverse_futures)\n\n##### Market Data Endpoints\n\n- `/v2/public/orderBook/L2` Order Book\n- `/v2/public/kline/list` Query Kline\n- `/v2/public/tickers` Latest Information for Symbol\n- `/v2/public/trading-records` Public Trading Records\n- `/v2/public/symbols` Query Symbol\n- `/v2/public/mark-price-kline` Query Index Price Kline\n- `/v2/public/index-price-kline` Query Index Price Kline\n- `/v2/public/open-interest` Open Interest\n- `/v2/public/big-deal` Latest Big Deal\n- `/v2/public/account-ratio` Long-Short Ratio\n\n##### Account Data Endpoints\n\n- `/futures/private/order/create` Place Active Order\n- `/futures/private/order/list` Get Active Order\n- `/futures/private/order/cancel` Cancel Active Order\n- `/futures/private/order/cancelAll` Cancel All Active Orders\n- `/futures/private/order` Query Active Order (real-time)\n- `/futures/private/stop-order/create` Place Conditional Order\n- `/futures/private/stop-order/list` Get Conditional Order\n- `/futures/private/stop-order/cancel` Cancel Conditional Order\n- `/futures/private/stop-order/cancelAll` Cancel All Conditional Orders\n- `/futures/private/stop-order` Query Conditional Order (real-time)\n- `/futures/private/position/list` My Position\n- `/futures/private/position/trading-stop` Set Trading-Stop\n- `/futures/private/position/leverage/save` Set Leverage\n- `/v2/private/account/api-key` API Key info\n\n##### Wallet Data Endpoints\n\n- `/v2/private/wallet/balance` Get Wallet Balance\n\n#### [Spot v1](https://bybit-exchange.github.io/docs/spot/v1)\n\n##### Market Data Endpoints\n\n- `/spot/v1/symbols` Query Symbol\n- `/spot/quote/v1/depth` Order Book\n- `/spot/quote/v1/depth/merged` Merged Order Book\n- `/spot/quote/v1/trades` Public Trading Records\n- `/spot/quote/v1/kline` Query Kline\n- `/spot/quote/v1/ticker/24hr` Latest Information for Symbol\n- `/spot/quote/v1/ticker/price` Last Traded Price\n- `/spot/quote/v1/ticker/book_ticker` Best Bid/Ask Price\n\n##### Account Data Endpoints\n\n- `/spot/v1/order`\n  - Place Active Order\n  - Get Active Order\n  - Cancel Active Order\n  - Fast Cancel Active Order\n- `/spot/v1/order/fast` Fast Cancel Active Order\n- `/spot/order/batch-cancel` Batch Cancel Active Order\n- `/spot/order/batch-fast-cancel` Batch Fast Cancel Active Order\n- `/spot/order/batch-cancel-by-ids` Batch Cancel Active Order By IDs\n- `/spot/v1/open-orders` Open Orders\n\n##### Wallet Data Endpoints\n\n- `/spot/v1/account` Get Wallet Balance\n\n### WebSocket API\n\n#### Public Topics V5\n\n- [Orderbook](https://bybit-exchange.github.io/docs/v5/websocket/public/orderbook)\n- [Kline](https://bybit-exchange.github.io/docs/v5/websocket/public/kline)\n- [Ticker](https://bybit-exchange.github.io/docs/v5/websocket/public/ticker)\n- [Trade](https://bybit-exchange.github.io/docs/v5/websocket/public/trade)\n- [Liquidation](https://bybit-exchange.github.io/docs/v5/websocket/public/liquidation)\n\n#### Private Topics V5\n\n- [Position](https://bybit-exchange.github.io/docs/v5/websocket/private/position)\n- [Order](https://bybit-exchange.github.io/docs/v5/websocket/private/order)\n- [Wallet](https://bybit-exchange.github.io/docs/v5/websocket/private/wallet)\n- [Execution](https://bybit-exchange.github.io/docs/v5/websocket/private/execution)\n\n#### [Trade V5](https://bybit-exchange.github.io/docs/v5/websocket/trade/guideline)\n\n- Create\n- Cancel\n\n#### [deprecated] [Spot v1](https://bybit-exchange.github.io/docs/spot/v1/#t-websocket)\n\n##### Public Topics\n\n- trade\n\n##### Public Topics V2\n\n- trade\n\n##### Private Topics\n\n- outboundAccountInfo\n\n## Integration Tests\n\nThere are tests so that we can get to know the changes of bybit api response.\n\nSee below\n\n- [REST API Integration Test](./integrationtest/README.md)\n- [Websocket API Integration Test](./integrationtest-ws/README.md)\n\n## Contributing\n\nI would like to cover Bybit API and contributions are always welcome. The calling pattern is established, so adding new methods is relatively straightforward. See some PRs like https://github.com/hirokisan/bybit/pull/44.\n\nTo submit issues, PRs, and every other help is welcome.\n","funding_links":["https://github.com/sponsors/hirokisan"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhirokisan%2Fbybit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhirokisan%2Fbybit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhirokisan%2Fbybit/lists"}