Skip to content

Commit

Permalink
Trade stack synchronization added
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyMashukov committed Mar 13, 2024
1 parent b19d77a commit ac48437
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/config/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ func InitServiceContainer() Container {
PriceCalculator: &priceCalculator,
RDB: rdb,
Ctx: &ctx,
Lock: &sync.Mutex{},
}

orderExecutor := exchange.OrderExecutor{
Expand Down
5 changes: 5 additions & 0 deletions src/service/exchange/trade_stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"gitlab.com/open-soft/go-crypto-bot/src/service"
"gitlab.com/open-soft/go-crypto-bot/src/utils"
"sort"
"sync"
"time"
)

Expand All @@ -28,6 +29,7 @@ type TradeStack struct {
PriceCalculator PriceCalculatorInterface
RDB *redis.Client
Ctx *context.Context
Lock *sync.Mutex
}

type TradeStackParams struct {
Expand Down Expand Up @@ -69,6 +71,9 @@ func (t *TradeStack) CanBuy(limit model.TradeLimit) bool {
}

func (t *TradeStack) GetTradeStack(params TradeStackParams) []model.TradeStackItem {
t.Lock.Lock()
defer t.Lock.Unlock()

balanceUsdt, err := t.BalanceService.GetAssetBalance("USDT", true)
stack := make([]model.TradeStackItem, 0)

Expand Down

0 comments on commit ac48437

Please sign in to comment.