Skip to content

Commit

Permalink
Using built-in json instead of json-iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
khiemdoan committed Dec 4, 2024
1 parent 4fd0ba3 commit 3ae4efe
Show file tree
Hide file tree
Showing 38 changed files with 44 additions and 23 deletions.
1 change: 1 addition & 0 deletions v2/account_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package binance

import (
"context"
"encoding/json"
"net/http"
)

Expand Down
1 change: 1 addition & 0 deletions v2/asset_detail_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package binance

import (
"context"
"encoding/json"
"net/http"
)

Expand Down
1 change: 1 addition & 0 deletions v2/asset_dividend_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package binance

import (
"context"
"encoding/json"
"net/http"
)

Expand Down
1 change: 1 addition & 0 deletions v2/bnb_burn_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package binance

import (
"context"
"encoding/json"
"net/http"
)

Expand Down
1 change: 1 addition & 0 deletions v2/c2c_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package binance

import (
"context"
"encoding/json"
"net/http"
)

Expand Down
5 changes: 1 addition & 4 deletions v2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"crypto/tls"
"encoding/json"
"fmt"
"io"
"log"
Expand All @@ -13,7 +14,6 @@ import (
"time"

"github.com/bitly/go-simplejson"
jsoniter "github.com/json-iterator/go"

"github.com/adshao/go-binance/v2/common"
"github.com/adshao/go-binance/v2/delivery"
Expand Down Expand Up @@ -133,9 +133,6 @@ type SelfTradePreventionMode string
// UseTestnet switch all the API endpoints from production to the testnet
var UseTestnet = false

// Redefining the standard package
var json = jsoniter.ConfigCompatibleWithStandardLibrary

// Global enums
const (
SideTypeBuy SideType = "BUY"
Expand Down
1 change: 1 addition & 0 deletions v2/convert_trade.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package binance

import (
"context"
"encoding/json"
"net/http"
)

Expand Down
1 change: 1 addition & 0 deletions v2/deposit_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package binance

import (
"context"
"encoding/json"
"net/http"
)

Expand Down
1 change: 1 addition & 0 deletions v2/dust_log_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package binance

import (
"context"
"encoding/json"
"net/http"
)

Expand Down
1 change: 1 addition & 0 deletions v2/exchange_info_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package binance

import (
"context"
"encoding/json"
"net/http"

"github.com/adshao/go-binance/v2/common"
Expand Down
1 change: 1 addition & 0 deletions v2/fiat_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package binance

import (
"context"
"encoding/json"
"net/http"
)

Expand Down
1 change: 1 addition & 0 deletions v2/futures_algo_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package binance

import (
"context"
"encoding/json"
"fmt"
"net/http"

Expand Down
1 change: 1 addition & 0 deletions v2/futures_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package binance

import (
"context"
"encoding/json"
"net/http"
)

Expand Down
3 changes: 0 additions & 3 deletions v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@ require (
github.com/google/uuid v1.6.0
github.com/gorilla/websocket v1.5.0
github.com/jpillora/backoff v1.0.0
github.com/json-iterator/go v1.1.12
github.com/stretchr/testify v1.8.1
)

require (
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/kr/pretty v0.2.0 // 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.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
8 changes: 0 additions & 8 deletions v2/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,23 @@ 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/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
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/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
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=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
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.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
Expand Down
1 change: 1 addition & 0 deletions v2/interest_history_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package binance

import (
"context"
"encoding/json"
"net/http"
)

Expand Down
5 changes: 4 additions & 1 deletion v2/internal_universal_transfer_service.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package binance

import "context"
import (
"context"
"encoding/json"
)

// InternalUniversalTransferService Universal Transfer (For Master Account)
// https://binance-docs.github.io/apidocs/spot/en/#universal-transfer-for-master-account
Expand Down
1 change: 1 addition & 0 deletions v2/liquidity_pool_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package binance

import (
"context"
"encoding/json"
"net/http"
)

Expand Down
1 change: 1 addition & 0 deletions v2/margin_order_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package binance

import (
"context"
"encoding/json"
"net/http"
)

Expand Down
1 change: 1 addition & 0 deletions v2/margin_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package binance

import (
"context"
"encoding/json"
"net/http"
"strings"
)
Expand Down
4 changes: 2 additions & 2 deletions v2/order_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package binance

import (
"context"
stdjson "encoding/json"
"encoding/json"
"net/http"
)

Expand Down Expand Up @@ -766,7 +766,7 @@ func (s *CancelOpenOrdersService) Do(ctx context.Context, opts ...RequestOption)
if err != nil {
return &CancelOpenOrdersResponse{}, err
}
rawMessages := make([]*stdjson.RawMessage, 0)
rawMessages := make([]*json.RawMessage, 0)
err = json.Unmarshal(data, &rawMessages)
if err != nil {
return &CancelOpenOrdersResponse{}, err
Expand Down
1 change: 1 addition & 0 deletions v2/order_service_ws_create.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package binance

import (
"encoding/json"
"time"

"github.com/adshao/go-binance/v2/common"
Expand Down
1 change: 1 addition & 0 deletions v2/order_service_ws_create_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package binance

import (
"encoding/json"
"fmt"
"testing"

Expand Down
1 change: 1 addition & 0 deletions v2/pay_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package binance

import (
"context"
"encoding/json"
"net/http"
)

Expand Down
1 change: 1 addition & 0 deletions v2/rate_limit_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package binance

import (
"context"
"encoding/json"
"net/http"
)

Expand Down
1 change: 1 addition & 0 deletions v2/rebate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package binance

import (
"context"
"encoding/json"
"net/http"
)

Expand Down
1 change: 1 addition & 0 deletions v2/request.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package binance

import (
"encoding/json"
"fmt"
"io"
"net/http"
Expand Down
1 change: 1 addition & 0 deletions v2/savings_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package binance

import (
"context"
"encoding/json"
"net/http"
)

Expand Down
1 change: 1 addition & 0 deletions v2/simple_earn_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package binance

import (
"context"
"encoding/json"
"net/http"
)

Expand Down
1 change: 1 addition & 0 deletions v2/staking_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package binance

import (
"context"
"encoding/json"
"net/http"
)

Expand Down
1 change: 1 addition & 0 deletions v2/subaccount_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package binance

import (
"context"
"encoding/json"
"net/http"
)

Expand Down
1 change: 1 addition & 0 deletions v2/ticker_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package binance

import (
"context"
"encoding/json"
"net/http"

"github.com/adshao/go-binance/v2/common"
Expand Down
1 change: 1 addition & 0 deletions v2/trade_fee_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package binance

import (
"context"
"encoding/json"
"net/http"
)

Expand Down
1 change: 1 addition & 0 deletions v2/trade_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package binance

import (
"context"
"encoding/json"
"net/http"
)

Expand Down
1 change: 1 addition & 0 deletions v2/tradingDayTicker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package binance

import (
"context"
"encoding/json"

"net/http"

Expand Down
1 change: 1 addition & 0 deletions v2/user_universal_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package binance

import (
"context"
"encoding/json"
"net/http"
)

Expand Down
10 changes: 5 additions & 5 deletions v2/websocket_service.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package binance

import (
stdjson "encoding/json"
"encoding/json"
"fmt"
"strings"
"time"
Expand Down Expand Up @@ -133,7 +133,7 @@ func WsCombinedPartialDepthServe(symbolLevels map[string]string, handler WsParti
symbol := strings.Split(stream, "@")[0]
event.Symbol = strings.ToUpper(symbol)
data := j.Get("data").MustMap()
event.LastUpdateID, _ = data["lastUpdateId"].(stdjson.Number).Int64()
event.LastUpdateID, _ = data["lastUpdateId"].(json.Number).Int64()
bidsLen := len(data["bids"].([]interface{}))
event.Bids = make([]Bid, bidsLen)
for i := 0; i < bidsLen; i++ {
Expand Down Expand Up @@ -254,9 +254,9 @@ func wsCombinedDepthServe(endpoint string, handler WsDepthHandler, errHandler Er
symbol := strings.Split(stream, "@")[0]
event.Symbol = strings.ToUpper(symbol)
data := j.Get("data").MustMap()
event.Time, _ = data["E"].(stdjson.Number).Int64()
event.LastUpdateID, _ = data["u"].(stdjson.Number).Int64()
event.FirstUpdateID, _ = data["U"].(stdjson.Number).Int64()
event.Time, _ = data["E"].(json.Number).Int64()
event.LastUpdateID, _ = data["u"].(json.Number).Int64()
event.FirstUpdateID, _ = data["U"].(json.Number).Int64()
bidsLen := len(data["b"].([]interface{}))
event.Bids = make([]Bid, bidsLen)
for i := 0; i < bidsLen; i++ {
Expand Down
1 change: 1 addition & 0 deletions v2/withdraw_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package binance

import (
"context"
"encoding/json"
"net/http"
)

Expand Down

0 comments on commit 3ae4efe

Please sign in to comment.