tri: load test data from static file

This commit is contained in:
c9s 2023-07-11 10:23:54 +08:00
parent ce481ba52d
commit b1c1caa6af
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
3 changed files with 41 additions and 6 deletions

View File

@ -3,24 +3,20 @@
package tri package tri
import ( import (
"context"
"fmt" "fmt"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/c9s/bbgo/pkg/cache"
"github.com/c9s/bbgo/pkg/exchange/binance"
"github.com/c9s/bbgo/pkg/fixedpoint" "github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types" "github.com/c9s/bbgo/pkg/types"
"github.com/c9s/bbgo/pkg/util"
) )
var markets = make(types.MarketMap) var markets = make(types.MarketMap)
func init() { func init() {
var err error if err := util.ReadJsonFile("../../../testdata/binance-markets.json", &markets); err != nil {
markets, err = cache.LoadExchangeMarketsWithCache(context.Background(), &binance.Exchange{})
if err != nil {
panic(err) panic(err)
} }
} }

View File

@ -2,7 +2,9 @@ package util
import ( import (
"encoding/json" "encoding/json"
"io"
"io/ioutil" "io/ioutil"
"os"
) )
func WriteJsonFile(p string, obj interface{}) error { func WriteJsonFile(p string, obj interface{}) error {
@ -13,3 +15,24 @@ func WriteJsonFile(p string, obj interface{}) error {
return ioutil.WriteFile(p, out, 0644) return ioutil.WriteFile(p, out, 0644)
} }
func ReadJsonFile(file string, obj interface{}) error {
f, err := os.Open(file)
if err != nil {
return err
}
defer f.Close()
byteResult, err := io.ReadAll(f)
if err != nil {
return err
}
err = json.Unmarshal([]byte(byteResult), obj)
if err != nil {
return err
}
return nil
}

View File

@ -62,5 +62,21 @@
"minPrice": 0.01, "minPrice": 0.01,
"maxPrice": 100000, "maxPrice": 100000,
"tickSize": 0.01 "tickSize": 0.01
},
"ETHBTC": {
"symbol": "ETHBTC",
"localSymbol": "ETHBTC",
"pricePrecision": 8,
"volumePrecision": 8,
"quoteCurrency": "BTC",
"baseCurrency": "ETH",
"minNotional": 0.0001,
"minAmount": 0.0001,
"minQuantity": 0.0001,
"maxQuantity": 100000,
"stepSize": 0.0001,
"minPrice": 1e-05,
"maxPrice": 922327,
"tickSize": 1e-05
} }
} }