Use jsoniter to unmarshal and add some official enumerations.

This commit is contained in:
isther 2024-01-04 16:50:01 +08:00
parent a5e773a1c3
commit da22696037
16 changed files with 66 additions and 13 deletions

View File

@ -2,7 +2,6 @@ package bybit_connector
import (
"context"
"encoding/json"
"github.com/wuhewuhe/bybit.go.api/handlers"
"net/http"
)

View File

@ -2,7 +2,6 @@ package bybit_connector
import (
"context"
"encoding/json"
"net/http"
)

View File

@ -2,7 +2,6 @@ package bybit_connector
import (
"context"
"encoding/json"
"github.com/wuhewuhe/bybit.go.api/handlers"
"net/http"
)

View File

@ -5,7 +5,6 @@ import (
"crypto/hmac"
"crypto/sha256"
"encoding/hex"
"encoding/json"
"fmt"
"time"

4
go.mod
View File

@ -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

10
go.sum
View File

@ -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=

View File

@ -2,7 +2,6 @@ package bybit_connector
import (
"context"
"encoding/json"
"github.com/wuhewuhe/bybit.go.api/handlers"
"net/http"
)

52
models/enum.go Normal file
View File

@ -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"
)

View File

@ -2,7 +2,6 @@ package bybit_connector
import (
"context"
"encoding/json"
"net/http"
)

View File

@ -2,7 +2,6 @@ package bybit_connector
import (
"context"
"encoding/json"
"github.com/wuhewuhe/bybit.go.api/handlers"
"net/http"
)

View File

@ -2,7 +2,6 @@ package bybit_connector
import (
"context"
"encoding/json"
"github.com/wuhewuhe/bybit.go.api/handlers"
"net/http"
)

View File

@ -1,7 +1,6 @@
package bybit_connector
import (
"encoding/json"
"fmt"
"io"
"log"

View File

@ -2,7 +2,6 @@ package bybit_connector
import (
"context"
"encoding/json"
"github.com/wuhewuhe/bybit.go.api/handlers"
"net/http"
)

View File

@ -2,7 +2,6 @@ package bybit_connector
import (
"context"
"encoding/json"
"errors"
"github.com/wuhewuhe/bybit.go.api/handlers"
"net/http"

View File

@ -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"

View File

@ -2,7 +2,6 @@ package bybit_connector
import (
"context"
"encoding/json"
"github.com/wuhewuhe/bybit.go.api/handlers"
"net/http"
)