From da226960372d5fc7780fd61adc50feeb04e6ebf8 Mon Sep 17 00:00:00 2001 From: isther Date: Thu, 4 Jan 2024 16:50:01 +0800 Subject: [PATCH] Use jsoniter to unmarshal and add some official enumerations. --- account.go | 1 - asset.go | 1 - broker.go | 1 - bybit_websocket.go | 1 - go.mod | 4 ++++ go.sum | 10 +++++++++ lending.go | 1 - models/enum.go | 52 ++++++++++++++++++++++++++++++++++++++++++++++ place_order.go | 1 - position.go | 1 - pre_upgrade.go | 1 - request.go | 1 - spot_leverage.go | 1 - spot_margin.go | 1 - trade.go | 1 - user.go | 1 - 16 files changed, 66 insertions(+), 13 deletions(-) create mode 100644 models/enum.go diff --git a/account.go b/account.go index 85021a9..ccf993c 100644 --- a/account.go +++ b/account.go @@ -2,7 +2,6 @@ package bybit_connector import ( "context" - "encoding/json" "github.com/wuhewuhe/bybit.go.api/handlers" "net/http" ) diff --git a/asset.go b/asset.go index 684f136..bf0f2a6 100644 --- a/asset.go +++ b/asset.go @@ -2,7 +2,6 @@ package bybit_connector import ( "context" - "encoding/json" "net/http" ) diff --git a/broker.go b/broker.go index c1c94d4..a68b1c6 100644 --- a/broker.go +++ b/broker.go @@ -2,7 +2,6 @@ package bybit_connector import ( "context" - "encoding/json" "github.com/wuhewuhe/bybit.go.api/handlers" "net/http" ) diff --git a/bybit_websocket.go b/bybit_websocket.go index be19463..99e3dd9 100644 --- a/bybit_websocket.go +++ b/bybit_websocket.go @@ -5,7 +5,6 @@ import ( "crypto/hmac" "crypto/sha256" "encoding/hex" - "encoding/json" "fmt" "time" diff --git a/go.mod b/go.mod index a9da616..993c8b4 100644 --- a/go.mod +++ b/go.mod @@ -3,13 +3,17 @@ module github.com/wuhewuhe/bybit.go.api go 1.21 require ( + github.com/bitly/go-simplejson v0.5.1 github.com/google/uuid v1.5.0 github.com/gorilla/websocket v1.5.1 + github.com/json-iterator/go v1.1.12 github.com/stretchr/testify v1.8.4 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect + github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect + 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 diff --git a/go.sum b/go.sum index 2e52c76..3120674 100644 --- a/go.sum +++ b/go.sum @@ -1,10 +1,19 @@ +github.com/bitly/go-simplejson v0.5.1 h1:xgwPbetQScXt1gh9BmoJ6j9JMr3TElvuIyjR8pgdoow= +github.com/bitly/go-simplejson v0.5.1/go.mod h1:YOPVLzCfwK14b4Sff3oP1AmGhI9T9Vsg84etUnlyp+Q= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU= github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= 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/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -12,6 +21,7 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/objx v0.5.1 h1:4VhoImhV/Bm0ToFkXFi8hXNXwpDRZ/ynw3amt82mzq0= github.com/stretchr/objx v0.5.1/go.mod h1:/iHQpkQwBD6DLUmQ4pE+s1TXdob1mORJ4/UFdrifcy0= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= diff --git a/lending.go b/lending.go index 2e2941e..3e43085 100644 --- a/lending.go +++ b/lending.go @@ -2,7 +2,6 @@ package bybit_connector import ( "context" - "encoding/json" "github.com/wuhewuhe/bybit.go.api/handlers" "net/http" ) diff --git a/models/enum.go b/models/enum.go new file mode 100644 index 0000000..f527997 --- /dev/null +++ b/models/enum.go @@ -0,0 +1,52 @@ +package models + +type Category string + +const ( + CategorySpot Category = "spot" + CategoryLinear Category = "linear" //Unified Account: USDT perpetual, and USDC contract, including USDC perp, USDC futures; Classic Account: USDT perp + CategoryInverse Category = "inverse" // Inverse contract, including Inverse perp, Inverse futures + CategoryOption Category = "option" +) + +type OrderStatus string + +const ( + OrderStatusCreated OrderStatus = "Created" // order has been accepted by the system but not yet put through the matching engine + OrderStatusNew OrderStatus = "New" // order has been placed successfully + OrderStatusRejected OrderStatus = "Rejected" + OrderStatusPartiallyFilled OrderStatus = "PartiallyFilled" + OrderStatusPartiallyFilledCanceled OrderStatus = "PartiallyFilledCanceled" //Only spot has this order status + OrderStatusFilled OrderStatus = "Filled" + OrderStatusCancelled OrderStatus = "Cancelled" // In derivatives, orders with this status may have an executed qty + OrderStatusUntriggered OrderStatus = "Untriggered" + OrderStatusTriggered OrderStatus = "Triggered" + OrderStatusDeactivated OrderStatus = "Deactivated" // UTA: Spot tp/sl order, conditional order, OCO order are cancelled before they are triggered +) + +type TimeInForce string + +const ( + TimeInForceGTC TimeInForce = "GTC" //GoodTillCancel + TimeInForceIOC TimeInForce = "IOC" //ImmediateOrCancel + TimeInForceFOK TimeInForce = "FOK" //FillOrKill + TimeInForcePostOnly TimeInForce = "PostOnly" +) + +type OrderType string + +const ( + OrderTypeMarket OrderType = "Market" + Limit OrderType = "Limit" + UNKNOWN OrderType = "UNKNOWN" // Is not a valid request parameter value. Is only used in some responses. Mainly, it is used when execType is Funding. +) + +type SymbolStatus string + +const ( + SymbolStatusPreLaunch SymbolStatus = "PreLaunch" + SymbolStatusTrading SymbolStatus = "Trading" + SymbolStatusSettling SymbolStatus = "Settling" + SymbolStatusDelivering SymbolStatus = "Delivering" + SymbolStatusClosed SymbolStatus = "Closed" +) diff --git a/place_order.go b/place_order.go index de6d503..65b07d7 100644 --- a/place_order.go +++ b/place_order.go @@ -2,7 +2,6 @@ package bybit_connector import ( "context" - "encoding/json" "net/http" ) diff --git a/position.go b/position.go index ef8658f..e331d61 100644 --- a/position.go +++ b/position.go @@ -2,7 +2,6 @@ package bybit_connector import ( "context" - "encoding/json" "github.com/wuhewuhe/bybit.go.api/handlers" "net/http" ) diff --git a/pre_upgrade.go b/pre_upgrade.go index eb48829..84b2041 100644 --- a/pre_upgrade.go +++ b/pre_upgrade.go @@ -2,7 +2,6 @@ package bybit_connector import ( "context" - "encoding/json" "github.com/wuhewuhe/bybit.go.api/handlers" "net/http" ) diff --git a/request.go b/request.go index 49ecd9e..672ae5c 100644 --- a/request.go +++ b/request.go @@ -1,7 +1,6 @@ package bybit_connector import ( - "encoding/json" "fmt" "io" "log" diff --git a/spot_leverage.go b/spot_leverage.go index c82d969..58e7fae 100644 --- a/spot_leverage.go +++ b/spot_leverage.go @@ -2,7 +2,6 @@ package bybit_connector import ( "context" - "encoding/json" "github.com/wuhewuhe/bybit.go.api/handlers" "net/http" ) diff --git a/spot_margin.go b/spot_margin.go index 300770a..f7bb9ab 100644 --- a/spot_margin.go +++ b/spot_margin.go @@ -2,7 +2,6 @@ package bybit_connector import ( "context" - "encoding/json" "errors" "github.com/wuhewuhe/bybit.go.api/handlers" "net/http" diff --git a/trade.go b/trade.go index 494b2a9..4f674bc 100644 --- a/trade.go +++ b/trade.go @@ -2,7 +2,6 @@ package bybit_connector import ( "context" - "encoding/json" "github.com/wuhewuhe/bybit.go.api/handlers" "github.com/wuhewuhe/bybit.go.api/models" "net/http" diff --git a/user.go b/user.go index b20aae8..fe08604 100644 --- a/user.go +++ b/user.go @@ -2,7 +2,6 @@ package bybit_connector import ( "context" - "encoding/json" "github.com/wuhewuhe/bybit.go.api/handlers" "net/http" )