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:
Andrew
2020-02-26 15:45:13 +11:00
committed by GitHub
parent def3cdf226
commit b26ec86d43
122 changed files with 18066 additions and 2029 deletions

View File

@@ -17,8 +17,8 @@ import (
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
"github.com/thrasher-corp/gocryptotrader/log"
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
)
const (
@@ -671,32 +671,32 @@ func (b *Bitfinex) WithdrawCryptocurrency(wallet, address, paymentID string, amo
}
// WithdrawFIAT Sends an authenticated request to withdraw FIAT currency
func (b *Bitfinex) WithdrawFIAT(withdrawalType, walletType string, withdrawRequest *withdraw.FiatRequest) (Withdrawal, error) {
func (b *Bitfinex) WithdrawFIAT(withdrawalType, walletType string, withdrawRequest *withdraw.Request) (Withdrawal, error) {
var response []Withdrawal
req := make(map[string]interface{})
req["withdraw_type"] = withdrawalType
req["walletselected"] = walletType
req["amount"] = strconv.FormatFloat(withdrawRequest.Amount, 'f', -1, 64)
req["account_name"] = withdrawRequest.BankAccountName
req["account_number"] = withdrawRequest.BankAccountNumber
req["bank_name"] = withdrawRequest.BankName
req["bank_address"] = withdrawRequest.BankAddress
req["bank_city"] = withdrawRequest.BankCity
req["bank_country"] = withdrawRequest.BankCountry
req["expressWire"] = withdrawRequest.IsExpressWire
req["swift"] = withdrawRequest.SwiftCode
req["account_name"] = withdrawRequest.Fiat.Bank.AccountName
req["account_number"] = withdrawRequest.Fiat.Bank.AccountNumber
req["bank_name"] = withdrawRequest.Fiat.Bank.BankName
req["bank_address"] = withdrawRequest.Fiat.Bank.BankAddress
req["bank_city"] = withdrawRequest.Fiat.Bank.BankPostalCity
req["bank_country"] = withdrawRequest.Fiat.Bank.BankCountry
req["expressWire"] = withdrawRequest.Fiat.IsExpressWire
req["swift"] = withdrawRequest.Fiat.Bank.SWIFTCode
req["detail_payment"] = withdrawRequest.Description
req["currency"] = withdrawRequest.WireCurrency
req["account_address"] = withdrawRequest.BankAddress
req["currency"] = withdrawRequest.Currency
req["account_address"] = withdrawRequest.Fiat.Bank.BankAddress
if withdrawRequest.RequiresIntermediaryBank {
req["intermediary_bank_name"] = withdrawRequest.IntermediaryBankName
req["intermediary_bank_address"] = withdrawRequest.IntermediaryBankAddress
req["intermediary_bank_city"] = withdrawRequest.IntermediaryBankCity
req["intermediary_bank_country"] = withdrawRequest.IntermediaryBankCountry
req["intermediary_bank_account"] = strconv.FormatFloat(withdrawRequest.IntermediaryBankAccountNumber, 'f', -1, 64)
req["intermediary_bank_swift"] = withdrawRequest.IntermediarySwiftCode
if withdrawRequest.Fiat.RequiresIntermediaryBank {
req["intermediary_bank_name"] = withdrawRequest.Fiat.IntermediaryBankName
req["intermediary_bank_address"] = withdrawRequest.Fiat.IntermediaryBankAddress
req["intermediary_bank_city"] = withdrawRequest.Fiat.IntermediaryBankCity
req["intermediary_bank_country"] = withdrawRequest.Fiat.IntermediaryBankCountry
req["intermediary_bank_account"] = strconv.FormatFloat(withdrawRequest.Fiat.IntermediaryBankAccountNumber, 'f', -1, 64)
req["intermediary_bank_swift"] = withdrawRequest.Fiat.IntermediarySwiftCode
}
err := b.SendAuthenticatedHTTPRequest(http.MethodPost,

View File

@@ -16,7 +16,8 @@ import (
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
"github.com/thrasher-corp/gocryptotrader/portfolio/banking"
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
)
// Please supply your own keys here to do better tests
@@ -273,55 +274,6 @@ func TestWalletTransfer(t *testing.T) {
}
}
func TestWithdrawCryptocurrency(t *testing.T) {
if !b.ValidateAPICredentials() {
t.SkipNow()
}
t.Parallel()
_, err := b.WithdrawCryptocurrency("bad",
"rEb8TK3gBgk5auZkwc6sHnwrGVJH8DuaLh",
"102257461",
1,
currency.XRP)
if err == nil {
t.Error("error cannot be nil")
}
}
func TestWithdrawFiat(t *testing.T) {
t.Parallel()
if areTestAPIKeysSet() && !canManipulateRealOrders {
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
}
var withdrawFiatRequest = withdraw.FiatRequest{
GenericInfo: withdraw.GenericInfo{
Amount: 1,
Currency: currency.USD,
Description: "WITHDRAW IT ALL",
},
BankAccountName: "Satoshi Nakamoto",
BankAccountNumber: "12345",
BankAddress: "123 Fake St",
BankCity: "Tarry Town",
BankCountry: "Hyrule",
BankName: "Federal Reserve Bank",
WireCurrency: currency.USD.String(),
SwiftCode: "Taylor",
RequiresIntermediaryBank: false,
IsExpressWire: false,
}
_, err := b.WithdrawFIAT("wire", "exchange", &withdrawFiatRequest)
if !areTestAPIKeysSet() && err == nil {
t.Error("Expecting an error when no keys are set")
}
if areTestAPIKeysSet() && err != nil {
t.Errorf("Withdraw failed to be placed: %v", err)
}
}
func TestNewOrder(t *testing.T) {
if !b.ValidateAPICredentials() {
t.SkipNow()
@@ -862,13 +814,13 @@ func TestWithdraw(t *testing.T) {
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
}
withdrawCryptoRequest := withdraw.CryptoRequest{
GenericInfo: withdraw.GenericInfo{
Amount: -1,
Currency: currency.BTC,
Description: "WITHDRAW IT ALL",
withdrawCryptoRequest := withdraw.Request{
Amount: -1,
Currency: currency.BTC,
Description: "WITHDRAW IT ALL",
Crypto: &withdraw.CryptoRequest{
Address: core.BitcoinDonationAddress,
},
Address: core.BitcoinDonationAddress,
}
_, err := b.WithdrawCryptocurrencyFunds(&withdrawCryptoRequest)
@@ -880,34 +832,53 @@ func TestWithdraw(t *testing.T) {
}
}
func TestWithdrawFiat(t *testing.T) {
t.Parallel()
if areTestAPIKeysSet() && !canManipulateRealOrders {
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
}
var withdrawFiatRequest = withdraw.Request{
Amount: -1,
Currency: currency.USD,
Description: "WITHDRAW IT ALL",
Fiat: &withdraw.FiatRequest{
Bank: &banking.Account{},
WireCurrency: currency.USD.String(),
},
}
_, err := b.WithdrawFiatFunds(&withdrawFiatRequest)
if !areTestAPIKeysSet() && err == nil {
t.Error("Expecting an error when no keys are set")
}
if areTestAPIKeysSet() && err != nil {
t.Errorf("Withdraw failed to be placed: %v", err)
}
}
func TestWithdrawInternationalBank(t *testing.T) {
t.Parallel()
if areTestAPIKeysSet() && !canManipulateRealOrders {
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
}
var withdrawFiatRequest = withdraw.FiatRequest{
GenericInfo: withdraw.GenericInfo{
Amount: -1,
Currency: currency.BTC,
Description: "WITHDRAW IT ALL",
var withdrawFiatRequest = withdraw.Request{
Amount: -1,
Currency: currency.BTC,
Description: "WITHDRAW IT ALL",
Fiat: &withdraw.FiatRequest{
Bank: &banking.Account{},
WireCurrency: currency.USD.String(),
RequiresIntermediaryBank: true,
IsExpressWire: false,
IntermediaryBankAccountNumber: 12345,
IntermediaryBankAddress: "123 Fake St",
IntermediaryBankCity: "Tarry Town",
IntermediaryBankCountry: "Hyrule",
IntermediaryBankName: "Federal Reserve Bank",
IntermediarySwiftCode: "Taylor",
},
BankAccountName: "Satoshi Nakamoto",
BankAccountNumber: "12345",
BankAddress: "123 Fake St",
BankCity: "Tarry Town",
BankCountry: "Hyrule",
BankName: "Federal Reserve Bank",
WireCurrency: currency.USD.String(),
SwiftCode: "Taylor",
RequiresIntermediaryBank: true,
IsExpressWire: false,
IntermediaryBankAccountNumber: 12345,
IntermediaryBankAddress: "123 Fake St",
IntermediaryBankCity: "Tarry Town",
IntermediaryBankCountry: "Hyrule",
IntermediaryBankName: "Federal Reserve Bank",
IntermediarySwiftCode: "Taylor",
}
_, err := b.WithdrawFiatFundsToInternationalBank(&withdrawFiatRequest)

View File

@@ -19,8 +19,8 @@ import (
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
"github.com/thrasher-corp/gocryptotrader/log"
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
)
// GetDefaultConfig returns a default exchange config
@@ -537,26 +537,29 @@ func (b *Bitfinex) GetDepositAddress(c currency.Code, accountID string) (string,
}
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is submitted
func (b *Bitfinex) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.CryptoRequest) (string, error) {
func (b *Bitfinex) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
// Bitfinex has support for three types, exchange, margin and deposit
// As this is for trading, I've made the wrapper default 'exchange'
// TODO: Discover an automated way to make the decision for wallet type to withdraw from
walletType := "exchange"
resp, err := b.WithdrawCryptocurrency(walletType,
withdrawRequest.Address,
withdrawRequest.Crypto.Address,
withdrawRequest.Description,
withdrawRequest.Amount,
withdrawRequest.Currency)
if err != nil {
return "", err
return nil, err
}
return strconv.FormatInt(resp.WithdrawalID, 10), err
return &withdraw.ExchangeResponse{
ID: strconv.FormatInt(resp.WithdrawalID, 10),
Status: resp.Status,
}, err
}
// WithdrawFiatFunds returns a withdrawal ID when a withdrawal is submitted
// Returns comma delimited withdrawal IDs
func (b *Bitfinex) WithdrawFiatFunds(withdrawRequest *withdraw.FiatRequest) (string, error) {
func (b *Bitfinex) WithdrawFiatFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
withdrawalType := "wire"
// Bitfinex has support for three types, exchange, margin and deposit
// As this is for trading, I've made the wrapper default 'exchange'
@@ -564,16 +567,26 @@ func (b *Bitfinex) WithdrawFiatFunds(withdrawRequest *withdraw.FiatRequest) (str
walletType := "exchange"
resp, err := b.WithdrawFIAT(withdrawalType, walletType, withdrawRequest)
if err != nil {
return "", err
return nil, err
}
return strconv.FormatInt(resp.WithdrawalID, 10), nil
return &withdraw.ExchangeResponse{
ID: strconv.FormatInt(resp.WithdrawalID, 10),
Status: resp.Status,
}, err
}
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a withdrawal is submitted
// Returns comma delimited withdrawal IDs
func (b *Bitfinex) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.FiatRequest) (string, error) {
return b.WithdrawFiatFunds(withdrawRequest)
func (b *Bitfinex) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
v, err := b.WithdrawFiatFunds(withdrawRequest)
if err != nil {
return nil, err
}
return &withdraw.ExchangeResponse{
ID: v.ID,
Status: v.Status,
}, nil
}
// GetWebsocket returns a pointer to the exchange websocket