mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
bugfixes: Backtester credentials, Binance ExecutionLimits, Mock recording (#1539)
* fix mock recording, binance, backtester * minor credential streamlining
This commit is contained in:
@@ -1233,46 +1233,46 @@ func (b *Binance) FetchExchangeLimits(ctx context.Context, a asset.Item) ([]orde
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !slices.Contains(s.Permissions, aUpper) {
|
||||
continue
|
||||
}
|
||||
|
||||
l := order.MinMaxLevel{
|
||||
Pair: cp,
|
||||
Asset: a,
|
||||
}
|
||||
|
||||
for _, f := range s.Filters {
|
||||
// TODO: Unhandled filters:
|
||||
// maxPosition, trailingDelta, percentPriceBySide, maxNumAlgoOrders
|
||||
switch f.FilterType {
|
||||
case priceFilter:
|
||||
l.MinPrice = f.MinPrice
|
||||
l.MaxPrice = f.MaxPrice
|
||||
l.PriceStepIncrementSize = f.TickSize
|
||||
case percentPriceFilter:
|
||||
l.MultiplierUp = f.MultiplierUp
|
||||
l.MultiplierDown = f.MultiplierDown
|
||||
l.AveragePriceMinutes = f.AvgPriceMinutes
|
||||
case lotSizeFilter:
|
||||
l.MaximumBaseAmount = f.MaxQty
|
||||
l.MinimumBaseAmount = f.MinQty
|
||||
l.AmountStepIncrementSize = f.StepSize
|
||||
case notionalFilter:
|
||||
l.MinNotional = f.MinNotional
|
||||
case icebergPartsFilter:
|
||||
l.MaxIcebergParts = f.Limit
|
||||
case marketLotSizeFilter:
|
||||
l.MarketMinQty = f.MinQty
|
||||
l.MarketMaxQty = f.MaxQty
|
||||
l.MarketStepIncrementSize = f.StepSize
|
||||
case maxNumOrdersFilter:
|
||||
l.MaxTotalOrders = f.MaxNumOrders
|
||||
l.MaxAlgoOrders = f.MaxNumAlgoOrders
|
||||
for i := range s.PermissionSets {
|
||||
if !slices.Contains(s.PermissionSets[i], aUpper) {
|
||||
continue
|
||||
}
|
||||
l := order.MinMaxLevel{
|
||||
Pair: cp,
|
||||
Asset: a,
|
||||
}
|
||||
for _, f := range s.Filters {
|
||||
// TODO: Unhandled filters:
|
||||
// maxPosition, trailingDelta, percentPriceBySide, maxNumAlgoOrders
|
||||
switch f.FilterType {
|
||||
case priceFilter:
|
||||
l.MinPrice = f.MinPrice
|
||||
l.MaxPrice = f.MaxPrice
|
||||
l.PriceStepIncrementSize = f.TickSize
|
||||
case percentPriceFilter:
|
||||
l.MultiplierUp = f.MultiplierUp
|
||||
l.MultiplierDown = f.MultiplierDown
|
||||
l.AveragePriceMinutes = f.AvgPriceMinutes
|
||||
case lotSizeFilter:
|
||||
l.MaximumBaseAmount = f.MaxQty
|
||||
l.MinimumBaseAmount = f.MinQty
|
||||
l.AmountStepIncrementSize = f.StepSize
|
||||
case notionalFilter:
|
||||
l.MinNotional = f.MinNotional
|
||||
case icebergPartsFilter:
|
||||
l.MaxIcebergParts = f.Limit
|
||||
case marketLotSizeFilter:
|
||||
l.MarketMinQty = f.MinQty
|
||||
l.MarketMaxQty = f.MaxQty
|
||||
l.MarketStepIncrementSize = f.StepSize
|
||||
case maxNumOrdersFilter:
|
||||
l.MaxTotalOrders = f.MaxNumOrders
|
||||
l.MaxAlgoOrders = f.MaxNumAlgoOrders
|
||||
}
|
||||
}
|
||||
limits = append(limits, l)
|
||||
break
|
||||
}
|
||||
|
||||
limits = append(limits, l)
|
||||
}
|
||||
return limits, nil
|
||||
}
|
||||
|
||||
@@ -1085,8 +1085,8 @@ func TestGetExchangeInfo(t *testing.T) {
|
||||
info, err := b.GetExchangeInfo(context.Background())
|
||||
require.NoError(t, err, "GetExchangeInfo must not error")
|
||||
if mockTests {
|
||||
exp := time.Date(2022, 2, 25, 3, 50, 40, int(601*time.Millisecond), time.UTC)
|
||||
assert.True(t, info.ServerTime.Equal(exp), "ServerTime should be correct")
|
||||
exp := time.Date(2024, 5, 10, 6, 8, 1, int(707*time.Millisecond), time.UTC)
|
||||
assert.True(t, info.ServerTime.Equal(exp), "expected %v received %v", exp.UTC(), info.ServerTime.UTC())
|
||||
} else {
|
||||
assert.WithinRange(t, info.ServerTime, time.Now().Add(-24*time.Hour), time.Now().Add(24*time.Hour), "ServerTime should be within a day of now")
|
||||
}
|
||||
|
||||
@@ -65,6 +65,7 @@ type ExchangeInfo struct {
|
||||
IsMarginTradingAllowed bool `json:"isMarginTradingAllowed"`
|
||||
Filters []*filterData `json:"filters"`
|
||||
Permissions []string `json:"permissions"`
|
||||
PermissionSets [][]string `json:"permissionSets"`
|
||||
} `json:"symbols"`
|
||||
}
|
||||
|
||||
|
||||
230277
exchanges/binance/testdata/http.json
vendored
230277
exchanges/binance/testdata/http.json
vendored
File diff suppressed because it is too large
Load Diff
@@ -47,9 +47,21 @@ func HTTPRecord(res *http.Response, service string, respContents []byte) error {
|
||||
}
|
||||
service = strings.ToLower(service)
|
||||
|
||||
fileout := filepath.Join(DefaultDirectory, service, service+".json")
|
||||
outputFilePath := filepath.Join(DefaultDirectory, service, service+".json")
|
||||
_, err := os.Stat(outputFilePath)
|
||||
if err != nil {
|
||||
if os.IsExist(err) {
|
||||
return err
|
||||
}
|
||||
// check alternative path to add compatibility with /internal/testing/exchange/exchange.go MockHTTPInstance
|
||||
outputFilePath = filepath.Join("..", service, "testdata", "http.json")
|
||||
_, err = os.Stat(outputFilePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
contents, err := os.ReadFile(fileout)
|
||||
contents, err := os.ReadFile(outputFilePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -227,7 +239,7 @@ func HTTPRecord(res *http.Response, service string, respContents []byte) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return file.Write(fileout, payload)
|
||||
return file.Write(outputFilePath, payload)
|
||||
}
|
||||
|
||||
// GetFilteredHeader filters excluded http headers for insertion into a mock
|
||||
|
||||
@@ -25,10 +25,10 @@ import (
|
||||
const (
|
||||
// WebsocketResponseDefaultTimeout used in websocket testing
|
||||
// Defines wait time for receiving websocket response before cancelling
|
||||
WebsocketResponseDefaultTimeout = (3 * time.Second)
|
||||
WebsocketResponseDefaultTimeout = 3 * time.Second
|
||||
// WebsocketResponseExtendedTimeout used in websocket testing
|
||||
// Defines wait time for receiving websocket response before cancelling
|
||||
WebsocketResponseExtendedTimeout = (15 * time.Second)
|
||||
WebsocketResponseExtendedTimeout = 15 * time.Second
|
||||
// WebsocketChannelOverrideCapacity used in websocket testing
|
||||
// Defines channel capacity as defaults size can block tests
|
||||
WebsocketChannelOverrideCapacity = 500
|
||||
|
||||
Reference in New Issue
Block a user