mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-31 23:16:54 +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:
@@ -16,7 +16,7 @@ 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/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
)
|
||||
|
||||
@@ -334,19 +334,19 @@ func ({{.Variable}} *{{.CapitalName}}) GetDepositAddress(cryptocurrency currency
|
||||
|
||||
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func ({{.Variable}} *{{.CapitalName}}) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.CryptoRequest) (string, error) {
|
||||
func ({{.Variable}} *{{.CapitalName}}) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return "", common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func ({{.Variable}} *{{.CapitalName}}) WithdrawFiatFunds(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
func ({{.Variable}} *{{.CapitalName}}) WithdrawFiatFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return "", common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func ({{.Variable}} *{{.CapitalName}}) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
func ({{.Variable}} *{{.CapitalName}}) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.Request) (string, error) {
|
||||
return "", common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"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/portfolio/withdraw"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -175,16 +175,16 @@ func testWrappers(e exchange.IBotExchange) []string {
|
||||
funcs = append(funcs, "GetDepositAddress")
|
||||
}
|
||||
|
||||
_, err = e.WithdrawCryptocurrencyFunds(&withdraw.CryptoRequest{})
|
||||
_, err = e.WithdrawCryptocurrencyFunds(&withdraw.Request{})
|
||||
if err == common.ErrNotYetImplemented {
|
||||
funcs = append(funcs, "WithdrawCryptocurrencyFunds")
|
||||
}
|
||||
|
||||
_, err = e.WithdrawFiatFunds(&withdraw.FiatRequest{})
|
||||
_, err = e.WithdrawFiatFunds(&withdraw.Request{})
|
||||
if err == common.ErrNotYetImplemented {
|
||||
funcs = append(funcs, "WithdrawFiatFunds")
|
||||
}
|
||||
_, err = e.WithdrawFiatFundsToInternationalBank(&withdraw.FiatRequest{})
|
||||
_, err = e.WithdrawFiatFundsToInternationalBank(&withdraw.Request{})
|
||||
if err == common.ErrNotYetImplemented {
|
||||
funcs = append(funcs, "WithdrawFiatFundsToInternationalBank")
|
||||
}
|
||||
|
||||
@@ -23,7 +23,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"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -622,15 +623,14 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
|
||||
Response: jsonifyInterface([]interface{}{r19}),
|
||||
})
|
||||
|
||||
genericWithdrawRequest := withdraw.GenericInfo{
|
||||
Amount: config.OrderSubmission.Amount,
|
||||
withdrawRequest := withdraw.Request{
|
||||
Currency: p.Quote,
|
||||
Crypto: &withdraw.CryptoRequest{
|
||||
Address: withdrawAddressOverride,
|
||||
},
|
||||
Amount: config.OrderSubmission.Amount,
|
||||
}
|
||||
withdrawRequest := withdraw.CryptoRequest{
|
||||
GenericInfo: genericWithdrawRequest,
|
||||
Address: withdrawAddressOverride,
|
||||
}
|
||||
var r20 string
|
||||
var r20 *withdraw.ExchangeResponse
|
||||
r20, err = e.WithdrawCryptocurrencyFunds(&withdrawRequest)
|
||||
msg = ""
|
||||
if err != nil {
|
||||
@@ -666,53 +666,59 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
|
||||
Response: jsonifyInterface([]interface{}{r21}),
|
||||
})
|
||||
|
||||
fiatWithdrawRequest := withdraw.FiatRequest{
|
||||
GenericInfo: genericWithdrawRequest,
|
||||
BankAccountName: config.BankDetails.BankAccountName,
|
||||
BankAccountNumber: config.BankDetails.BankAccountNumber,
|
||||
SwiftCode: config.BankDetails.SwiftCode,
|
||||
IBAN: config.BankDetails.Iban,
|
||||
BankCity: config.BankDetails.BankCity,
|
||||
BankName: config.BankDetails.BankName,
|
||||
BankAddress: config.BankDetails.BankAddress,
|
||||
BankCountry: config.BankDetails.BankCountry,
|
||||
BankPostalCode: config.BankDetails.BankPostalCode,
|
||||
BankCode: config.BankDetails.BankCode,
|
||||
IsExpressWire: config.BankDetails.IsExpressWire,
|
||||
RequiresIntermediaryBank: config.BankDetails.RequiresIntermediaryBank,
|
||||
IntermediaryBankName: config.BankDetails.IntermediaryBankName,
|
||||
IntermediaryBankAccountNumber: config.BankDetails.IntermediaryBankAccountNumber,
|
||||
IntermediarySwiftCode: config.BankDetails.IntermediarySwiftCode,
|
||||
IntermediaryIBAN: config.BankDetails.IntermediaryIban,
|
||||
IntermediaryBankCity: config.BankDetails.IntermediaryBankCity,
|
||||
IntermediaryBankAddress: config.BankDetails.IntermediaryBankAddress,
|
||||
IntermediaryBankCountry: config.BankDetails.IntermediaryBankCountry,
|
||||
IntermediaryBankPostalCode: config.BankDetails.IntermediaryBankPostalCode,
|
||||
IntermediaryBankCode: config.BankDetails.IntermediaryBankCode,
|
||||
withdrawRequestFiat := withdraw.Request{
|
||||
Currency: p.Quote,
|
||||
Amount: config.OrderSubmission.Amount,
|
||||
Fiat: &withdraw.FiatRequest{
|
||||
Bank: &banking.Account{
|
||||
AccountName: config.BankDetails.BankAccountName,
|
||||
AccountNumber: config.BankDetails.BankAccountNumber,
|
||||
SWIFTCode: config.BankDetails.SwiftCode,
|
||||
IBAN: config.BankDetails.Iban,
|
||||
BankPostalCity: config.BankDetails.BankCity,
|
||||
BankName: config.BankDetails.BankName,
|
||||
BankAddress: config.BankDetails.BankAddress,
|
||||
BankCountry: config.BankDetails.BankCountry,
|
||||
BankPostalCode: config.BankDetails.BankPostalCode,
|
||||
BankCode: config.BankDetails.BankCode,
|
||||
},
|
||||
|
||||
IsExpressWire: config.BankDetails.IsExpressWire,
|
||||
RequiresIntermediaryBank: config.BankDetails.RequiresIntermediaryBank,
|
||||
IntermediaryBankName: config.BankDetails.IntermediaryBankName,
|
||||
IntermediaryBankAccountNumber: config.BankDetails.IntermediaryBankAccountNumber,
|
||||
IntermediarySwiftCode: config.BankDetails.IntermediarySwiftCode,
|
||||
IntermediaryIBAN: config.BankDetails.IntermediaryIban,
|
||||
IntermediaryBankCity: config.BankDetails.IntermediaryBankCity,
|
||||
IntermediaryBankAddress: config.BankDetails.IntermediaryBankAddress,
|
||||
IntermediaryBankCountry: config.BankDetails.IntermediaryBankCountry,
|
||||
IntermediaryBankPostalCode: config.BankDetails.IntermediaryBankPostalCode,
|
||||
IntermediaryBankCode: config.BankDetails.IntermediaryBankCode,
|
||||
},
|
||||
}
|
||||
var r22 string
|
||||
r22, err = e.WithdrawFiatFunds(&fiatWithdrawRequest)
|
||||
var r22 *withdraw.ExchangeResponse
|
||||
r22, err = e.WithdrawFiatFunds(&withdrawRequestFiat)
|
||||
msg = ""
|
||||
if err != nil {
|
||||
msg = err.Error()
|
||||
responseContainer.ErrorCount++
|
||||
}
|
||||
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
|
||||
SentParams: jsonifyInterface([]interface{}{fiatWithdrawRequest}),
|
||||
SentParams: jsonifyInterface([]interface{}{withdrawRequestFiat}),
|
||||
Function: "WithdrawFiatFunds",
|
||||
Error: msg,
|
||||
Response: r22,
|
||||
})
|
||||
|
||||
var r23 string
|
||||
r23, err = e.WithdrawFiatFundsToInternationalBank(&fiatWithdrawRequest)
|
||||
var r23 *withdraw.ExchangeResponse
|
||||
r23, err = e.WithdrawFiatFundsToInternationalBank(&withdrawRequestFiat)
|
||||
msg = ""
|
||||
if err != nil {
|
||||
msg = err.Error()
|
||||
responseContainer.ErrorCount++
|
||||
}
|
||||
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
|
||||
SentParams: jsonifyInterface([]interface{}{fiatWithdrawRequest}),
|
||||
SentParams: jsonifyInterface([]interface{}{withdrawRequestFiat}),
|
||||
Function: "WithdrawFiatFundsToInternationalBank",
|
||||
Error: msg,
|
||||
Response: r23,
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
@@ -13,12 +14,16 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/gctrpc"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
const timeFormat = "2006-01-02 15:04:05"
|
||||
|
||||
var startTime, endTime, order string
|
||||
var limit int
|
||||
|
||||
var getInfoCommand = cli.Command{
|
||||
Name: "getinfo",
|
||||
Usage: "gets GoCryptoTrader info",
|
||||
@@ -903,7 +908,7 @@ func getPortfolioSummary(_ *cli.Context) error {
|
||||
var addPortfolioAddressCommand = cli.Command{
|
||||
Name: "addportfolioaddress",
|
||||
Usage: "adds an address to the portfolio",
|
||||
ArgsUsage: "<address> <coin_type> <description> <balance>",
|
||||
ArgsUsage: "<address> <coin_type> <description> <balance> <cold_storage> <supported_exchanges> ",
|
||||
Action: addPortfolioAddress,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
@@ -922,6 +927,14 @@ var addPortfolioAddressCommand = cli.Command{
|
||||
Name: "balance",
|
||||
Usage: "balance of the address",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "cold_storage",
|
||||
Usage: "true/false if address is cold storage",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "supported_exchanges",
|
||||
Usage: "common separated list of exchanges supported by this address for withdrawals",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -941,6 +954,8 @@ func addPortfolioAddress(c *cli.Context) error {
|
||||
var coinType string
|
||||
var description string
|
||||
var balance float64
|
||||
var supportedExchanges string
|
||||
var coldstorage bool
|
||||
|
||||
if c.IsSet("address") {
|
||||
address = c.String("address")
|
||||
@@ -969,13 +984,30 @@ func addPortfolioAddress(c *cli.Context) error {
|
||||
}
|
||||
}
|
||||
|
||||
if c.IsSet("cold_storage") {
|
||||
coldstorage = c.Bool("cold_storage")
|
||||
} else {
|
||||
tv, errBool := strconv.ParseBool(c.Args().Get(4))
|
||||
if errBool == nil {
|
||||
coldstorage = tv
|
||||
}
|
||||
}
|
||||
|
||||
if c.IsSet("supported_exchanges") {
|
||||
supportedExchanges = c.String("supported_exchanges")
|
||||
} else {
|
||||
supportedExchanges = c.Args().Get(5)
|
||||
}
|
||||
|
||||
client := gctrpc.NewGoCryptoTraderClient(conn)
|
||||
result, err := client.AddPortfolioAddress(context.Background(),
|
||||
&gctrpc.AddPortfolioAddressRequest{
|
||||
Address: address,
|
||||
CoinType: coinType,
|
||||
Description: description,
|
||||
Balance: balance,
|
||||
Address: address,
|
||||
CoinType: coinType,
|
||||
Description: description,
|
||||
Balance: balance,
|
||||
SupportedExchanges: supportedExchanges,
|
||||
ColdStorage: coldstorage,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -2148,9 +2180,9 @@ func getCryptocurrencyDepositAddress(c *cli.Context) error {
|
||||
}
|
||||
|
||||
var withdrawCryptocurrencyFundsCommand = cli.Command{
|
||||
Name: "withdrawcryptocurrencyfunds",
|
||||
Name: "withdrawcryptofunds",
|
||||
Usage: "withdraws cryptocurrency funds from the desired exchange",
|
||||
ArgsUsage: "<exchange> <cryptocurrency>",
|
||||
ArgsUsage: "<exchange> <currency> <amount> <address> <addresstag> <fee> <description>",
|
||||
Action: withdrawCryptocurrencyFunds,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
@@ -2158,20 +2190,123 @@ var withdrawCryptocurrencyFundsCommand = cli.Command{
|
||||
Usage: "the exchange to withdraw from",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "cryptocurrency",
|
||||
Name: "currency",
|
||||
Usage: "the cryptocurrency to withdraw funds from",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "address",
|
||||
Usage: "address to withdraw to",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "addresstag",
|
||||
Usage: "address tag/memo",
|
||||
},
|
||||
cli.Float64Flag{
|
||||
Name: "amount",
|
||||
Usage: "amount of funds to withdraw",
|
||||
},
|
||||
cli.Float64Flag{
|
||||
Name: "fee",
|
||||
Usage: "fee to submit with request",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "description",
|
||||
Usage: "description to submit with request",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func withdrawCryptocurrencyFunds(_ *cli.Context) error {
|
||||
return common.ErrNotYetImplemented
|
||||
func withdrawCryptocurrencyFunds(c *cli.Context) error {
|
||||
if c.NArg() == 0 && c.NumFlags() == 0 {
|
||||
cli.ShowCommandHelp(c, "withdrawcryptofunds")
|
||||
return nil
|
||||
}
|
||||
|
||||
var exchange, cur, address, addressTag, description string
|
||||
var amount, fee float64
|
||||
|
||||
if c.IsSet("exchange") {
|
||||
exchange = c.String("exchange")
|
||||
} else if c.Args().Get(0) != "" {
|
||||
exchange = c.Args().Get(0)
|
||||
}
|
||||
|
||||
if !validExchange(exchange) {
|
||||
return errInvalidExchange
|
||||
}
|
||||
|
||||
if c.IsSet("currency") {
|
||||
cur = c.String("currency")
|
||||
} else if c.Args().Get(1) != "" {
|
||||
cur = c.Args().Get(1)
|
||||
}
|
||||
|
||||
if c.IsSet("amount") {
|
||||
amount = c.Float64("amount")
|
||||
} else if c.Args().Get(2) != "" {
|
||||
amountStr, err := strconv.ParseFloat(c.Args().Get(2), 64)
|
||||
if err == nil {
|
||||
amount = amountStr
|
||||
}
|
||||
}
|
||||
|
||||
if c.IsSet("address") {
|
||||
address = c.String("address")
|
||||
} else if c.Args().Get(3) != "" {
|
||||
address = c.Args().Get(3)
|
||||
}
|
||||
|
||||
if c.IsSet("addresstag") {
|
||||
addressTag = c.String("addresstag")
|
||||
} else if c.Args().Get(4) != "" {
|
||||
addressTag = c.Args().Get(4)
|
||||
}
|
||||
|
||||
if c.IsSet("fee") {
|
||||
fee = c.Float64("fee")
|
||||
} else if c.Args().Get(5) != "" {
|
||||
feeStr, err := strconv.ParseFloat(c.Args().Get(5), 64)
|
||||
if err == nil {
|
||||
fee = feeStr
|
||||
}
|
||||
}
|
||||
|
||||
if c.IsSet("description") {
|
||||
description = c.String("description")
|
||||
} else if c.Args().Get(6) != "" {
|
||||
description = c.Args().Get(6)
|
||||
}
|
||||
|
||||
conn, err := setupClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
client := gctrpc.NewGoCryptoTraderClient(conn)
|
||||
|
||||
result, err := client.WithdrawCryptocurrencyFunds(context.Background(),
|
||||
&gctrpc.WithdrawCryptoRequest{
|
||||
Exchange: exchange,
|
||||
Currency: cur,
|
||||
Address: address,
|
||||
AddressTag: addressTag,
|
||||
Amount: amount,
|
||||
Fee: fee,
|
||||
Description: description,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
jsonOutput(result)
|
||||
return nil
|
||||
}
|
||||
|
||||
var withdrawFiatFundsCommand = cli.Command{
|
||||
Name: "withdrawfiatfunds",
|
||||
Usage: "withdraws fiat funds from the desired exchange",
|
||||
ArgsUsage: "<exchange> <fiat_currency>",
|
||||
ArgsUsage: "<exchange> <currency> <amount> <bankaccount id> <description>",
|
||||
Action: withdrawFiatFunds,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
@@ -2179,14 +2314,350 @@ var withdrawFiatFundsCommand = cli.Command{
|
||||
Usage: "the exchange to withdraw from",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "fiat_currency",
|
||||
Name: "currency",
|
||||
Usage: "the fiat currency to withdraw funds from",
|
||||
},
|
||||
cli.Float64Flag{
|
||||
Name: "amount",
|
||||
Usage: "amount of funds to withdraw",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "bankaccountid",
|
||||
Usage: "ID of bank account to use",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "description",
|
||||
Usage: "description to submit with request",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func withdrawFiatFunds(_ *cli.Context) error {
|
||||
return common.ErrNotYetImplemented
|
||||
func withdrawFiatFunds(c *cli.Context) error {
|
||||
if c.NArg() == 0 && c.NumFlags() == 0 {
|
||||
cli.ShowCommandHelp(c, "withdrawfiatfunds")
|
||||
return nil
|
||||
}
|
||||
|
||||
var exchange, cur, description, bankAccountID string
|
||||
var amount float64
|
||||
|
||||
if c.IsSet("exchange") {
|
||||
exchange = c.String("exchange")
|
||||
} else if c.Args().Get(0) != "" {
|
||||
exchange = c.Args().Get(0)
|
||||
}
|
||||
|
||||
if !validExchange(exchange) {
|
||||
return errInvalidExchange
|
||||
}
|
||||
|
||||
if c.IsSet("currency") {
|
||||
cur = c.String("currency")
|
||||
} else if c.Args().Get(1) != "" {
|
||||
cur = c.Args().Get(1)
|
||||
}
|
||||
|
||||
if c.IsSet("amount") {
|
||||
amount = c.Float64("amount")
|
||||
} else if c.Args().Get(2) != "" {
|
||||
amountStr, err := strconv.ParseFloat(c.Args().Get(2), 64)
|
||||
if err == nil {
|
||||
amount = amountStr
|
||||
}
|
||||
}
|
||||
|
||||
if c.IsSet("bankaccountid") {
|
||||
bankAccountID = c.String("bankaccountid")
|
||||
} else if c.Args().Get(3) != "" {
|
||||
bankAccountID = c.Args().Get(3)
|
||||
}
|
||||
|
||||
if c.IsSet("description") {
|
||||
description = c.String("description")
|
||||
} else if c.Args().Get(4) != "" {
|
||||
description = c.Args().Get(4)
|
||||
}
|
||||
|
||||
conn, err := setupClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
client := gctrpc.NewGoCryptoTraderClient(conn)
|
||||
result, err := client.WithdrawFiatFunds(context.Background(),
|
||||
&gctrpc.WithdrawFiatRequest{
|
||||
Exchange: exchange,
|
||||
Currency: cur,
|
||||
Amount: amount,
|
||||
Description: description,
|
||||
BankAccountId: bankAccountID,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
jsonOutput(result)
|
||||
return nil
|
||||
}
|
||||
|
||||
var withdrawalRequestCommand = cli.Command{
|
||||
Name: "withdrawalrequesthistory",
|
||||
Usage: "retrieve previous withdrawal request details",
|
||||
ArgsUsage: "<type> <args>",
|
||||
Subcommands: []cli.Command{
|
||||
{
|
||||
Name: "byid",
|
||||
Usage: "id",
|
||||
ArgsUsage: "<id>",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "id",
|
||||
Usage: "<id>",
|
||||
},
|
||||
},
|
||||
Action: withdrawlRequestByID,
|
||||
},
|
||||
{
|
||||
Name: "byexchangeid",
|
||||
Usage: "exchange id",
|
||||
ArgsUsage: "<id>",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "exchange",
|
||||
Usage: "<exchange>",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "id",
|
||||
Usage: "<id>",
|
||||
},
|
||||
},
|
||||
Action: withdrawlRequestByExchangeID,
|
||||
},
|
||||
{
|
||||
Name: "byexchange",
|
||||
Usage: "exchange limit",
|
||||
ArgsUsage: "<id>",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "exchange",
|
||||
Usage: "<exchange>",
|
||||
},
|
||||
cli.Int64Flag{
|
||||
Name: "limit",
|
||||
Usage: "<limit>",
|
||||
},
|
||||
},
|
||||
Action: withdrawlRequestByExchangeID,
|
||||
},
|
||||
{
|
||||
Name: "bydate",
|
||||
Usage: "exchange start end limit",
|
||||
ArgsUsage: "<exchange> <start> <end> <limit>",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "exchange",
|
||||
Usage: "<exchange>",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "start",
|
||||
Usage: "<start>",
|
||||
Value: time.Now().AddDate(0, -1, 0).Format(timeFormat),
|
||||
Destination: &startTime,
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "end",
|
||||
Usage: "<end>",
|
||||
Value: time.Now().Format(timeFormat),
|
||||
Destination: &endTime,
|
||||
},
|
||||
cli.Int64Flag{
|
||||
Name: "limit",
|
||||
Usage: "<limit>",
|
||||
},
|
||||
},
|
||||
Action: withdrawlRequestByDate,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func withdrawlRequestByID(c *cli.Context) error {
|
||||
if c.NArg() == 0 && c.NumFlags() == 0 {
|
||||
cli.ShowSubcommandHelp(c)
|
||||
return nil
|
||||
}
|
||||
|
||||
var ID string
|
||||
if c.IsSet("id") {
|
||||
ID = c.String("id")
|
||||
} else {
|
||||
ID = c.Args().First()
|
||||
}
|
||||
|
||||
if ID == "" {
|
||||
return errors.New("an ID must be specified")
|
||||
}
|
||||
|
||||
conn, err := setupClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
client := gctrpc.NewGoCryptoTraderClient(conn)
|
||||
|
||||
result, err := client.WithdrawalEventByID(context.Background(),
|
||||
&gctrpc.WithdrawalEventByIDRequest{
|
||||
Id: ID,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
jsonOutput(result)
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawlRequestByExchangeID(c *cli.Context) error {
|
||||
if c.NArg() == 0 && c.NumFlags() == 0 {
|
||||
cli.ShowSubcommandHelp(c)
|
||||
return nil
|
||||
}
|
||||
|
||||
var exchange string
|
||||
if c.IsSet("exchange") {
|
||||
exchange = c.String("exchange")
|
||||
} else {
|
||||
exchange = c.Args().First()
|
||||
}
|
||||
|
||||
var limit, limitStr int64
|
||||
var ID string
|
||||
var err error
|
||||
if c.Command.Name == "byexchangeid" {
|
||||
if c.IsSet("id") {
|
||||
ID = c.String("id")
|
||||
} else {
|
||||
ID = c.Args().Get(1)
|
||||
}
|
||||
if ID == "" {
|
||||
return errors.New("an ID must be specified")
|
||||
}
|
||||
limit = 1
|
||||
} else {
|
||||
if c.IsSet("limit") {
|
||||
limit = c.Int64("limit")
|
||||
} else if c.Args().Get(1) != "" {
|
||||
limitStr, err = strconv.ParseInt(c.Args().Get(1), 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if limitStr > math.MaxInt32 {
|
||||
return fmt.Errorf("limit greater than max size: %v", math.MaxInt32)
|
||||
}
|
||||
limit = limitStr
|
||||
}
|
||||
}
|
||||
|
||||
conn, err := setupClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
client := gctrpc.NewGoCryptoTraderClient(conn)
|
||||
|
||||
result, err := client.WithdrawalEventsByExchange(context.Background(),
|
||||
&gctrpc.WithdrawalEventsByExchangeRequest{
|
||||
Exchange: exchange,
|
||||
Id: ID,
|
||||
Limit: int32(limit),
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
jsonOutput(result)
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawlRequestByDate(c *cli.Context) error {
|
||||
if c.NArg() == 0 && c.NumFlags() == 0 {
|
||||
cli.ShowSubcommandHelp(c)
|
||||
return nil
|
||||
}
|
||||
|
||||
var exchange string
|
||||
var limit, limitStr int64
|
||||
var err error
|
||||
if c.IsSet("exchange") {
|
||||
exchange = c.String("exchange")
|
||||
} else {
|
||||
exchange = c.Args().First()
|
||||
}
|
||||
|
||||
if !c.IsSet("start") {
|
||||
if c.Args().Get(1) != "" {
|
||||
startTime = c.Args().Get(1)
|
||||
}
|
||||
}
|
||||
|
||||
if !c.IsSet("end") {
|
||||
if c.Args().Get(2) != "" {
|
||||
endTime = c.Args().Get(2)
|
||||
}
|
||||
}
|
||||
|
||||
if c.IsSet("limit") {
|
||||
limit = c.Int64("limit")
|
||||
} else if c.Args().Get(3) != "" {
|
||||
limitStr, err = strconv.ParseInt(c.Args().Get(3), 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if limitStr > math.MaxInt32 {
|
||||
return fmt.Errorf("limit greater than max size: %v", math.MaxInt32)
|
||||
}
|
||||
limit = limitStr
|
||||
}
|
||||
|
||||
s, err := time.Parse(timeFormat, startTime)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid time format for start: %v", err)
|
||||
}
|
||||
|
||||
e, err := time.Parse(timeFormat, endTime)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid time format for end: %v", err)
|
||||
}
|
||||
|
||||
if e.Before(s) {
|
||||
return errors.New("start cannot be after before")
|
||||
}
|
||||
|
||||
_, offset := time.Now().Zone()
|
||||
loc := time.FixedZone("", -offset)
|
||||
|
||||
conn, err := setupClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
client := gctrpc.NewGoCryptoTraderClient(conn)
|
||||
result, err := client.WithdrawalEventsByDate(context.Background(),
|
||||
&gctrpc.WithdrawalEventsByDateRequest{
|
||||
Exchange: exchange,
|
||||
Start: s.In(loc).Format(timeFormat),
|
||||
End: e.In(loc).Format(timeFormat),
|
||||
Limit: int32(limit),
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
jsonOutput(result)
|
||||
return nil
|
||||
}
|
||||
|
||||
var getLoggerDetailsCommand = cli.Command{
|
||||
@@ -2953,11 +3424,6 @@ func clearScreen() error {
|
||||
}
|
||||
}
|
||||
|
||||
const timeFormat = "2006-01-02 15:04:05"
|
||||
|
||||
var startTime, endTime, order string
|
||||
var limit int
|
||||
|
||||
var getAuditEventCommand = cli.Command{
|
||||
Name: "getauditevent",
|
||||
Usage: "gets audit events matching query parameters",
|
||||
|
||||
@@ -124,6 +124,7 @@ func main() {
|
||||
getCryptocurrencyDepositAddressCommand,
|
||||
withdrawCryptocurrencyFundsCommand,
|
||||
withdrawFiatFundsCommand,
|
||||
withdrawalRequestCommand,
|
||||
getLoggerDetailsCommand,
|
||||
setLoggerDetailsCommand,
|
||||
getExchangePairsCommand,
|
||||
|
||||
Reference in New Issue
Block a user