mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +00:00
add new test helper to create balance map objects
Signed-off-by: c9s <yoanlin93@gmail.com>
This commit is contained in:
parent
14fa561f6e
commit
8f0d58aee9
|
@ -215,19 +215,19 @@ func Test_usdFiatBalances(t *testing.T) {
|
|||
}{
|
||||
{
|
||||
args: args{
|
||||
balances: types.BalanceMap{
|
||||
"USDC": types.Balance{Currency: "USDC", Available: Number(70.0 + 80.0)},
|
||||
"USDT": types.Balance{Currency: "USDT", Available: Number(100.0)},
|
||||
"BTC": types.Balance{Currency: "BTC", Available: Number(0.01)},
|
||||
},
|
||||
},
|
||||
wantFiats: types.BalanceMap{
|
||||
"USDC": types.Balance{Currency: "USDC", Available: Number(70.0 + 80.0)},
|
||||
"USDT": types.Balance{Currency: "USDT", Available: Number(100.0)},
|
||||
},
|
||||
wantRest: types.BalanceMap{
|
||||
"BTC": types.Balance{Currency: "BTC", Available: Number(0.01)},
|
||||
balances: BalancesFromText(`
|
||||
USDC, 150.0
|
||||
USDT, 100.0
|
||||
BTC, 0.01
|
||||
`),
|
||||
},
|
||||
wantFiats: BalancesFromText(`
|
||||
USDC, 150.0
|
||||
USDT, 100.0
|
||||
`),
|
||||
wantRest: BalancesFromText(`
|
||||
BTC, 0.01
|
||||
`),
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
|
|
43
pkg/testing/testhelper/balance.go
Normal file
43
pkg/testing/testhelper/balance.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
package testhelper
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/c9s/bbgo/pkg/fixedpoint"
|
||||
"github.com/c9s/bbgo/pkg/types"
|
||||
)
|
||||
|
||||
func BalancesFromText(str string) types.BalanceMap {
|
||||
balances := make(types.BalanceMap)
|
||||
lines := strings.Split(str, "\n")
|
||||
for _, line := range lines {
|
||||
line = strings.TrimSpace(line)
|
||||
if len(line) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
cols := strings.SplitN(line, ",", 2)
|
||||
if len(cols) < 2 {
|
||||
panic("column length should be 2")
|
||||
}
|
||||
|
||||
currency := strings.TrimSpace(cols[0])
|
||||
available := fixedpoint.MustNewFromString(strings.TrimSpace(cols[1]))
|
||||
balances[currency] = Balance(currency, available)
|
||||
}
|
||||
|
||||
return balances
|
||||
}
|
||||
|
||||
// Balance returns a balance object with the given currency and available amount
|
||||
func Balance(currency string, available fixedpoint.Value) types.Balance {
|
||||
return types.Balance{
|
||||
Currency: currency,
|
||||
Available: available,
|
||||
Locked: fixedpoint.Zero,
|
||||
Borrowed: fixedpoint.Zero,
|
||||
Interest: fixedpoint.Zero,
|
||||
NetAsset: fixedpoint.Zero,
|
||||
MaxWithdrawAmount: fixedpoint.Zero,
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user