{"id":16965211,"url":"https://github.com/qct/bitmex-go","last_synced_at":"2025-03-22T14:31:04.505Z","repository":{"id":57484770,"uuid":"100833992","full_name":"qct/bitmex-go","owner":"qct","description":"golang restful SDK for BITMEX","archived":false,"fork":false,"pushed_at":"2023-10-11T23:29:50.000Z","size":15541,"stargazers_count":37,"open_issues_count":2,"forks_count":14,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-18T11:52:02.006Z","etag":null,"topics":["bitmex","cryptocoins","cryptocurrency","exchange","golang","rest-api","restful"],"latest_commit_sha":null,"homepage":"","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/qct.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":"2017-08-20T02:45:36.000Z","updated_at":"2024-09-28T19:49:42.000Z","dependencies_parsed_at":"2024-06-18T21:39:45.454Z","dependency_job_id":null,"html_url":"https://github.com/qct/bitmex-go","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qct%2Fbitmex-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qct%2Fbitmex-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qct%2Fbitmex-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qct%2Fbitmex-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/qct","download_url":"https://codeload.github.com/qct/bitmex-go/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244971788,"owners_count":20540857,"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":["bitmex","cryptocoins","cryptocurrency","exchange","golang","rest-api","restful"],"created_at":"2024-10-13T23:45:22.179Z","updated_at":"2025-03-22T14:31:02.008Z","avatar_url":"https://github.com/qct.png","language":"Go","readme":"# Golang SDK for [bitmex](https://www.bitmex.com)\n\ninspired by [https://github.com/BitMEX/api-connectors](https://github.com/BitMEX/api-connectors), [https://www.bitmex.com/api/explorer](https://www.bitmex.com/api/explorer) and [https://github.com/jxc6698/bitcoin-exchange-api](https://github.com/jxc6698/bitcoin-exchange-api)\n\nall structs and APIs are from the bitmex official api connectors, based on that, add authentication and fix bugs.\n\n## Why\nthe generated connectors by bitmex have too many mistakes to use, this SDK fix these bugs to ensure bitmex API can get right results.\n\n## Installation\n`go get github.com/qct/bitmex-go`\n\n## Examples\n1. Get order book\n```\napiClient = swagger.NewAPIClient(swagger.NewConfiguration())\norderBookApi := restful.NewOrderBookApi(apiClient.OrderBookApi)\norderBooks, err := orderBookApi.OrderBookGetL2(\"XBTUSD\", 5)\nif err != nil {\n    log.Println(\"error wihle get orderbook: \", err)\n}\nfor _, v := range orderBooks.AskList {\n    log.Printf(\"%+v\\n\", v)\n}\nfor _, v := range orderBooks.BidList {\n    log.Printf(\"%+v\\n\", v)\n}\n```\n\n2. Get your position\n```\napiClient = swagger.NewAPIClient(swagger.NewConfiguration())\nauth      = context.WithValue(context.TODO(), swagger.ContextAPIKey, swagger.APIKey{\n        Key:    apiKey,\n        Secret: secretKey,\n    })\n\npositionApi := apiClient.PositionApi\nparams := map[string]interface{}{\n    \"filter\":  \"{\\\"symbol\\\": \\\"XBTUSD\\\"}\",\n    \"columns\": \"\",\n    \"count\":   float32(10),\n}\npositions, response, err := positionApi.PositionGet(auth, params)\nif err != nil {\n    log.Println(\"error: \", err)\n}\nlog.Println(response.Status)\nlog.Printf(\"%+v\\n\", positions)\n```\n\n3. Get your wallet\n```\napiClient = swagger.NewAPIClient(swagger.NewConfiguration())\nauth      = context.WithValue(context.TODO(), swagger.ContextAPIKey, swagger.APIKey{\n        Key:    apiKey,\n        Secret: secretKey,\n    })\n\nuserApi := apiClient.UserApi\nparams := map[string]interface{}{\n    \"currency\": \"\",\n}\nwallet, response, err := userApi.UserGetWallet(auth, params)\nif err != nil {\n    log.Println(\"error: \", err)\n}\nlog.Println(response.Status)\nlog.Printf(\"wallet: %+v\\n\", wallet)\n```\n\n4. Get margin info\n```\napiClient = swagger.NewAPIClient(swagger.NewConfiguration())\nauth      = context.WithValue(context.TODO(), swagger.ContextAPIKey, swagger.APIKey{\n        Key:    apiKey,\n        Secret: secretKey,\n    })\n\nuserApi := apiClient.UserApi\nmargin, response, err := userApi.UserGetMargin(auth, nil)\nif err != nil {\n    log.Println(\"error: \", err)\n}\nlog.Println(response.Status)\nlog.Printf(\"margin: %+v\\n\", margin)\n```\n\n5. Buy \u0026 Sell\n```\napiClient = swagger.NewAPIClient(swagger.NewConfiguration())\nauth      = context.WithValue(context.TODO(), swagger.ContextAPIKey, swagger.APIKey{\n        Key:    apiKey,\n        Secret: secretKey,\n    })\n\n// buy\norderApi := restful.NewOrderApi(apiClient.OrderApi, auth)\nresp, orderId, err := orderApi.LimitBuy(\"XBTUSD\", 1.0, 13000, \"qct_f_f_\")\nif err != nil {\n    log.Println(\"error: \", err)\n}\nlog.Printf(\"response: %s, orderId: %s\\n\", resp.Status, orderId)\n\n// sell\nresp, orderId, err := orderApi.LimitSell(\"XBTUSD\", 1.0, 20000, \"qct_f_f_\")\nif err != nil {\n    log.Println(\"error: \", err)\n}\nlog.Printf(\"result: %s, orderId: %s\\n\", resp.Status, orderId)\n```\n\n6. Get your order\n```\napiClient = swagger.NewAPIClient(swagger.NewConfiguration())\nauth      = context.WithValue(context.TODO(), swagger.ContextAPIKey, swagger.APIKey{\n        Key:    apiKey,\n        Secret: secretKey,\n    })\n\norderApi := apiClient.OrderApi\nparams := map[string]interface{}{\n    \"symbol\":    \"XBTUSD\",\n    \"filter\":    \"\",\n    \"columns\":   \"\",\n    \"count\":     float32(5),\n    \"start\":     nil,\n    \"reverse\":   true,\n    \"startTime\": nil,\n    \"endTime\":   nil,\n}\norders, response, err := orderApi.OrderGetOrders(auth, params)\nif err != nil {\n    log.Println(\"error: \", err)\n}\nlog.Println(response.Status)\nlog.Printf(\"orders: %+v\\n\", orders)\n```\n\n7. Even chat through RESTFul api\n```\napiClient = swagger.NewAPIClient(swagger.NewConfiguration())\nauth      = context.WithValue(context.TODO(), swagger.ContextAPIKey, swagger.APIKey{\n        Key:    apiKey,\n        Secret: secretKey,\n    })\n\nchatApi := apiClient.ChatApi\nparams := map[string]interface{}{\n    \"channelID\": 2.0,\n}\nchat, response, err := chatApi.ChatNew(auth, \"hello\", params)\nif err != nil {\n    log.Println(\"error: \", err)\n}\nlog.Println(response.Status)\nlog.Printf(\"%+v\\n\", chat)\n```\n\n## Roadmap\n* I only tested some API I will use, in the near future, I will keep adding and fixing to make more API available.\n* make a PR to bitmex api collectors to generate a ready to use golang client.\n\n\n## Changelog\n1.swagger.json, in definitions:\n```\n\"OrderBookL2\": {\n      \"properties\": {\n        \"id\": { \"type\": \"number\", \"format\": \"int64\" },\n        \"symbol\": { \"type\": \"string\" },\n        \"side\": { \"type\": \"string\" },\n        \"size\": { \"type\": \"number\", \"format\": \"int64\" },\n        \"price\": { \"format\": \"double\", \"type\": \"number\" }\n      },\n      \"required\": [\"id\", \"symbol\", \"side\"],\n      \"type\": \"object\"\n    },\n```\n\n2.api_order.go, cancel multi orders\n```go\nif localVarOptionals != nil \u0026\u0026 localVarOptionals.OrderID.IsSet() {\n    //localVarFormParams.Add(\"orderID\", parameterToString(localVarOptionals.OrderID.Value(), \"\"))\n    ids := strings.Split(localVarOptionals.OrderID.Value(), \",\")\n    for _, id := range ids {\n        localVarFormParams.Add(\"orderID\", id)\n    }\n}\nif localVarOptionals != nil \u0026\u0026 localVarOptionals.ClOrdID.IsSet() {\n    //localVarFormParams.Add(\"clOrdID\", parameterToString(localVarOptionals.ClOrdID.Value(), \"\"))\n    ids := strings.Split(localVarOptionals.ClOrdID.Value(), \",\")\n    for _, id := range ids {\n        localVarFormParams.Add(\"clOrdID\", id)\n    }\n}\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqct%2Fbitmex-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqct%2Fbitmex-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqct%2Fbitmex-go/lists"}