mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-24 15:10:19 +00:00
Withdraw additional functionality (validation/submission/tracking) (#409)
* reworked request struct and exchange response started work on validation system * removed import cycle until work around * Added intial withdraw support via CLI added * Added Crypto command to gctcli * moved var declartion to single line * Test updates for binance and anx * All exchange tests have been updated test coverage added to validate * First pass at adding withdrawl select from database * started adding basic lru cache system * Added basic LRU cache including Add Get Remove Contains ContainsOrAdd Clear * wording changes on comments * removed exported var's in strut as they are not required * Added README * README updates * corrected ID on commands * rm line :D * merged in origin/cache * linter fixes (gofmt) * Added basic cache lookup to events * swapped to mutex over rwmutex updated comments * unexported getNewest & getOldest * unexported getNewest & getOldest * Updated comments and cited references in source * updated comments * WIP * Migrated exchange WithdrawFiat wrapper to new struct response * Migrated exchange WithdrawFiat wrapper to new struct response * started work on bank management * Added exchange level banking details back with migration to banking package * Removed broken tests for now * Added validation to bank accounts * removed duplicate bank details from withdraw struct * Test coverage increased * gofmt * merged upstream/master with clean up * First pass at adding command line linking to gctcli * added validation for crypto address, added gctcli support to retreive previous withdrawal requests * general cleanup * general cleanup * reordered imports * Increased test coverage moved to database sublogger * Pass incorrect currency no longer return error from c.CheckBankAccountConfig * remove TestMain() for now as other tests in this package will need to be reworked * Happy little race car * Reverted to upstream tests * Added test covarege for validation method, corrected response on cli protobuf * query clean up and removal of duplicated code * cleaned up queries into singlem ethod increased test coverage * Migrated international fund withdraw to new exchange response and added cache size override * Migrated international fund withdraw to new exchange response and added cache size override * Extended gctcli commands * lowered default cache to 25 * small code clean up * added get by date method * add returned error * cli commands cleaing return error on nil results to fix out of bounds * merged write & read helpers into one for test coverage and increased engine/withdraw test coverage * gofmt * Added test coverage for valid ID * removed unused param * converted to use timestamp package from protobuf * gofmt * use built in RFC3339 timestamp * remove setting of CreatedAt & UpdatedAt and allow ORm to take care of it * also use ptype on byid * code flow improvements * remove inverse conditional check and linters run * removed test data * removed comment * removed comment * also write failures to database for auditing * converted to use default time for start & end * Default to time.Now() minus 30 days * Default to time.Now() minus 30 days * small code clean up * fixed missing semicolon on migrations, code clean up * updated sqlite migrations * Added additonal check for exchange level bank account if global is not found * case sensativity fix for currency names * use correct compare * test coverage fixed * removed space * return pointer to banking.Account * return pointer to banking.Account * added else check back to validate() * Added empty string as default to migration over NULL due to retrivial of data
This commit is contained in:
@@ -8,8 +8,8 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/gctscript/wrappers"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
var exchangeModule = map[string]objects.Object{
|
||||
@@ -435,15 +435,15 @@ func ExchangeWithdrawCrypto(args ...objects.Object) (objects.Object, error) {
|
||||
return nil, fmt.Errorf(ErrParameterConvertFailed, description)
|
||||
}
|
||||
|
||||
withdrawRequest := &withdraw.CryptoRequest{
|
||||
GenericInfo: withdraw.GenericInfo{
|
||||
Currency: currency.NewCode(cur),
|
||||
Description: description,
|
||||
Amount: amount,
|
||||
withdrawRequest := &withdraw.Request{
|
||||
Crypto: &withdraw.CryptoRequest{
|
||||
Address: address,
|
||||
AddressTag: addressTag,
|
||||
FeeAmount: feeAmount,
|
||||
},
|
||||
Address: address,
|
||||
AddressTag: addressTag,
|
||||
FeeAmount: feeAmount,
|
||||
Currency: currency.NewCode(cur),
|
||||
Description: description,
|
||||
Amount: amount,
|
||||
}
|
||||
|
||||
rtn, err := wrappers.GetWrapper().WithdrawalCryptoFunds(exchangeName, withdrawRequest)
|
||||
@@ -481,12 +481,10 @@ func ExchangeWithdrawFiat(args ...objects.Object) (objects.Object, error) {
|
||||
return nil, fmt.Errorf(ErrParameterConvertFailed, bankAccountID)
|
||||
}
|
||||
|
||||
withdrawRequest := &withdraw.FiatRequest{
|
||||
GenericInfo: withdraw.GenericInfo{
|
||||
Currency: currency.NewCode(cur),
|
||||
Description: description,
|
||||
Amount: amount,
|
||||
},
|
||||
withdrawRequest := &withdraw.Request{
|
||||
Currency: currency.NewCode(cur),
|
||||
Description: description,
|
||||
Amount: amount,
|
||||
}
|
||||
|
||||
rtn, err := wrappers.GetWrapper().WithdrawalFiatFunds(exchangeName, bankAccountID, withdrawRequest)
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// Wrapper instance of GCT to use for modules
|
||||
@@ -30,8 +30,8 @@ type Exchange interface {
|
||||
CancelOrder(exch, orderid string) (bool, error)
|
||||
AccountInformation(exch string) (account.Holdings, error)
|
||||
DepositAddress(exch string, currencyCode currency.Code) (string, error)
|
||||
WithdrawalFiatFunds(exch, bankaccountid string, request *withdraw.FiatRequest) (out string, err error)
|
||||
WithdrawalCryptoFunds(exch string, request *withdraw.CryptoRequest) (out string, err error)
|
||||
WithdrawalFiatFunds(exch, bankAccountID string, request *withdraw.Request) (out string, err error)
|
||||
WithdrawalCryptoFunds(exch string, request *withdraw.Request) (out string, err error)
|
||||
}
|
||||
|
||||
// SetModuleWrapper link the wrapper and interface to use for modules
|
||||
|
||||
@@ -13,7 +13,8 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/banking"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// Exchange implements all required methods for Wrapper
|
||||
@@ -143,14 +144,18 @@ func (e Exchange) DepositAddress(exch string, currencyCode currency.Code) (out s
|
||||
}
|
||||
|
||||
// WithdrawalFiatFunds withdraw funds from exchange to requested fiat source
|
||||
func (e Exchange) WithdrawalFiatFunds(exch, bankaccountid string, request *withdraw.FiatRequest) (string, error) {
|
||||
func (e Exchange) WithdrawalFiatFunds(exch, bankAccountID string, request *withdraw.Request) (string, error) {
|
||||
ex, err := e.GetExchange(exch)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
v, err := engine.Bot.Config.GetBankAccountByID(bankaccountid)
|
||||
var v *banking.Account
|
||||
v, err = banking.GetBankAccountByID(bankAccountID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
v, err = ex.GetBase().GetExchangeBankAccounts(bankAccountID, request.Currency.String())
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
||||
otp, err := engine.GetExchangeoOTPByName(exch)
|
||||
@@ -159,29 +164,29 @@ func (e Exchange) WithdrawalFiatFunds(exch, bankaccountid string, request *withd
|
||||
if errParse != nil {
|
||||
return "", errors.New("failed to generate OTP unable to continue")
|
||||
}
|
||||
request.GenericInfo.OneTimePassword = otpValue
|
||||
request.OneTimePassword = otpValue
|
||||
}
|
||||
request.BankAccountName = v.AccountName
|
||||
request.BankAccountNumber = v.AccountNumber
|
||||
request.BankName = v.BankName
|
||||
request.BankAddress = v.BankAddress
|
||||
request.BankCity = v.BankPostalCity
|
||||
request.BankCountry = v.BankCountry
|
||||
request.BankPostalCode = v.BankPostalCode
|
||||
request.BSB = v.BSBNumber
|
||||
request.SwiftCode = v.SWIFTCode
|
||||
request.IBAN = v.IBAN
|
||||
request.Exchange = exch
|
||||
request.Fiat.Bank.AccountName = v.AccountName
|
||||
request.Fiat.Bank.AccountNumber = v.AccountNumber
|
||||
request.Fiat.Bank.BankName = v.BankName
|
||||
request.Fiat.Bank.BankAddress = v.BankAddress
|
||||
request.Fiat.Bank.BankPostalCity = v.BankPostalCity
|
||||
request.Fiat.Bank.BankCountry = v.BankCountry
|
||||
request.Fiat.Bank.BankPostalCode = v.BankPostalCode
|
||||
request.Fiat.Bank.BSBNumber = v.BSBNumber
|
||||
request.Fiat.Bank.SWIFTCode = v.SWIFTCode
|
||||
request.Fiat.Bank.IBAN = v.IBAN
|
||||
|
||||
err = withdraw.Valid(request)
|
||||
resp, err := engine.SubmitWithdrawal(ex.GetName(), request)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return ex.WithdrawFiatFunds(request)
|
||||
return resp.Exchange.ID, nil
|
||||
}
|
||||
|
||||
// WithdrawalCryptoFunds withdraw funds from exchange to requested Crypto source
|
||||
func (e Exchange) WithdrawalCryptoFunds(exch string, request *withdraw.CryptoRequest) (out string, err error) {
|
||||
func (e Exchange) WithdrawalCryptoFunds(exch string, request *withdraw.Request) (out string, err error) {
|
||||
ex, err := e.GetExchange(exch)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -193,12 +198,12 @@ func (e Exchange) WithdrawalCryptoFunds(exch string, request *withdraw.CryptoReq
|
||||
if errParse != nil {
|
||||
return "", errors.New("failed to generate OTP unable to continue")
|
||||
}
|
||||
request.GenericInfo.OneTimePassword = v
|
||||
request.OneTimePassword = v
|
||||
}
|
||||
|
||||
err = withdraw.Valid(request)
|
||||
resp, err := engine.SubmitWithdrawal(ex.GetName(), request)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return ex.WithdrawCryptocurrencyFunds(request)
|
||||
return resp.Exchange.ID, nil
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// Exchanges validator for test execution/scripts
|
||||
@@ -193,7 +193,7 @@ func (w Wrapper) DepositAddress(exch string, _ currency.Code) (string, error) {
|
||||
}
|
||||
|
||||
// WithdrawalCryptoFunds validator for test execution/scripts
|
||||
func (w Wrapper) WithdrawalCryptoFunds(exch string, _ *withdraw.CryptoRequest) (out string, err error) {
|
||||
func (w Wrapper) WithdrawalCryptoFunds(exch string, _ *withdraw.Request) (out string, err error) {
|
||||
if exch == exchError.String() {
|
||||
return exch, errTestFailed
|
||||
}
|
||||
@@ -202,7 +202,7 @@ func (w Wrapper) WithdrawalCryptoFunds(exch string, _ *withdraw.CryptoRequest) (
|
||||
}
|
||||
|
||||
// WithdrawalFiatFunds validator for test execution/scripts
|
||||
func (w Wrapper) WithdrawalFiatFunds(exch, _ string, _ *withdraw.FiatRequest) (out string, err error) {
|
||||
func (w Wrapper) WithdrawalFiatFunds(exch, _ string, _ *withdraw.Request) (out string, err error) {
|
||||
if exch == exchError.String() {
|
||||
return exch, errTestFailed
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user