mirror of
https://github.com/c9s/bbgo.git
synced 2024-09-20 08:11:08 +00:00
Merge pull request #1585 from c9s/c9s/fix-xalign-side-for-reversed-quote
FIX: [xalign] fix reversed market
This commit is contained in:
commit
d3a1a973b6
|
@ -90,7 +90,9 @@ func (s *Strategy) Validate() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *Strategy) aggregateBalances(ctx context.Context, sessions map[string]*bbgo.ExchangeSession) (totalBalances types.BalanceMap, sessionBalances map[string]types.BalanceMap) {
|
||||
func (s *Strategy) aggregateBalances(
|
||||
ctx context.Context, sessions map[string]*bbgo.ExchangeSession,
|
||||
) (totalBalances types.BalanceMap, sessionBalances map[string]types.BalanceMap) {
|
||||
totalBalances = make(types.BalanceMap)
|
||||
sessionBalances = make(map[string]types.BalanceMap)
|
||||
|
||||
|
@ -112,7 +114,9 @@ func (s *Strategy) aggregateBalances(ctx context.Context, sessions map[string]*b
|
|||
return totalBalances, sessionBalances
|
||||
}
|
||||
|
||||
func (s *Strategy) selectSessionForCurrency(ctx context.Context, sessions map[string]*bbgo.ExchangeSession, currency string, changeQuantity fixedpoint.Value) (*bbgo.ExchangeSession, *types.SubmitOrder) {
|
||||
func (s *Strategy) selectSessionForCurrency(
|
||||
ctx context.Context, sessions map[string]*bbgo.ExchangeSession, currency string, changeQuantity fixedpoint.Value,
|
||||
) (*bbgo.ExchangeSession, *types.SubmitOrder) {
|
||||
for _, sessionName := range s.PreferredSessions {
|
||||
session := sessions[sessionName]
|
||||
|
||||
|
@ -128,12 +132,26 @@ func (s *Strategy) selectSessionForCurrency(ctx context.Context, sessions map[st
|
|||
}
|
||||
|
||||
for _, quoteCurrency := range quoteCurrencies {
|
||||
// skip the same currency, because there is no such USDT/USDT market
|
||||
if currency == quoteCurrency {
|
||||
continue
|
||||
}
|
||||
|
||||
// check both quoteCurrency/currency and currency/quoteCurrency
|
||||
symbol := currency + quoteCurrency
|
||||
market, ok := session.Market(symbol)
|
||||
if !ok {
|
||||
// for TWD in USDT/TWD market, buy TWD means sell USDT
|
||||
symbol = quoteCurrency + currency
|
||||
market, ok = session.Market(symbol)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
// reverse side
|
||||
side = side.Reverse()
|
||||
}
|
||||
|
||||
ticker, err := session.Exchange.QueryTicker(ctx, symbol)
|
||||
if err != nil {
|
||||
log.WithError(err).Errorf("unable to query ticker on %s", symbol)
|
||||
|
@ -376,7 +394,9 @@ func (s *Strategy) align(ctx context.Context, sessions map[string]*bbgo.Exchange
|
|||
}
|
||||
}
|
||||
|
||||
func (s *Strategy) calculateRefillQuantity(totalBalances types.BalanceMap, currency string, expectedBalance fixedpoint.Value) fixedpoint.Value {
|
||||
func (s *Strategy) calculateRefillQuantity(
|
||||
totalBalances types.BalanceMap, currency string, expectedBalance fixedpoint.Value,
|
||||
) fixedpoint.Value {
|
||||
if b, ok := totalBalances[currency]; ok {
|
||||
netBalance := b.Net()
|
||||
return expectedBalance.Sub(netBalance)
|
||||
|
|
Loading…
Reference in New Issue
Block a user