mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-22 15:10:13 +00:00
* tag optional sonic and allow full library conversion * Add workflow and disallow arm and darwin usage * Add basic hotswap benchmark * linter: fix * use bash * linter: fix? * Fix whoopsie, add to make file, also add mention in features list. * test enforcement * actually read documentation see if this works * linter: fix * linter: fix * sonic: bump tagged version * encoding/json: drop build tag arch and os filters * encoding/json: consolidate tests * encoding/json: log build tag usage * rm superfluous builds * glorious/nits: add template change and regen docs * glorious/nits: update commentary on nolint directive * glorious/nits: rm init func and log results in main.go * Test to actually pull flag in * linter: fix * thrasher: nits * gk: nits 4 goflags goooooooooo! * gk: nits rn * make sonic default json implementation * screen 386 * linter: fix * Add commentary * glorious: nits Makefile not working * gk: nits * gk: nits whoops * whoopsirino * mention 32bit systems won't be sonic * gk: super-duper nit of extremes --------- Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
40 lines
1.2 KiB
Go
40 lines
1.2 KiB
Go
package versions
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/buger/jsonparser"
|
|
"github.com/thrasher-corp/gocryptotrader/encoding/json"
|
|
)
|
|
|
|
// Version3 is an ExchangeVersion to remove the publishPeriod from the exchange's orderbook config
|
|
type Version3 struct{}
|
|
|
|
func init() {
|
|
Manager.registerVersion(3, &Version3{})
|
|
}
|
|
|
|
// Exchanges returns all exchanges: "*"
|
|
func (v *Version3) Exchanges() []string { return []string{"*"} }
|
|
|
|
// UpgradeExchange will remove the publishPeriod from the exchange's orderbook config
|
|
func (v *Version3) UpgradeExchange(_ context.Context, e []byte) ([]byte, error) {
|
|
e = jsonparser.Delete(e, "orderbook", "publishPeriod")
|
|
return e, nil
|
|
}
|
|
|
|
const defaultOrderbookPublishPeriod = time.Second * 10
|
|
|
|
// DowngradeExchange will downgrade the exchange's config by setting the default orderbook publish period
|
|
func (v *Version3) DowngradeExchange(_ context.Context, e []byte) ([]byte, error) {
|
|
if _, _, _, err := jsonparser.Get(e, "orderbook"); err != nil {
|
|
return e, nil //nolint:nilerr // No error, just return the original config
|
|
}
|
|
out, err := json.Marshal(defaultOrderbookPublishPeriod)
|
|
if err != nil {
|
|
return e, err
|
|
}
|
|
return jsonparser.Set(e, out, "orderbook", "publishPeriod")
|
|
}
|