mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 08:45:16 +00:00
xfunding: pull out newState constructor
This commit is contained in:
parent
36836c7c79
commit
a3f96871e2
|
@ -82,6 +82,15 @@ type State struct {
|
||||||
UsedQuoteInvestment fixedpoint.Value `json:"usedQuoteInvestment"`
|
UsedQuoteInvestment fixedpoint.Value `json:"usedQuoteInvestment"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newState() *State {
|
||||||
|
return &State{
|
||||||
|
PositionState: PositionClosed,
|
||||||
|
PendingBaseTransfer: fixedpoint.Zero,
|
||||||
|
TotalBaseTransfer: fixedpoint.Zero,
|
||||||
|
UsedQuoteInvestment: fixedpoint.Zero,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (s *State) Reset() {
|
func (s *State) Reset() {
|
||||||
s.PositionState = PositionClosed
|
s.PositionState = PositionClosed
|
||||||
s.PendingBaseTransfer = fixedpoint.Zero
|
s.PendingBaseTransfer = fixedpoint.Zero
|
||||||
|
@ -246,6 +255,15 @@ func (s *Strategy) CrossRun(ctx context.Context, orderExecutionRouter bbgo.Order
|
||||||
s.spotMarket, _ = s.spotSession.Market(s.Symbol)
|
s.spotMarket, _ = s.spotSession.Market(s.Symbol)
|
||||||
s.futuresMarket, _ = s.futuresSession.Market(s.Symbol)
|
s.futuresMarket, _ = s.futuresSession.Market(s.Symbol)
|
||||||
|
|
||||||
|
binanceFutures, ok := s.futuresSession.Exchange.(*binance.Exchange)
|
||||||
|
if !ok {
|
||||||
|
return errNotBinanceExchange
|
||||||
|
}
|
||||||
|
binanceSpot, ok := s.spotSession.Exchange.(*binance.Exchange)
|
||||||
|
if !ok {
|
||||||
|
return errNotBinanceExchange
|
||||||
|
}
|
||||||
|
|
||||||
// adjust QuoteInvestment
|
// adjust QuoteInvestment
|
||||||
if b, ok := s.spotSession.Account.Balance(s.spotMarket.QuoteCurrency); ok {
|
if b, ok := s.spotSession.Account.Balance(s.spotMarket.QuoteCurrency); ok {
|
||||||
originalQuoteInvestment := s.QuoteInvestment
|
originalQuoteInvestment := s.QuoteInvestment
|
||||||
|
@ -284,26 +302,12 @@ func (s *Strategy) CrossRun(ctx context.Context, orderExecutionRouter bbgo.Order
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.State == nil || s.Reset {
|
if s.State == nil || s.Reset {
|
||||||
s.State = &State{
|
s.State = newState()
|
||||||
PositionState: PositionClosed,
|
|
||||||
PendingBaseTransfer: fixedpoint.Zero,
|
|
||||||
TotalBaseTransfer: fixedpoint.Zero,
|
|
||||||
UsedQuoteInvestment: fixedpoint.Zero,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("loaded spot position: %s", s.SpotPosition.String())
|
log.Infof("loaded spot position: %s", s.SpotPosition.String())
|
||||||
log.Infof("loaded futures position: %s", s.FuturesPosition.String())
|
log.Infof("loaded futures position: %s", s.FuturesPosition.String())
|
||||||
|
|
||||||
binanceFutures, ok := s.futuresSession.Exchange.(*binance.Exchange)
|
|
||||||
if !ok {
|
|
||||||
return errNotBinanceExchange
|
|
||||||
}
|
|
||||||
binanceSpot, ok := s.spotSession.Exchange.(*binance.Exchange)
|
|
||||||
if !ok {
|
|
||||||
return errNotBinanceExchange
|
|
||||||
}
|
|
||||||
|
|
||||||
s.spotOrderExecutor = s.allocateOrderExecutor(ctx, s.spotSession, instanceID, s.SpotPosition)
|
s.spotOrderExecutor = s.allocateOrderExecutor(ctx, s.spotSession, instanceID, s.SpotPosition)
|
||||||
s.spotOrderExecutor.TradeCollector().OnTrade(func(trade types.Trade, profit fixedpoint.Value, netProfit fixedpoint.Value) {
|
s.spotOrderExecutor.TradeCollector().OnTrade(func(trade types.Trade, profit fixedpoint.Value, netProfit fixedpoint.Value) {
|
||||||
// we act differently on the spot account
|
// we act differently on the spot account
|
||||||
|
|
Loading…
Reference in New Issue
Block a user