bbgo: add comments to the quota methods
This commit is contained in:
parent
cee99956ff
commit
ca847047ac
|
@ -12,12 +12,16 @@ type Quota struct {
|
||||||
Locked fixedpoint.Value
|
Locked fixedpoint.Value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add adds the fund to the available quota
|
||||||
func (q *Quota) Add(fund fixedpoint.Value) {
|
func (q *Quota) Add(fund fixedpoint.Value) {
|
||||||
q.mu.Lock()
|
q.mu.Lock()
|
||||||
q.Available = q.Available.Add(fund)
|
q.Available = q.Available.Add(fund)
|
||||||
q.mu.Unlock()
|
q.mu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Lock locks the fund from the available quota
|
||||||
|
// returns true if the fund is locked successfully
|
||||||
|
// returns false if the fund is not enough
|
||||||
func (q *Quota) Lock(fund fixedpoint.Value) bool {
|
func (q *Quota) Lock(fund fixedpoint.Value) bool {
|
||||||
if fund.Compare(q.Available) > 0 {
|
if fund.Compare(q.Available) > 0 {
|
||||||
return false
|
return false
|
||||||
|
@ -31,12 +35,15 @@ func (q *Quota) Lock(fund fixedpoint.Value) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Commit commits the locked fund
|
||||||
func (q *Quota) Commit() {
|
func (q *Quota) Commit() {
|
||||||
q.mu.Lock()
|
q.mu.Lock()
|
||||||
q.Locked = fixedpoint.Zero
|
q.Locked = fixedpoint.Zero
|
||||||
q.mu.Unlock()
|
q.mu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Rollback rolls back the locked fund
|
||||||
|
// this will move the locked fund to the available quota
|
||||||
func (q *Quota) Rollback() {
|
func (q *Quota) Rollback() {
|
||||||
q.mu.Lock()
|
q.mu.Lock()
|
||||||
q.Available = q.Available.Add(q.Locked)
|
q.Available = q.Available.Add(q.Locked)
|
||||||
|
@ -44,12 +51,14 @@ func (q *Quota) Rollback() {
|
||||||
q.mu.Unlock()
|
q.mu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// QuotaTransaction is a transactional quota manager
|
||||||
type QuotaTransaction struct {
|
type QuotaTransaction struct {
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
BaseAsset Quota
|
BaseAsset Quota
|
||||||
QuoteAsset Quota
|
QuoteAsset Quota
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Commit commits the transaction
|
||||||
func (m *QuotaTransaction) Commit() bool {
|
func (m *QuotaTransaction) Commit() bool {
|
||||||
m.mu.Lock()
|
m.mu.Lock()
|
||||||
m.BaseAsset.Commit()
|
m.BaseAsset.Commit()
|
||||||
|
@ -58,6 +67,7 @@ func (m *QuotaTransaction) Commit() bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Rollback rolls back the transaction
|
||||||
func (m *QuotaTransaction) Rollback() bool {
|
func (m *QuotaTransaction) Rollback() bool {
|
||||||
m.mu.Lock()
|
m.mu.Lock()
|
||||||
m.BaseAsset.Rollback()
|
m.BaseAsset.Rollback()
|
||||||
|
|
|
@ -504,6 +504,8 @@ func (s *Strategy) updateQuote(ctx context.Context) {
|
||||||
s.logger.Infof("%s maker bid disabled: quote balance %s not found", s.Symbol, b.String())
|
s.logger.Infof("%s maker bid disabled: quote balance %s not found", s.Symbol, b.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s.logger.Infof("maker quota: %+v", makerQuota)
|
||||||
|
|
||||||
// if
|
// if
|
||||||
// 1) the source session is a margin session
|
// 1) the source session is a margin session
|
||||||
// 2) the min margin level is configured
|
// 2) the min margin level is configured
|
||||||
|
|
Loading…
Reference in New Issue
Block a user