mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-29 15:10:37 +00:00
* Speeds up tests * Reduces time.Sleeps, lowers CreateTestBot complexity. Breaks things * Removal of unecessary config reads. Parallel tests. Lower times * Speeds up recent trades results * mini update * zoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooom * Removes the dupes * Lint * post cherrypick * Fix rare kraken data race * Fixes banking global issues. Fixes postgres trades * rmline for appveyor test * Expands timeout in event that channel is closed before send * Fix data race * No rows, no bows and definitely no shows * Removes parallel from createsnapshot tests * Extends timedmutext test a smidge. Exchange fatality * Shorter end timeframe and bigger candle
116 lines
2.8 KiB
Go
116 lines
2.8 KiB
Go
package banking
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/thrasher-corp/gocryptotrader/common"
|
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
|
)
|
|
|
|
// SetAccounts safely overwrites bank account slice
|
|
func SetAccounts(accs ...Account) {
|
|
m.Lock()
|
|
defer m.Unlock()
|
|
accounts = accs
|
|
}
|
|
|
|
// AppendAccounts safely adds to bank account slice
|
|
func AppendAccounts(accs ...Account) {
|
|
m.Lock()
|
|
defer m.Unlock()
|
|
accountRange:
|
|
for j := range accs {
|
|
for i := range accounts {
|
|
if accounts[i].AccountNumber == accs[j].AccountNumber {
|
|
continue accountRange
|
|
}
|
|
}
|
|
accounts = append(accounts, accs[j])
|
|
}
|
|
}
|
|
|
|
// GetBankAccountByID Returns a bank account based on its ID
|
|
func GetBankAccountByID(id string) (*Account, error) {
|
|
m.Lock()
|
|
defer m.Unlock()
|
|
for x := range accounts {
|
|
if strings.EqualFold(accounts[x].ID, id) {
|
|
return &accounts[x], nil
|
|
}
|
|
}
|
|
return nil, fmt.Errorf(ErrBankAccountNotFound, id)
|
|
}
|
|
|
|
// ExchangeSupported Checks if exchange is supported by bank account
|
|
func (b *Account) ExchangeSupported(exchange string) bool {
|
|
exchList := strings.Split(b.SupportedExchanges, ",")
|
|
return common.StringDataCompareInsensitive(exchList, exchange)
|
|
}
|
|
|
|
// Validate validates bank account settings
|
|
func (b *Account) Validate() error {
|
|
if b.BankName == "" ||
|
|
b.BankAddress == "" ||
|
|
b.BankPostalCode == "" ||
|
|
b.BankPostalCity == "" ||
|
|
b.BankCountry == "" ||
|
|
b.AccountName == "" ||
|
|
b.SupportedCurrencies == "" {
|
|
return fmt.Errorf(
|
|
"banking details for %s is enabled but variables not set correctly",
|
|
b.BankName)
|
|
}
|
|
|
|
if b.SupportedExchanges == "" {
|
|
b.SupportedExchanges = "ALL"
|
|
}
|
|
|
|
if strings.Contains(strings.ToUpper(
|
|
b.SupportedCurrencies),
|
|
currency.AUD.String()) {
|
|
if b.BSBNumber == "" {
|
|
return fmt.Errorf(
|
|
"banking details for %s is enabled but BSB/SWIFT values not set",
|
|
b.BankName)
|
|
}
|
|
} else {
|
|
if b.IBAN == "" && b.SWIFTCode == "" {
|
|
return fmt.Errorf(
|
|
"banking details for %s is enabled but SWIFT/IBAN values not set",
|
|
b.BankName)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ValidateForWithdrawal confirms bank account meets minimum requirements to submit
|
|
// a withdrawal request
|
|
func (b *Account) ValidateForWithdrawal(exchange string, cur currency.Code) (err []string) {
|
|
if !b.Enabled {
|
|
err = append(err, ErrBankAccountDisabled)
|
|
}
|
|
if !b.ExchangeSupported(exchange) {
|
|
err = append(err, "Exchange "+exchange+" not supported by bank account")
|
|
}
|
|
|
|
if b.AccountNumber == "" {
|
|
err = append(err, ErrAccountCannotBeEmpty)
|
|
}
|
|
|
|
if !common.StringDataCompareInsensitive(strings.Split(b.SupportedCurrencies, ","), cur.String()) {
|
|
err = append(err, ErrCurrencyNotSupportedByAccount)
|
|
}
|
|
|
|
if cur.Upper() == currency.AUD {
|
|
if b.BSBNumber == "" {
|
|
err = append(err, ErrBSBRequiredForAUD)
|
|
}
|
|
} else {
|
|
if b.IBAN == "" && b.SWIFTCode == "" {
|
|
err = append(err, ErrIBANSwiftNotSet)
|
|
}
|
|
}
|
|
return
|
|
}
|