{"id":23140844,"url":"https://github.com/f0cii/bybit-api","last_synced_at":"2025-08-17T13:31:32.108Z","repository":{"id":41281215,"uuid":"198441151","full_name":"f0cii/bybit-api","owner":"f0cii","description":"Go library for using the Bybit's Rest \u0026 Websocket API","archived":false,"fork":false,"pushed_at":"2022-02-06T02:47:58.000Z","size":163,"stargazers_count":49,"open_issues_count":5,"forks_count":37,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-08-14T07:58:32.569Z","etag":null,"topics":["bybit","bybit-api","bybit-rest","golang","websocket-api"],"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/f0cii.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":"2019-07-23T13:54:10.000Z","updated_at":"2025-06-10T08:11:51.000Z","dependencies_parsed_at":"2022-07-06T11:04:18.883Z","dependency_job_id":null,"html_url":"https://github.com/f0cii/bybit-api","commit_stats":null,"previous_names":["sumorf/bybit-api","f0cii/bybit-api","frankrap/bybit-api"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/f0cii/bybit-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f0cii%2Fbybit-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f0cii%2Fbybit-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f0cii%2Fbybit-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f0cii%2Fbybit-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/f0cii","download_url":"https://codeload.github.com/f0cii/bybit-api/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f0cii%2Fbybit-api/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270438630,"owners_count":24583660,"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","status":"online","status_checked_at":"2025-08-14T02:00:10.309Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-api","bybit-rest","golang","websocket-api"],"created_at":"2024-12-17T14:11:49.733Z","updated_at":"2025-08-17T13:31:31.815Z","avatar_url":"https://github.com/f0cii.png","language":"Go","readme":"# bybit-api\nGo library for using the ByBit's Rest \u0026amp; Websocket API\n\n[API Doc](https://bybit-exchange.github.io/docs/inverse/#t-introduction)\n\n### Example\n\n### Rest api\n```\npackage main\n\nimport (\n\t\"github.com/frankrap/bybit-api/rest\"\n\t\"log\"\n)\n\nfunc main() {\n\t//baseURL := \"https://api.bybit.com/\"\t// 主网络\n\tbaseURL := \"https://api-testnet.bybit.com/\" // 测试网络\n\tb := rest.New(nil, baseURL, \"YIxOY2RhFkylPudq96\", \"Bg9G2oFOb3aaIMguD3FOvOJJVBycaoXqXNcI\")\n\n\t// 获取持仓\n\tpositions, err := b.GetPositions()\n\tif err != nil {\n\t\tlog.Printf(\"%v\", err)\n\t\treturn\n\t}\n\n\tlog.Printf(\"positions: %#v\", positions)\n\n\t// 创建委托\n\tsymbol := \"BTCUSD\"\n\tside := \"Buy\"\n\torderType := \"Limit\"\n\tqty := 30\n\tprice := 7000.0\n\ttimeInForce := \"GoodTillCancel\"\n\treduceOnly := false\n\torder, err := b.CreateOrder(side, orderType, price, qty, timeInForce, reduceOnly, symbol)\n\tif err != nil {\n\t\tlog.Println(err)\n\t\treturn\n\t}\n\tlog.Printf(\"Create order: %#v\", order)\n\n\t// 获取委托单\n}\n```\n\n### Websocket\n```\npackage main\n\nimport (\n\t\"github.com/frankrap/bybit-api/ws\"\n\t\"log\"\n)\n\nfunc main() {\n\tcfg := \u0026ws.Configuration{\n\t\tAddr:          ws.HostTestnet, // 测试网络\n\t\tApiKey:        \"wKuYtkeNdC2PaMKjoy\",\n\t\tSecretKey:     \"5ekcDn3KnKoCRbfvrPImYzVdx7Ri2hhVxkmw\",\n\t\tAutoReconnect: true, // 断线自动重连\n\t\tDebugMode:     true,\n\t}\n\tb := ws.New(cfg)\n\n\t// 订阅新版25档orderBook\n\tb.Subscribe(ws.WSOrderBook25L1 + \".BTCUSD\")\n\t// 实时交易\n\t//b.Subscribe(\"trade.BTCUSD\")\n\tb.Subscribe(ws.WSTrade) // BTCUSD/ETHUSD/EOSUSD/XRPUSD\n\t// K线\n\tb.Subscribe(ws.WSKLine + \".BTCUSD.1m\")\n\t// 每日保险基金更新\n\tb.Subscribe(ws.WSInsurance)\n\t// 产品最新行情\n\tb.Subscribe(ws.WSInstrument + \".BTCUSD\")\n\n\t// 仓位变化\n\tb.Subscribe(ws.WSPosition)\n\t// 委托单成交信息\n\tb.Subscribe(ws.WSExecution)\n\t// 委托单的更新\n\tb.Subscribe(ws.WSOrder)\n\n\tb.On(ws.WSOrderBook25L1, handleOrderBook)\n\tb.On(ws.WSTrade, handleTrade)\n\tb.On(ws.WSKLine, handleKLine)\n\tb.On(ws.WSInsurance, handleInsurance)\n\tb.On(ws.WSInstrument, handleInstrument)\n\n\tb.On(ws.WSPosition, handlePosition)\n\tb.On(ws.WSExecution, handleExecution)\n\tb.On(ws.WSOrder, handleOrder)\n\n\tb.Start()\n\n\tforever := make(chan struct{})\n\t\u003c-forever\n}\n\nfunc handleOrderBook(symbol string, data ws.OrderBook) {\n\tlog.Printf(\"handleOrderBook %v/%v\", symbol, data)\n}\n\nfunc handleTrade(symbol string, data []*ws.Trade) {\n\tlog.Printf(\"handleTrade %v/%v\", symbol, data)\n}\n\nfunc handleKLine(symbol string, data ws.KLine) {\n\tlog.Printf(\"handleKLine %v/%v\", symbol, data)\n}\n\nfunc handleInsurance(currency string, data []*ws.Insurance) {\n\tlog.Printf(\"handleInsurance %v/%v\", currency, data)\n}\n\nfunc handleInstrument(symbol string, data []*ws.Instrument) {\n\tlog.Printf(\"handleInstrument %v/%v\", symbol, data)\n}\n\nfunc handlePosition(data []*ws.Position) {\n\tlog.Printf(\"handlePosition %v\", data)\n}\n\nfunc handleExecution(data []*ws.Execution) {\n\tlog.Printf(\"handleExecution %v\", data)\n}\n\nfunc handleOrder(data []*ws.Order) {\n\tlog.Printf(\"handleOrder %v\", data)\n}\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ff0cii%2Fbybit-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ff0cii%2Fbybit-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ff0cii%2Fbybit-api/lists"}