mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-01 07:26:48 +00:00
exchanges: Limit mock test JSON data size by truncating slices and maps (#1968)
* set limiter to first level mock data list and updated unit tests * address nested slices length limit * minor fix recording file and update unit tests * minor updates on unit tests * re-record mock files and minor fix on the unit tests ti adapt the mock data change * improve http recording limit value and fix issues with mock data in binance * added MockDataSliceLimit in request items and resolve minor unit test issues * resolve missed conflict * rename mock variables, resolve unit test issues, and other updates * minor fix to CheckJSON and update unit tests * minor unit test fix * further optimization on mock CheckJSON method, unit tests, and re-record poloniex * common and recording unit tests fix * minor linter issues fix * unit tests format fix * fix miscellaneous error * unit tests fix and minor docs update * re-record and reduce mock file size * indentation fix * minor assertion test fix * reverted log.Printf line in live testing * rename variables * update NewVCRServer unit test * replace string comparison with *net.OpError check * restructur net error test * exchanges/mock: Remove redundant error assertion message in TestNewVCRServer --------- Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
This commit is contained in:
@@ -709,12 +709,13 @@ func (e *Exchange) SendHTTPRequest(ctx context.Context, ePath exchange.URL, path
|
||||
return err
|
||||
}
|
||||
item := &request.Item{
|
||||
Method: http.MethodGet,
|
||||
Path: endpointPath + path,
|
||||
Result: result,
|
||||
Verbose: e.Verbose,
|
||||
HTTPDebugging: e.HTTPDebugging,
|
||||
HTTPRecording: e.HTTPRecording,
|
||||
Method: http.MethodGet,
|
||||
Path: endpointPath + path,
|
||||
Result: result,
|
||||
Verbose: e.Verbose,
|
||||
HTTPDebugging: e.HTTPDebugging,
|
||||
HTTPRecording: e.HTTPRecording,
|
||||
HTTPMockDataSliceLimit: e.HTTPMockDataSliceLimit,
|
||||
}
|
||||
|
||||
return e.SendPayload(ctx, f, func() (*request.Item, error) {
|
||||
@@ -738,13 +739,14 @@ func (e *Exchange) SendAPIKeyHTTPRequest(ctx context.Context, ePath exchange.URL
|
||||
headers := make(map[string]string)
|
||||
headers["X-MBX-APIKEY"] = creds.Key
|
||||
item := &request.Item{
|
||||
Method: http.MethodGet,
|
||||
Path: endpointPath + path,
|
||||
Headers: headers,
|
||||
Result: result,
|
||||
Verbose: e.Verbose,
|
||||
HTTPDebugging: e.HTTPDebugging,
|
||||
HTTPRecording: e.HTTPRecording,
|
||||
Method: http.MethodGet,
|
||||
Path: endpointPath + path,
|
||||
Headers: headers,
|
||||
Result: result,
|
||||
Verbose: e.Verbose,
|
||||
HTTPDebugging: e.HTTPDebugging,
|
||||
HTTPRecording: e.HTTPRecording,
|
||||
HTTPMockDataSliceLimit: e.HTTPMockDataSliceLimit,
|
||||
}
|
||||
|
||||
return e.SendPayload(ctx, f, func() (*request.Item, error) {
|
||||
@@ -783,13 +785,14 @@ func (e *Exchange) SendAuthHTTPRequest(ctx context.Context, ePath exchange.URL,
|
||||
headers["X-MBX-APIKEY"] = creds.Key
|
||||
fullPath := common.EncodeURLValues(endpointPath+path, params) + "&signature=" + hex.EncodeToString(hmacSigned)
|
||||
return &request.Item{
|
||||
Method: method,
|
||||
Path: fullPath,
|
||||
Headers: headers,
|
||||
Result: &interim,
|
||||
Verbose: e.Verbose,
|
||||
HTTPDebugging: e.HTTPDebugging,
|
||||
HTTPRecording: e.HTTPRecording,
|
||||
Method: method,
|
||||
Path: fullPath,
|
||||
Headers: headers,
|
||||
Result: &interim,
|
||||
Verbose: e.Verbose,
|
||||
HTTPDebugging: e.HTTPDebugging,
|
||||
HTTPRecording: e.HTTPRecording,
|
||||
HTTPMockDataSliceLimit: e.HTTPMockDataSliceLimit,
|
||||
}, nil
|
||||
}, request.AuthenticatedRequest)
|
||||
if err != nil {
|
||||
@@ -1061,13 +1064,14 @@ func (e *Exchange) GetWsAuthStreamKey(ctx context.Context) (string, error) {
|
||||
headers := make(map[string]string)
|
||||
headers["X-MBX-APIKEY"] = creds.Key
|
||||
item := &request.Item{
|
||||
Method: http.MethodPost,
|
||||
Path: endpointPath + userAccountStream,
|
||||
Headers: headers,
|
||||
Result: &resp,
|
||||
Verbose: e.Verbose,
|
||||
HTTPDebugging: e.HTTPDebugging,
|
||||
HTTPRecording: e.HTTPRecording,
|
||||
Method: http.MethodPost,
|
||||
Path: endpointPath + userAccountStream,
|
||||
Headers: headers,
|
||||
Result: &resp,
|
||||
Verbose: e.Verbose,
|
||||
HTTPDebugging: e.HTTPDebugging,
|
||||
HTTPRecording: e.HTTPRecording,
|
||||
HTTPMockDataSliceLimit: e.HTTPMockDataSliceLimit,
|
||||
}
|
||||
|
||||
err = e.SendPayload(ctx, request.Unset, func() (*request.Item, error) {
|
||||
@@ -1102,12 +1106,13 @@ func (e *Exchange) MaintainWsAuthStreamKey(ctx context.Context) error {
|
||||
headers := make(map[string]string)
|
||||
headers["X-MBX-APIKEY"] = creds.Key
|
||||
item := &request.Item{
|
||||
Method: http.MethodPut,
|
||||
Path: path,
|
||||
Headers: headers,
|
||||
Verbose: e.Verbose,
|
||||
HTTPDebugging: e.HTTPDebugging,
|
||||
HTTPRecording: e.HTTPRecording,
|
||||
Method: http.MethodPut,
|
||||
Path: path,
|
||||
Headers: headers,
|
||||
Verbose: e.Verbose,
|
||||
HTTPDebugging: e.HTTPDebugging,
|
||||
HTTPRecording: e.HTTPRecording,
|
||||
HTTPMockDataSliceLimit: e.HTTPMockDataSliceLimit,
|
||||
}
|
||||
|
||||
return e.SendPayload(ctx, request.Unset, func() (*request.Item, error) {
|
||||
|
||||
@@ -40,12 +40,10 @@ func TestMain(m *testing.M) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
e.Websocket.DataHandler = sharedtestvalues.GetWebsocketInterfaceChannelOverride()
|
||||
log.Printf(sharedtestvalues.LiveTesting, e.Name)
|
||||
if err := e.UpdateTradablePairs(context.Background(), true); err != nil {
|
||||
log.Fatalf("Binance UpdateTradablePairs error: %s", err)
|
||||
}
|
||||
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
@@ -28,10 +28,8 @@ func TestMain(m *testing.M) {
|
||||
if err := testexch.MockHTTPInstance(e); err != nil {
|
||||
log.Fatalf("Binance MockHTTPInstance error: %s", err)
|
||||
}
|
||||
|
||||
if err := e.UpdateTradablePairs(context.Background(), true); err != nil {
|
||||
log.Fatalf("Binance UpdateTradablePairs error: %s", err)
|
||||
}
|
||||
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
@@ -1091,7 +1091,7 @@ func TestGetExchangeInfo(t *testing.T) {
|
||||
info, err := e.GetExchangeInfo(t.Context())
|
||||
require.NoError(t, err, "GetExchangeInfo must not error")
|
||||
if mockTests {
|
||||
exp := time.Date(2024, 5, 10, 6, 8, 1, int(707*time.Millisecond), time.UTC)
|
||||
exp := time.Date(2025, 8, 7, 21, 55, 41, int(167*time.Millisecond), time.UTC)
|
||||
assert.Truef(t, info.ServerTime.Time().Equal(exp), "expected %v received %v", exp.UTC(), info.ServerTime.Time().UTC())
|
||||
} else {
|
||||
assert.WithinRange(t, info.ServerTime.Time(), time.Now().Add(-24*time.Hour), time.Now().Add(24*time.Hour), "ServerTime should be within a day of now")
|
||||
@@ -2034,7 +2034,7 @@ func TestSubscribeBadResp(t *testing.T) {
|
||||
|
||||
func TestWsTickerUpdate(t *testing.T) {
|
||||
t.Parallel()
|
||||
pressXToJSON := []byte(`{"stream":"btcusdt@ticker","data":{"e":"24hrTicker","E":1580254809477,"s":"BTCUSDT","p":"420.97000000","P":"4.720","w":"9058.27981278","x":"8917.98000000","c":"9338.96000000","Q":"0.17246300","b":"9338.03000000","B":"0.18234600","a":"9339.70000000","A":"0.14097600","o":"8917.99000000","h":"9373.19000000","l":"8862.40000000","v":"72229.53692000","q":"654275356.16896672","O":1580168409456,"C":1580254809456,"F":235294268,"L":235894703,"n":600436}}`)
|
||||
pressXToJSON := []byte(`{"stream":"btcusdt@ticker","data":{"e":"24hrTicker","E":1580254809477,"s":"ETHBTC","p":"420.97000000","P":"4.720","w":"9058.27981278","x":"8917.98000000","c":"9338.96000000","Q":"0.17246300","b":"9338.03000000","B":"0.18234600","a":"9339.70000000","A":"0.14097600","o":"8917.99000000","h":"9373.19000000","l":"8862.40000000","v":"72229.53692000","q":"654275356.16896672","O":1580168409456,"C":1580254809456,"F":235294268,"L":235894703,"n":600436}}`)
|
||||
err := e.wsHandleData(pressXToJSON)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
@@ -2046,7 +2046,7 @@ func TestWsKlineUpdate(t *testing.T) {
|
||||
pressXToJSON := []byte(`{"stream":"btcusdt@kline_1m","data":{
|
||||
"e": "kline",
|
||||
"E": 1234567891,
|
||||
"s": "BTCUSDT",
|
||||
"s": "ETHBTC",
|
||||
"k": {
|
||||
"t": 1234000001,
|
||||
"T": 1234600001,
|
||||
@@ -2079,7 +2079,7 @@ func TestWsTradeUpdate(t *testing.T) {
|
||||
pressXToJSON := []byte(`{"stream":"btcusdt@trade","data":{
|
||||
"e": "trade",
|
||||
"E": 1234567891,
|
||||
"s": "BTCUSDT",
|
||||
"s": "ETHBTC",
|
||||
"t": 12345,
|
||||
"p": "0.001",
|
||||
"q": "100",
|
||||
@@ -2321,7 +2321,11 @@ func TestGetHistoricCandles(t *testing.T) {
|
||||
}
|
||||
|
||||
startTime = time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||
_, err := e.GetHistoricCandles(t.Context(), currency.NewBTCUSDT(), asset.Spot, kline.Interval(time.Hour*7), startTime, end)
|
||||
|
||||
enabledPairs, err := e.GetEnabledPairs(asset.Spot)
|
||||
require.NoError(t, err, "GetEnabledPairs must not error")
|
||||
|
||||
_, err = e.GetHistoricCandles(t.Context(), enabledPairs[0], asset.Spot, kline.Interval(time.Hour*7), startTime, end)
|
||||
require.ErrorIs(t, err, kline.ErrRequestExceedsExchangeLimits)
|
||||
}
|
||||
|
||||
@@ -2760,9 +2764,11 @@ func TestFetchExchangeLimits(t *testing.T) {
|
||||
|
||||
func TestUpdateOrderExecutionLimits(t *testing.T) {
|
||||
t.Parallel()
|
||||
spotEnabled, err := e.GetEnabledPairs(asset.Spot)
|
||||
require.NoError(t, err, "GetEnabledPairs must not error")
|
||||
|
||||
tests := map[asset.Item]currency.Pair{
|
||||
asset.Spot: currency.NewBTCUSDT(),
|
||||
asset.Spot: spotEnabled[0],
|
||||
asset.Margin: currency.NewPair(currency.ETH, currency.BTC),
|
||||
}
|
||||
for _, a := range []asset.Item{asset.CoinMarginedFutures, asset.USDTMarginedFutures} {
|
||||
|
||||
506735
exchanges/binance/testdata/http.json
vendored
506735
exchanges/binance/testdata/http.json
vendored
File diff suppressed because it is too large
Load Diff
10
exchanges/binance/testdata/wsHandleData.json
vendored
10
exchanges/binance/testdata/wsHandleData.json
vendored
@@ -1,8 +1,8 @@
|
||||
{"stream":"btcusdt@ticker","data":{"e":"24hrTicker","E":1580254809477,"s":"BTCUSDT","p":"420.97000000","P":"4.720","w":"9058.27981278","x":"8917.98000000","c":"9338.96000000","Q":"0.17246300","b":"9338.03000000","B":"0.18234600","a":"9339.70000000","A":"0.14097600","o":"8917.99000000","h":"9373.19000000","l":"8862.40000000","v":"72229.53692000","q":"654275356.16896672","O":1580168409456,"C":1580254809456,"F":235294268,"L":235894703,"n":600436}}
|
||||
{"stream":"btcusdt@kline_1m","data":{"e": "kline","E": 123456789,"s": "BTCUSDT","k": {"t": 123400000,"T": 123460000,"s": "BTCUSDT","i": "1m","f": 100,"L": 200,"o": "0.0010","c": "0.0020","h": "0.0025","l": "0.0015","v": "1000","n": 100,"x": false,"q": "1.0000","V": "500","Q": "0.500","B": "123456"}}}
|
||||
{"stream":"btcusdt@trade","data":{"e": "trade","E": 123456789,"s": "BTCUSDT","t": 12345,"p": "0.001","q": "100","b": 88,"a": 50,"T": 123456785,"m": true,"M": true}}
|
||||
{"stream":"btcusdt@depth","data":{"e": "depthUpdate","E": 123456788,"s": "BTCUSDT","U": 157,"u": 160,"b": [["6621.45", "0.3"]],"a": [["6622.46", "1.5"]]}}
|
||||
{"stream":"BNBBTC@ticker","data":{"e":"24hrTicker","E":1580254809477,"s":"BNBBTC","p":"420.97000000","P":"4.720","w":"9058.27981278","x":"8917.98000000","c":"9338.96000000","Q":"0.17246300","b":"9338.03000000","B":"0.18234600","a":"9339.70000000","A":"0.14097600","o":"8917.99000000","h":"9373.19000000","l":"8862.40000000","v":"72229.53692000","q":"654275356.16896672","O":1580168409456,"C":1580254809456,"F":235294268,"L":235894703,"n":600436}}
|
||||
{"stream":"BNBBTC@kline_1m","data":{"e": "kline","E": 1234567880,"s": "BNBBTC","k": {"t": 1234000000,"T": 1234600000,"s": "BNBBTC","i": "1m","f": 100,"L": 200,"o": "0.0010","c": "0.0020","h": "0.0025","l": "0.0015","v": "1000","n": 100,"x": false,"q": "1.0000","V": "500","Q": "0.500","B": "123456"}}}
|
||||
{"stream":"BNBBTC@trade","data":{"e": "trade","E": 1234567880,"s": "BNBBTC","t": 12345,"p": "0.001","q": "100","b": 88,"a": 50,"T": 123456785,"m": true,"M": true}}
|
||||
{"stream":"BNBBTC@depth","data":{"e": "depthUpdate","E": 1234567880,"s": "BNBBTC","U": 157,"u": 160,"b": [["6621.45", "0.3"]],"a": [["6622.46", "1.5"]]}}
|
||||
{"stream":"jTfvpakT2yT0hVIo5gYWVihZhdM2PrBgJUZ5PyfZ4EVpCkx4Uoxk5timcrQc","data":{"e": "balanceUpdate","E": 1573200697110,"a": "BTC","d": "100.00000000","T": 1573200697068}}
|
||||
{"stream":"jTfvpakT2yT0hVIo5gYWVihZhdM2PrBgJUZ5PyfZ4EVpCkx4Uoxk5timcrQc","data":{"e": "listStatus","E": 1564035303637,"s": "ETHBTC","g": 2,"c": "OCO","l": "EXEC_STARTED","L": "EXECUTING","r": "NONE","C": "F4QN4G8DlFATFlIUQ0cjdD","T": 1564035303625,"O": [{"s": "ETHBTC","i": 17,"c": "AJYsMjErWJesZvqlJCTUgL"},{"s": "ETHBTC","i": 18,"c": "bfYPSQdLoqAJeNrOr9adzq"}]}}
|
||||
{"stream":"jTfvpakT2yT0hVIo5gYWVihZhdM2PrBgJUZ5PyfZ4EVpCkx4Uoxk5timcrQc","data":{"e":"executionReport","E":1616627567900,"s":"BTCUSDT","c":"c4wyKsIhoAaittTYlIVLqk","S":"BUY","o":"LIMIT","f":"GTC","q":"0.00028400","p":"52789.10000000","P":"0.00000000","F":"0.00000000","g":-1,"C":"","x":"NEW","X":"NEW","r":"NONE","i":5340845958,"l":"0.00000000","z":"0.00000000","L":"0.00000000","n":"0","N":"BTC","T":1616627567900,"t":-1,"I":11388173160,"w":true,"m":false,"M":false,"O":1616627567900,"Z":"0.00000000","Y":"0.00000000","Q":"0.00000000","W":1616627567900}}
|
||||
{"stream":"jTfvpakT2yT0hVIo5gYWVihZhdM2PrBgJUZ5PyfZ4EVpCkx4Uoxk5timcrQc","data":{"e":"executionReport","E":1616627567900,"s":"BNBBTC","c":"c4wyKsIhoAaittTYlIVLqk","S":"BUY","o":"LIMIT","f":"GTC","q":"0.00028400","p":"52789.10000000","P":"0.00000000","F":"0.00000000","g":-1,"C":"","x":"NEW","X":"NEW","r":"NONE","i":5340845958,"l":"0.00000000","z":"0.00000000","L":"0.00000000","n":"0","N":"BTC","T":1616627567900,"t":-1,"I":11388173160,"w":true,"m":false,"M":false,"O":1616627567900,"Z":"0.00000000","Y":"0.00000000","Q":"0.00000000","W":1616627567900}}
|
||||
{"stream":"jTfvpakT2yT0hVIo5gYWVihZhdM2PrBgJUZ5PyfZ4EVpCkx4Uoxk5timcrQc","data":{"e":"outboundAccountPosition","E":1616628815745,"u":1616628815745,"B":[{"a":"BTC","f":"0.00225109","l":"0.00123000"},{"a":"BNB","f":"0.00000000","l":"0.00000000"},{"a":"USDT","f":"54.43390661","l":"0.00000000"}]}}
|
||||
Reference in New Issue
Block a user