mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
backtest: check quoteQuantity only when price is given
This commit is contained in:
parent
adc2216e1f
commit
f06ec76618
|
@ -43,6 +43,8 @@ const parseOrder = () => {
|
||||||
case "quantity":
|
case "quantity":
|
||||||
d[key] = +d[key];
|
d[key] = +d[key];
|
||||||
break;
|
break;
|
||||||
|
case "update_time":
|
||||||
|
case "creation_time":
|
||||||
case "time":
|
case "time":
|
||||||
d[key] = new Date(d[key]);
|
d[key] = new Date(d[key]);
|
||||||
break;
|
break;
|
||||||
|
@ -150,7 +152,7 @@ const ordersToMarkets = (interval, orders) => {
|
||||||
// var markers = [{ time: data[data.length - 48].time, position: 'aboveBar', color: '#f68410', shape: 'circle', text: 'D' }];
|
// var markers = [{ time: data[data.length - 48].time, position: 'aboveBar', color: '#f68410', shape: 'circle', text: 'D' }];
|
||||||
for (let i = 0; i < orders.length; i++) {
|
for (let i = 0; i < orders.length; i++) {
|
||||||
let order = orders[i];
|
let order = orders[i];
|
||||||
let t = order.time.getTime() / 1000.0;
|
let t = order.update_time.getTime() / 1000.0;
|
||||||
let lastMarker = markers.length > 0 ? markers[markers.length - 1] : null;
|
let lastMarker = markers.length > 0 ? markers[markers.length - 1] : null;
|
||||||
if (lastMarker) {
|
if (lastMarker) {
|
||||||
let remainder = lastMarker.time % intervalSecs;
|
let remainder = lastMarker.time % intervalSecs;
|
||||||
|
|
|
@ -31,8 +31,8 @@ backtest:
|
||||||
# for testing max draw down (MDD) at 03-12
|
# for testing max draw down (MDD) at 03-12
|
||||||
# see here for more details
|
# see here for more details
|
||||||
# https://www.investopedia.com/terms/m/maximum-drawdown-mdd.asp
|
# https://www.investopedia.com/terms/m/maximum-drawdown-mdd.asp
|
||||||
startTime: "2022-01-10"
|
startTime: "2022-05-09"
|
||||||
endTime: "2022-01-11"
|
endTime: "2022-05-20"
|
||||||
symbols:
|
symbols:
|
||||||
- BTCUSDT
|
- BTCUSDT
|
||||||
sessions: [binance]
|
sessions: [binance]
|
||||||
|
@ -53,9 +53,9 @@ exchangeStrategies:
|
||||||
# exp:
|
# exp:
|
||||||
# domain: [20_000, 30_000]
|
# domain: [20_000, 30_000]
|
||||||
# range: [0.2, 0.001]
|
# range: [0.2, 0.001]
|
||||||
gridNumber: 100
|
gridNumber: 30
|
||||||
profitSpread: 1000.0 # The profit price spread that you want to add to your sell order when your buy order is executed
|
profitSpread: 1000.0 # The profit price spread that you want to add to your sell order when your buy order is executed
|
||||||
upperPrice: 50_000.0
|
upperPrice: 50_000.0
|
||||||
lowerPrice: 20_000.0
|
lowerPrice: 20_000.0
|
||||||
long: true # The sell order is submitted in the same order amount as the filled corresponding buy order, rather than the same quantity.
|
# long: true # The sell order is submitted in the same order amount as the filled corresponding buy order, rather than the same quantity.
|
||||||
|
|
||||||
|
|
|
@ -118,10 +118,12 @@ func (m *SimplePriceMatching) PlaceOrder(o types.SubmitOrder) (closedOrders *typ
|
||||||
return nil, nil, fmt.Errorf("order quantity %s is less than minQuantity %s, order: %+v", o.Quantity.String(), m.Market.MinQuantity.String(), o)
|
return nil, nil, fmt.Errorf("order quantity %s is less than minQuantity %s, order: %+v", o.Quantity.String(), m.Market.MinQuantity.String(), o)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !price.IsZero() {
|
||||||
quoteQuantity := o.Quantity.Mul(price)
|
quoteQuantity := o.Quantity.Mul(price)
|
||||||
if quoteQuantity.Compare(m.Market.MinNotional) < 0 {
|
if quoteQuantity.Compare(m.Market.MinNotional) < 0 {
|
||||||
return nil, nil, fmt.Errorf("order amount %s is less than minNotional %s, order: %+v", quoteQuantity.String(), m.Market.MinNotional.String(), o)
|
return nil, nil, fmt.Errorf("order amount %s is less than minNotional %s, order: %+v", quoteQuantity.String(), m.Market.MinNotional.String(), o)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch o.Side {
|
switch o.Side {
|
||||||
case types.SideTypeBuy:
|
case types.SideTypeBuy:
|
||||||
|
|
|
@ -220,26 +220,30 @@ type Order struct {
|
||||||
|
|
||||||
func (o Order) CsvHeader() []string {
|
func (o Order) CsvHeader() []string {
|
||||||
return []string{
|
return []string{
|
||||||
"time",
|
|
||||||
"order_id",
|
"order_id",
|
||||||
"symbol",
|
"symbol",
|
||||||
"side",
|
"side",
|
||||||
"order_type",
|
"order_type",
|
||||||
|
"status",
|
||||||
"price",
|
"price",
|
||||||
"quantity",
|
"quantity",
|
||||||
|
"creation_time",
|
||||||
|
"update_time",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o Order) CsvRecords() [][]string {
|
func (o Order) CsvRecords() [][]string {
|
||||||
return [][]string{
|
return [][]string{
|
||||||
{
|
{
|
||||||
o.UpdateTime.Time().UTC().Format(time.RFC1123),
|
|
||||||
strconv.FormatUint(o.OrderID, 10),
|
strconv.FormatUint(o.OrderID, 10),
|
||||||
o.Symbol,
|
o.Symbol,
|
||||||
string(o.Side),
|
string(o.Side),
|
||||||
string(o.Type),
|
string(o.Type),
|
||||||
|
string(o.Status),
|
||||||
o.Price.String(),
|
o.Price.String(),
|
||||||
o.Quantity.String(),
|
o.Quantity.String(),
|
||||||
|
o.CreationTime.Time().UTC().Format(time.RFC1123),
|
||||||
|
o.UpdateTime.Time().UTC().Format(time.RFC1123),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user