-
-
Notifications
You must be signed in to change notification settings - Fork 302
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkg/exchange: add tests for query markets
- Loading branch information
1 parent
3e087e8
commit 0d690c3
Showing
3 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
pkg/exchange/bitget/bitgetapi/v2/testdata/get_symbols_request.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{ | ||
"code":"00000", | ||
"msg":"success", | ||
"requestTime":1709620645267, | ||
"data":[ | ||
{ | ||
"symbol":"ETHUSDT", | ||
"baseCoin":"ETH", | ||
"quoteCoin":"USDT", | ||
"minTradeAmount":"0", | ||
"maxTradeAmount":"10000000000", | ||
"takerFeeRate":"0.002", | ||
"makerFeeRate":"0.002", | ||
"pricePrecision":"2", | ||
"quantityPrecision":"4", | ||
"quotePrecision":"6", | ||
"status":"online", | ||
"minTradeUSDT":"5", | ||
"buyLimitPriceRatio":"0.05", | ||
"sellLimitPriceRatio":"0.05", | ||
"areaSymbol":"no" | ||
}, | ||
{ | ||
"symbol":"BTCUSDT", | ||
"baseCoin":"BTC", | ||
"quoteCoin":"USDT", | ||
"minTradeAmount":"0", | ||
"maxTradeAmount":"10000000000", | ||
"takerFeeRate":"0.002", | ||
"makerFeeRate":"0.002", | ||
"pricePrecision":"2", | ||
"quantityPrecision":"6", | ||
"quotePrecision":"6", | ||
"status":"gray", | ||
"minTradeUSDT":"5", | ||
"buyLimitPriceRatio":"0.05", | ||
"sellLimitPriceRatio":"0.05", | ||
"areaSymbol":"no" | ||
}, | ||
{ | ||
"symbol":"SPONGEUSDT", | ||
"baseCoin":"SPONGE", | ||
"quoteCoin":"USDT", | ||
"minTradeAmount":"0", | ||
"maxTradeAmount":"10000000000", | ||
"takerFeeRate":"0.001", | ||
"makerFeeRate":"0.001", | ||
"pricePrecision":"8", | ||
"quantityPrecision":"0", | ||
"quotePrecision":"8", | ||
"status":"offline", | ||
"minTradeUSDT":"5", | ||
"buyLimitPriceRatio":"0.1", | ||
"sellLimitPriceRatio":"0.1", | ||
"areaSymbol":"no" | ||
} | ||
] | ||
} |
6 changes: 6 additions & 0 deletions
6
pkg/exchange/bitget/bitgetapi/v2/testdata/get_symbols_request_error.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"code":"40018", | ||
"msg":"Invalid IP", | ||
"requestTime":1709620645267, | ||
"data":[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package bitget | ||
|
||
import ( | ||
"context" | ||
"math" | ||
"net/http" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/c9s/bbgo/pkg/fixedpoint" | ||
"github.com/c9s/bbgo/pkg/testing/httptesting" | ||
"github.com/c9s/bbgo/pkg/types" | ||
) | ||
|
||
func TestExchange_QueryMarkets(t *testing.T) { | ||
ex := New("key", "secret", "passphrase") | ||
|
||
t.Run("succeeds", func(t *testing.T) { | ||
transport := &httptesting.MockTransport{} | ||
ex.client.HttpClient.Transport = transport | ||
|
||
f, err := os.ReadFile("bitgetapi/v2/testdata/get_symbols_request.json") | ||
assert.NoError(t, err) | ||
|
||
transport.GET("/api/v2/spot/public/symbols", func(req *http.Request) (*http.Response, error) { | ||
return httptesting.BuildResponseString(http.StatusOK, string(f)), nil | ||
}) | ||
|
||
mkts, err := ex.QueryMarkets(context.Background()) | ||
assert.NoError(t, err) | ||
|
||
expMkts := types.MarketMap{ | ||
"ETHUSDT": types.Market{ | ||
Exchange: types.ExchangeBitget, | ||
Symbol: "ETHUSDT", | ||
LocalSymbol: "ETHUSDT", | ||
PricePrecision: 2, | ||
VolumePrecision: 4, | ||
QuoteCurrency: "USDT", | ||
BaseCurrency: "ETH", | ||
MinNotional: fixedpoint.NewFromInt(5), | ||
MinAmount: fixedpoint.NewFromInt(5), | ||
MinQuantity: fixedpoint.NewFromInt(0), | ||
MaxQuantity: fixedpoint.NewFromInt(10000000000), | ||
StepSize: fixedpoint.NewFromFloat(1.0 / math.Pow10(4)), | ||
TickSize: fixedpoint.NewFromFloat(1.0 / math.Pow10(2)), | ||
MinPrice: fixedpoint.Zero, | ||
MaxPrice: fixedpoint.Zero, | ||
}, | ||
"BTCUSDT": types.Market{ | ||
Exchange: types.ExchangeBitget, | ||
Symbol: "BTCUSDT", | ||
LocalSymbol: "BTCUSDT", | ||
PricePrecision: 2, | ||
VolumePrecision: 6, | ||
QuoteCurrency: "USDT", | ||
BaseCurrency: "BTC", | ||
MinNotional: fixedpoint.NewFromInt(5), | ||
MinAmount: fixedpoint.NewFromInt(5), | ||
MinQuantity: fixedpoint.NewFromInt(0), | ||
MaxQuantity: fixedpoint.NewFromInt(10000000000), | ||
StepSize: fixedpoint.NewFromFloat(1.0 / math.Pow10(6)), | ||
TickSize: fixedpoint.NewFromFloat(1.0 / math.Pow10(2)), | ||
MinPrice: fixedpoint.Zero, | ||
MaxPrice: fixedpoint.Zero, | ||
}, | ||
} | ||
assert.Equal(t, expMkts, mkts) | ||
}) | ||
|
||
t.Run("error", func(t *testing.T) { | ||
transport := &httptesting.MockTransport{} | ||
ex.client.HttpClient.Transport = transport | ||
|
||
f, err := os.ReadFile("bitgetapi/v2/testdata/get_symbols_request_error.json") | ||
assert.NoError(t, err) | ||
|
||
transport.GET("/api/v2/spot/public/symbols", func(req *http.Request) (*http.Response, error) { | ||
return httptesting.BuildResponseString(http.StatusBadRequest, string(f)), nil | ||
}) | ||
|
||
_, err = ex.QueryMarkets(context.Background()) | ||
assert.ErrorContains(t, err, "Invalid IP") | ||
}) | ||
} |