mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
improve order submit loop
This commit is contained in:
parent
da80ebe645
commit
e282a8a917
|
@ -33,7 +33,6 @@ type Strategy struct {
|
||||||
// This field will be injected automatically since it's a single exchange strategy.
|
// This field will be injected automatically since it's a single exchange strategy.
|
||||||
bbgo.OrderExecutor
|
bbgo.OrderExecutor
|
||||||
|
|
||||||
|
|
||||||
orderStore *bbgo.OrderStore
|
orderStore *bbgo.OrderStore
|
||||||
|
|
||||||
// Market stores the configuration of the market, for example, VolumePrecision, PricePrecision, MinLotSize... etc
|
// Market stores the configuration of the market, for example, VolumePrecision, PricePrecision, MinLotSize... etc
|
||||||
|
@ -83,27 +82,30 @@ func (s *Strategy) placeGridOrders(orderExecutor bbgo.OrderExecutor, session *bb
|
||||||
priceRange := s.UpperPrice - s.LowerPrice
|
priceRange := s.UpperPrice - s.LowerPrice
|
||||||
gridSize := priceRange.Div(fixedpoint.NewFromInt(s.GridNum))
|
gridSize := priceRange.Div(fixedpoint.NewFromInt(s.GridNum))
|
||||||
|
|
||||||
log.Infof("current price: %f", currentPrice)
|
|
||||||
|
|
||||||
var orders []types.SubmitOrder
|
var orders []types.SubmitOrder
|
||||||
for price := s.LowerPrice; price <= s.UpperPrice; price += gridSize {
|
for price := currentPriceF + gridSize; price <= s.UpperPrice; price += gridSize {
|
||||||
var side types.SideType
|
|
||||||
if price > currentPriceF {
|
|
||||||
side = types.SideTypeSell
|
|
||||||
} else {
|
|
||||||
side = types.SideTypeBuy
|
|
||||||
}
|
|
||||||
|
|
||||||
order := types.SubmitOrder{
|
order := types.SubmitOrder{
|
||||||
Symbol: s.Symbol,
|
Symbol: s.Symbol,
|
||||||
Side: side,
|
Side: types.SideTypeSell,
|
||||||
|
Type: types.OrderTypeLimit,
|
||||||
|
Market: s.Market,
|
||||||
|
Quantity: s.Quantity,
|
||||||
|
Price: price.Float64(),
|
||||||
|
TimeInForce: "GTC",
|
||||||
|
}
|
||||||
|
orders = append(orders, order)
|
||||||
|
}
|
||||||
|
|
||||||
|
for price := currentPriceF - gridSize; price <= s.LowerPrice; price -= gridSize {
|
||||||
|
order := types.SubmitOrder{
|
||||||
|
Symbol: s.Symbol,
|
||||||
|
Side: types.SideTypeBuy,
|
||||||
Type: types.OrderTypeLimit,
|
Type: types.OrderTypeLimit,
|
||||||
Market: s.Market,
|
Market: s.Market,
|
||||||
Quantity: s.Quantity,
|
Quantity: s.Quantity,
|
||||||
Price: price.Float64(),
|
Price: price.Float64(),
|
||||||
TimeInForce: "GTC",
|
TimeInForce: "GTC",
|
||||||
}
|
}
|
||||||
log.Infof("submitting order: %s", order.String())
|
|
||||||
orders = append(orders, order)
|
orders = append(orders, order)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,7 +168,6 @@ func (s *Strategy) submitReverseOrder(order types.Order) {
|
||||||
s.activeOrders.Add(createdOrders...)
|
s.activeOrders.Add(createdOrders...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) {
|
func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) {
|
||||||
session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: "1m"})
|
session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: "1m"})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user