mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-23 07:15:15 +00:00
tri: load test data from static file
This commit is contained in:
parent
ce481ba52d
commit
b1c1caa6af
|
@ -3,24 +3,20 @@
|
|||
package tri
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"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/types"
|
||||
"github.com/c9s/bbgo/pkg/util"
|
||||
)
|
||||
|
||||
var markets = make(types.MarketMap)
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
markets, err = cache.LoadExchangeMarketsWithCache(context.Background(), &binance.Exchange{})
|
||||
if err != nil {
|
||||
if err := util.ReadJsonFile("../../../testdata/binance-markets.json", &markets); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,9 @@ package util
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
)
|
||||
|
||||
func WriteJsonFile(p string, obj interface{}) error {
|
||||
|
@ -13,3 +15,24 @@ func WriteJsonFile(p string, obj interface{}) error {
|
|||
|
||||
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
|
||||
}
|
||||
|
|
16
testdata/binance-markets.json
vendored
16
testdata/binance-markets.json
vendored
|
@ -62,5 +62,21 @@
|
|||
"minPrice": 0.01,
|
||||
"maxPrice": 100000,
|
||||
"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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user