/
FeeInfo.go
41 lines (33 loc) · 983 Bytes
/
FeeInfo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright 2020 Condensat Tech. All rights reserved.
// Use of this source code is governed by a MIT
// license that can be found in the LICENSE file.
package model
import (
"github.com/condensat/bank-core/database"
"github.com/condensat/bank-core/database/utils"
)
const DefaultFeeRate = Float(0.001) // 0.1%
type FeeInfo struct {
Currency CurrencyName `gorm:"primary_key"` // [PK] Related currency
Minimum Float `gorm:"default:0.0;not null"` // Minimum Fee
Rate Float `gorm:"default:0.001;not null"` // Percent Fee Rate (default 0.1%)
}
func (p *FeeInfo) IsValid() bool {
return len(p.Currency) > 0 &&
p.Minimum >= 0.0 &&
p.Rate >= 0.0
}
func (p *FeeInfo) Compute(amount Float) Float {
if !p.IsValid() {
return 0.0
}
if amount <= 0.0 {
return 0.0
}
fees := amount * p.Rate
if fees < p.Minimum {
fees = p.Minimum
}
fees = Float(utils.ToFixed(float64(fees), database.DatabaseFloatingPrecision))
return Float(fees)
}