From 1da7063114224f71e3870705085376ad237a4b83 Mon Sep 17 00:00:00 2001 From: Agrim Mittal Date: Wed, 12 Jun 2024 16:39:20 +0530 Subject: [PATCH 1/6] (fix) Use custrom url when connecting to private socket (#2) --- .gitignore | 1 + README.md | 10 +++--- account.go | 2 +- asset.go | 2 +- broker.go | 2 +- bybit_api_client.go | 2 +- bybit_websocket.go | 5 ++- examples/Account/get_transaction.go | 22 ------------- examples/Asset/get_coin_info.go | 22 ------------- examples/Asset/get_transfer_coin.go | 22 ------------- examples/Trade/place_batch_trade.go | 51 ----------------------------- examples/Trade/place_order.go | 21 ------------ go.mod | 2 +- go.sum | 1 - lending.go | 2 +- market_service.go | 2 +- market_service_test.go | 2 +- position.go | 2 +- pre_upgrade.go | 2 +- spot_leverage.go | 2 +- spot_margin.go | 2 +- trade.go | 4 +-- user.go | 2 +- 23 files changed, 25 insertions(+), 160 deletions(-) create mode 100644 .gitignore delete mode 100644 examples/Account/get_transaction.go delete mode 100644 examples/Asset/get_coin_info.go delete mode 100644 examples/Asset/get_transfer_coin.go delete mode 100644 examples/Trade/place_batch_trade.go delete mode 100644 examples/Trade/place_order.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a725465 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +vendor/ \ No newline at end of file diff --git a/README.md b/README.md index 5a57d46..3125238 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # bybit-go-api -[![GO 1.21.0](https://img.shields.io/badge/Go-1.21.0-brightgreen.svg)](https://github.com/wuhewuhe/bybit-go-api) [![Contributor Victor](https://img.shields.io/badge/contributor-Victor-blue.svg)](https://github.com/wuhewuhe/bybit-go-api) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/wuhewuhe/bybit-go-api/blob/main/LICENSE) +[![GO 1.21.0](https://img.shields.io/badge/Go-1.21.0-brightgreen.svg)](https://github.com/mudrex/bybit-go-api) [![Contributor Victor](https://img.shields.io/badge/contributor-Victor-blue.svg)](https://github.com/mudrex/bybit-go-api) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/mudrex/bybit-go-api/blob/main/LICENSE) ## Table of Contents - [About](#about) - [Development](#development) @@ -41,7 +41,7 @@ require ( ``` To import my package you need just to put the link to your go mode file -**github.com/wuhewuhe/bybit.go.api** +**github.com/mudrex/bybit.go.api** ## Usage Note: Replace placeholders (like YOUR_API_KEY, links, or other details) with the actual information. You can also customize this template to better fit the actual state and details of your Java API. @@ -163,7 +163,7 @@ List of other contributors
- +
@@ -171,8 +171,8 @@ List of other contributors

- 💻 - 📖 + 💻 + 📖
\ No newline at end of file diff --git a/account.go b/account.go index ccf993c..866aae1 100644 --- a/account.go +++ b/account.go @@ -2,7 +2,7 @@ package bybit_connector import ( "context" - "github.com/wuhewuhe/bybit.go.api/handlers" + "github.com/mudrex/bybit.go.api/handlers" "net/http" ) diff --git a/asset.go b/asset.go index dc08e92..f907f9c 100644 --- a/asset.go +++ b/asset.go @@ -2,7 +2,7 @@ package bybit_connector import ( "context" - "github.com/wuhewuhe/bybit.go.api/handlers" + "github.com/mudrex/bybit.go.api/handlers" "net/http" ) diff --git a/broker.go b/broker.go index a68b1c6..30f1c68 100644 --- a/broker.go +++ b/broker.go @@ -2,7 +2,7 @@ package bybit_connector import ( "context" - "github.com/wuhewuhe/bybit.go.api/handlers" + "github.com/mudrex/bybit.go.api/handlers" "net/http" ) diff --git a/bybit_api_client.go b/bybit_api_client.go index b13a9b7..fc30ee5 100644 --- a/bybit_api_client.go +++ b/bybit_api_client.go @@ -16,7 +16,7 @@ import ( "github.com/bitly/go-simplejson" jsoniter "github.com/json-iterator/go" - "github.com/wuhewuhe/bybit.go.api/handlers" + "github.com/mudrex/bybit.go.api/handlers" ) var json = jsoniter.ConfigCompatibleWithStandardLibrary diff --git a/bybit_websocket.go b/bybit_websocket.go index 99e3dd9..78d8513 100644 --- a/bybit_websocket.go +++ b/bybit_websocket.go @@ -46,6 +46,7 @@ type WebSocket struct { onMessage MessageHandler ctx context.Context cancel context.CancelFunc + isPrivate bool } type WebsocketOption func(*WebSocket) @@ -70,6 +71,7 @@ func NewBybitPrivateWebSocket(url, apiKey, apiSecret string, handler MessageHand maxAliveTime: "", pingInterval: 20, onMessage: handler, + isPrivate: true, } // Apply the provided options @@ -152,7 +154,8 @@ func (b *WebSocket) requiresAuthentication() bool { b.url == WEBSOCKET_PRIVATE_TESTNET || b.url == V3_CONTRACT_PRIVATE || b.url == V3_UNIFIED_PRIVATE || - b.url == V3_SPOT_PRIVATE + b.url == V3_SPOT_PRIVATE || + b.isPrivate } func (b *WebSocket) sendAuth() error { diff --git a/examples/Account/get_transaction.go b/examples/Account/get_transaction.go deleted file mode 100644 index b36271c..0000000 --- a/examples/Account/get_transaction.go +++ /dev/null @@ -1,22 +0,0 @@ -package main - -import ( - "context" - "fmt" - bybit "github.com/wuhewuhe/bybit.go.api" -) - -func main() { - PlaceTrade() -} - -func PlaceTrade() { - client := bybit.NewBybitHttpClient("8wYkmpLsMg10eNQyPm", "Ouxc34myDnXvei54XsBZgoQzfGxO4bkr2Zsj", bybit.WithBaseURL(bybit.TESTNET)) - params := map[string]interface{}{"accountType": "UNIFIED", "category": "linear"} - accountResult, err := client.NewAccountService(params).GetTransactionLog(context.Background()) - if err != nil { - fmt.Println(err) - return - } - fmt.Println(bybit.PrettyPrint(accountResult)) -} diff --git a/examples/Asset/get_coin_info.go b/examples/Asset/get_coin_info.go deleted file mode 100644 index 2875c42..0000000 --- a/examples/Asset/get_coin_info.go +++ /dev/null @@ -1,22 +0,0 @@ -package main - -import ( - "context" - "fmt" - bybit "github.com/wuhewuhe/bybit.go.api" -) - -func main() { - GetCoinInfo() -} - -func GetCoinInfo() { - client := bybit.NewBybitHttpClient("8wYkmpLsMg10eNQyPm", "Ouxc34myDnXvei54XsBZgoQzfGxO4bkr2Zsj", bybit.WithBaseURL(bybit.TESTNET)) - params := map[string]interface{}{"coin": "USDT"} - assetResult, err := client.NewAssetService(params).GetCoinInfo(context.Background()) - if err != nil { - fmt.Println(err) - return - } - fmt.Println(bybit.PrettyPrint(assetResult)) -} diff --git a/examples/Asset/get_transfer_coin.go b/examples/Asset/get_transfer_coin.go deleted file mode 100644 index 2c7c5fb..0000000 --- a/examples/Asset/get_transfer_coin.go +++ /dev/null @@ -1,22 +0,0 @@ -package main - -import ( - "context" - "fmt" - bybit "github.com/wuhewuhe/bybit.go.api" -) - -func main() { - PlaceOrder() -} - -func PlaceOrder() { - client := bybit.NewBybitHttpClient("8wYkmpLsMg10eNQyPm", "Ouxc34myDnXvei54XsBZgoQzfGxO4bkr2Zsj", bybit.WithBaseURL(bybit.TESTNET)) - params := map[string]interface{}{"fromAccountType": "UNIFIED", "toAccountType": "CONTRACT"} - response, err := client.NewAssetService(params).GetTransferableCoin(context.Background()) - if err != nil { - fmt.Println(err) - return - } - fmt.Println(bybit.PrettyPrint(response)) -} diff --git a/examples/Trade/place_batch_trade.go b/examples/Trade/place_batch_trade.go deleted file mode 100644 index bae2836..0000000 --- a/examples/Trade/place_batch_trade.go +++ /dev/null @@ -1,51 +0,0 @@ -package main - -import ( - "context" - "fmt" - bybit "github.com/wuhewuhe/bybit.go.api" -) - -func main() { - PlaceBatchTrade() -} - -func PlaceBatchTrade() { - client := bybit.NewBybitHttpClient("8wYkmpLsMg10eNQyPm", "Ouxc34myDnXvei54XsBZgoQzfGxO4bkr2Zsj", bybit.WithBaseURL(bybit.TESTNET)) - params := map[string]interface{}{"category": "option", - "request": []map[string]interface{}{ - { - "category": "option", - "symbol": "BTC-10FEB23-24000-C", - "orderType": "Limit", - "side": "Buy", - "qty": "0.1", - "price": "5", - "orderIv": "0.1", - "timeInForce": "GTC", - "orderLinkId": "9b381bb1-401", - "mmp": false, - "reduceOnly": false, - }, - { - "category": "option", - "symbol": "BTC-10FEB23-24000-C", - "orderType": "Limit", - "side": "Buy", - "qty": "0.1", - "price": "5", - "orderIv": "0.1", - "timeInForce": "GTC", - "orderLinkId": "82ee86dd-001", - "mmp": false, - "reduceOnly": false, - }, - }, - } - orderResult, err := client.NewTradeService(params).PlaceBatchOrder(context.Background()) - if err != nil { - fmt.Println(err) - return - } - fmt.Println(bybit.PrettyPrint(orderResult)) -} diff --git a/examples/Trade/place_order.go b/examples/Trade/place_order.go deleted file mode 100644 index e640850..0000000 --- a/examples/Trade/place_order.go +++ /dev/null @@ -1,21 +0,0 @@ -package main - -import ( - "context" - "fmt" - bybit "github.com/wuhewuhe/bybit.go.api" -) - -func main() { - PlaceOrder() -} - -func PlaceOrder() { - client := bybit.NewBybitHttpClient("8wYkmpLsMg10eNQyPm", "Ouxc34myDnXvei54XsBZgoQzfGxO4bkr2Zsj", bybit.WithBaseURL(bybit.TESTNET)) - orderResult, err := client.NewPlaceOrderService("linear", "XRPUSDT", "Buy", "Market", "10").Do(context.Background()) - if err != nil { - fmt.Println(err) - return - } - fmt.Println(bybit.PrettyPrint(orderResult)) -} diff --git a/go.mod b/go.mod index cb1ade5..5995023 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/wuhewuhe/bybit.go.api +module github.com/mudrex/bybit.go.api go 1.21 diff --git a/go.sum b/go.sum index 3b3cac7..53db67c 100644 --- a/go.sum +++ b/go.sum @@ -10,7 +10,6 @@ github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/ github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= -github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= diff --git a/lending.go b/lending.go index 3e43085..3be4d61 100644 --- a/lending.go +++ b/lending.go @@ -2,7 +2,7 @@ package bybit_connector import ( "context" - "github.com/wuhewuhe/bybit.go.api/handlers" + "github.com/mudrex/bybit.go.api/handlers" "net/http" ) diff --git a/market_service.go b/market_service.go index a660dc1..92d055d 100644 --- a/market_service.go +++ b/market_service.go @@ -5,7 +5,7 @@ import ( "fmt" "net/http" - "github.com/wuhewuhe/bybit.go.api/models" + "github.com/mudrex/bybit.go.api/models" ) // MarketKlinesService Market Kline (GET /v5/market/kline) diff --git a/market_service_test.go b/market_service_test.go index 5c85684..2d44969 100644 --- a/market_service_test.go +++ b/market_service_test.go @@ -4,8 +4,8 @@ import ( "net/http" "testing" + "github.com/mudrex/bybit.go.api/models" "github.com/stretchr/testify/suite" - "github.com/wuhewuhe/bybit.go.api/models" ) type marketTestSuite struct { diff --git a/position.go b/position.go index e331d61..f8d2a46 100644 --- a/position.go +++ b/position.go @@ -2,7 +2,7 @@ package bybit_connector import ( "context" - "github.com/wuhewuhe/bybit.go.api/handlers" + "github.com/mudrex/bybit.go.api/handlers" "net/http" ) diff --git a/pre_upgrade.go b/pre_upgrade.go index 84b2041..1d34013 100644 --- a/pre_upgrade.go +++ b/pre_upgrade.go @@ -2,7 +2,7 @@ package bybit_connector import ( "context" - "github.com/wuhewuhe/bybit.go.api/handlers" + "github.com/mudrex/bybit.go.api/handlers" "net/http" ) diff --git a/spot_leverage.go b/spot_leverage.go index 58e7fae..8061fa1 100644 --- a/spot_leverage.go +++ b/spot_leverage.go @@ -2,7 +2,7 @@ package bybit_connector import ( "context" - "github.com/wuhewuhe/bybit.go.api/handlers" + "github.com/mudrex/bybit.go.api/handlers" "net/http" ) diff --git a/spot_margin.go b/spot_margin.go index f7bb9ab..7a0b67c 100644 --- a/spot_margin.go +++ b/spot_margin.go @@ -3,7 +3,7 @@ package bybit_connector import ( "context" "errors" - "github.com/wuhewuhe/bybit.go.api/handlers" + "github.com/mudrex/bybit.go.api/handlers" "net/http" ) diff --git a/trade.go b/trade.go index 4f674bc..4a3bf81 100644 --- a/trade.go +++ b/trade.go @@ -2,8 +2,8 @@ package bybit_connector import ( "context" - "github.com/wuhewuhe/bybit.go.api/handlers" - "github.com/wuhewuhe/bybit.go.api/models" + "github.com/mudrex/bybit.go.api/handlers" + "github.com/mudrex/bybit.go.api/models" "net/http" ) diff --git a/user.go b/user.go index fe08604..aba4615 100644 --- a/user.go +++ b/user.go @@ -2,7 +2,7 @@ package bybit_connector import ( "context" - "github.com/wuhewuhe/bybit.go.api/handlers" + "github.com/mudrex/bybit.go.api/handlers" "net/http" ) From f43558c56191930d3fd00a67ad7dcf676067b64c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 12 Jun 2024 16:39:31 +0530 Subject: [PATCH 2/6] Bump golang.org/x/net in the go_modules group across 1 directory (#1) Bumps the go_modules group with 1 update in the / directory: [golang.org/x/net](https://github.com/golang/net). Updates `golang.org/x/net` from 0.19.0 to 0.23.0 - [Commits](https://github.com/golang/net/compare/v0.19.0...v0.23.0) --- updated-dependencies: - dependency-name: golang.org/x/net dependency-type: indirect dependency-group: go_modules ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 5995023..0f6bbe3 100644 --- a/go.mod +++ b/go.mod @@ -16,6 +16,6 @@ require ( github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/stretchr/objx v0.5.1 // indirect - golang.org/x/net v0.19.0 // indirect + golang.org/x/net v0.23.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 53db67c..d90013a 100644 --- a/go.sum +++ b/go.sum @@ -28,8 +28,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c= -golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U= +golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= +golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From 54bce653fe02f41686d8dd35f31e240a5741a4b5 Mon Sep 17 00:00:00 2001 From: Shravan Kumar Gond Date: Thu, 8 Aug 2024 13:07:39 +0530 Subject: [PATCH 3/6] Pass missing Body in the POST method /set-margin-mode (#4) --- account.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/account.go b/account.go index 866aae1..b9857fa 100644 --- a/account.go +++ b/account.go @@ -2,8 +2,9 @@ package bybit_connector import ( "context" - "github.com/mudrex/bybit.go.api/handlers" "net/http" + + "github.com/mudrex/bybit.go.api/handlers" ) type AccountClient struct { @@ -234,11 +235,15 @@ func (s *AccountClient) SetCollateralCoin(ctx context.Context, opts ...RequestOp } func (s *AccountClient) SetMarginMode(ctx context.Context, opts ...RequestOption) (res *ServerResponse, err error) { + if err = handlers.ValidateParams(s.params); err != nil { + return nil, err + } r := &request{ method: http.MethodPost, endpoint: "/v5/account/set-margin-mode", secType: secTypeSigned, } + r.setParams(s.params) data, err := s.c.callAPI(ctx, r, opts...) if err != nil { return nil, err From e89a206ceaf1dd9d8304dedd48aefba5f4ff06a6 Mon Sep 17 00:00:00 2001 From: upendra235 <105635577+upendra235@users.noreply.github.com> Date: Mon, 12 Aug 2024 15:32:34 +0530 Subject: [PATCH 4/6] fix concurrent writes to websocket (#5) --- bybit_websocket.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bybit_websocket.go b/bybit_websocket.go index 78d8513..cae1ccb 100644 --- a/bybit_websocket.go +++ b/bybit_websocket.go @@ -6,6 +6,7 @@ import ( "crypto/sha256" "encoding/hex" "fmt" + "sync" "time" "github.com/google/uuid" @@ -14,6 +15,8 @@ import ( type MessageHandler func(message string) error +var mu sync.Mutex + func (b *WebSocket) handleIncomingMessages() { for { _, message, err := b.conn.ReadMessage() @@ -129,6 +132,8 @@ func Ping(b *WebSocket) { for { select { case <-ticker.C: // Wait until the ticker sends a signal + mu.Lock() + defer mu.Unlock() if err := b.conn.WriteMessage(websocket.PingMessage, nil); err != nil { fmt.Println("Failed to send ping:", err) } @@ -146,6 +151,8 @@ func (b *WebSocket) Disconnect() error { } func (b *WebSocket) Send(message string) error { + mu.Lock() + defer mu.Unlock() return b.conn.WriteMessage(websocket.TextMessage, []byte(message)) } From d18f5f22d0f919b784bb0ba693ee33bc6456fb51 Mon Sep 17 00:00:00 2001 From: Shravan Kumar Gond Date: Wed, 16 Oct 2024 11:26:31 +0530 Subject: [PATCH 5/6] Update the Intrument Info endpoint response with the latest detail (#6) --- market_service_test.go | 21 ++++++++++----------- models/marketResponse.go | 15 ++++++--------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/market_service_test.go b/market_service_test.go index 2d44969..c3dd30d 100644 --- a/market_service_test.go +++ b/market_service_test.go @@ -390,12 +390,11 @@ func (s *marketTestSuite) TestInstrumentsInfo() { "status": "Trading", "marginTrading": "both", "lotSizeFilter": { - "basePrecision": "0.000001", - "quotePrecision": "0.00000001", - "minOrderQty": "0.000048", - "maxOrderQty": "71.73956243", - "minOrderAmt": "1", - "maxOrderAmt": "2000000" + "minOrderQty": "0.000048", + "maxOrderQty": "71.73956243", + "minNotionalValue": "5.00", + "maxMktOrderQty": "10.0", + "postOnlyMaxOrderQty": "71.73956243" }, "priceFilter": { "tickSize": "0.01" @@ -446,11 +445,11 @@ func (s *marketTestSuite) TestInstrumentsInfo() { Status: "Trading", MarginTrading: "both", LotSizeFilter: models.LotSizeFilter{ - BasePrecision: "0.000001", - QuotePrecision: "0.00000001", - MinOrderQty: "0.000048", - MaxOrderQty: "71.73956243", MinOrderAmt: "1", - MaxOrderAmt: "2000000", + MinOrderQty: "0.000048", + MaxOrderQty: "71.73956243", + MinNotionalValue: "5.00", + MaxMktOrderQty: "10.0", + PostOnlyMaxOrderQty: "71.73956243", }, PriceFilter: models.PriceFilter{ TickSize: "0.01", diff --git a/models/marketResponse.go b/models/marketResponse.go index c373999..74a2fe6 100644 --- a/models/marketResponse.go +++ b/models/marketResponse.go @@ -87,8 +87,12 @@ type Instrument struct { LotSizeFilter LotSizeFilter `json:"lotSizeFilter"` UnifiedMarginTrade bool `json:"unifiedMarginTrade"` FundingInterval int `json:"fundingInterval"` + UpperFundingRate string `json:"upperFundingRate"` + LowerFundingRate string `json:"lowerFundingRate"` SettleCoin string `json:"settleCoin"` CopyTrading string `json:"copyTrading"` + IsPreListing bool `json:"isPreListing"` + PreListingInfo string `json:"preListingInfo"` } type LeverageFilter struct { @@ -107,18 +111,11 @@ type LotSizeFilter struct { MaxOrderQty string `json:"maxOrderQty"` MinOrderQty string `json:"minOrderQty"` QtyStep string `json:"qtyStep"` + MaxMktOrderQty string `json:"maxMktOrderQty"` + MinNotionalValue string `json:"minNotionalValue"` PostOnlyMaxOrderQty string `json:"postOnlyMaxOrderQty"` - BasePrecision string `json:"basePrecision"` - QuotePrecision string `json:"quotePrecision"` - MaxOrderAmt string `json:"maxOrderAmt"` - MinOrderAmt string `jsoN:"minOrderAmt"` } -// type OrderBookEntry struct { -// Price string `json:"0"` -// Size string `json:"1"` -// } - type OrderBookEntry []string type OrderBookInfo struct { From 7ce6d96cef7eca635c1f4be7fa619dd343f63b7f Mon Sep 17 00:00:00 2001 From: upendra235 <105635577+upendra235@users.noreply.github.com> Date: Wed, 16 Oct 2024 16:34:55 +0530 Subject: [PATCH 6/6] Revert concurrent write fix (#7) --- bybit_websocket.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/bybit_websocket.go b/bybit_websocket.go index cae1ccb..78d8513 100644 --- a/bybit_websocket.go +++ b/bybit_websocket.go @@ -6,7 +6,6 @@ import ( "crypto/sha256" "encoding/hex" "fmt" - "sync" "time" "github.com/google/uuid" @@ -15,8 +14,6 @@ import ( type MessageHandler func(message string) error -var mu sync.Mutex - func (b *WebSocket) handleIncomingMessages() { for { _, message, err := b.conn.ReadMessage() @@ -132,8 +129,6 @@ func Ping(b *WebSocket) { for { select { case <-ticker.C: // Wait until the ticker sends a signal - mu.Lock() - defer mu.Unlock() if err := b.conn.WriteMessage(websocket.PingMessage, nil); err != nil { fmt.Println("Failed to send ping:", err) } @@ -151,8 +146,6 @@ func (b *WebSocket) Disconnect() error { } func (b *WebSocket) Send(message string) error { - mu.Lock() - defer mu.Unlock() return b.conn.WriteMessage(websocket.TextMessage, []byte(message)) }