xalign: add DryRun and fix quote amount calculation

This commit is contained in:
c9s 2023-06-08 23:15:26 +08:00
parent fb078c9ede
commit 8baafdf329
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -32,6 +32,7 @@ type Strategy struct {
PreferredQuoteCurrencies *QuoteCurrencyPreference `json:"quoteCurrencies"`
ExpectedBalances map[string]fixedpoint.Value `json:"expectedBalances"`
UseTakerOrder bool `json:"useTakerOrder"`
DryRun bool `json:"dryRun"`
orderBook map[string]*bbgo.ActiveOrderBook
}
@ -92,7 +93,7 @@ func (s *Strategy) selectSessionForCurrency(ctx context.Context, sessions map[st
for _, sessionName := range s.PreferredSessions {
session := sessions[sessionName]
var taker bool = s.UseTakerOrder
var taker = s.UseTakerOrder
var side types.SideType
var quoteCurrencies []string
if changeQuantity.Sign() > 0 {
@ -137,7 +138,7 @@ func (s *Strategy) selectSessionForCurrency(ctx context.Context, sessions map[st
price = ticker.Buy
}
requiredQuoteAmount := q.Div(price)
requiredQuoteAmount := q.Mul(price)
if requiredQuoteAmount.Compare(quoteBalance.Available) < 0 {
log.Warnf("required quote amount %f < quote balance %v", requiredQuoteAmount.Float64(), quoteBalance)
continue
@ -250,9 +251,12 @@ func (s *Strategy) align(ctx context.Context, sessions map[string]*bbgo.Exchange
selectedSession, submitOrder := s.selectSessionForCurrency(ctx, sessions, currency, q)
if selectedSession != nil && submitOrder != nil {
log.Infof("placing order on %s: %#v", selectedSession.Name, submitOrder)
if s.DryRun {
return
}
createdOrder, err := selectedSession.Exchange.SubmitOrder(ctx, *submitOrder)
if err != nil {
log.WithError(err).Errorf("can not place order")