gRPC/Engine/Exchanges: Implement direct getwithdrawalshistory method (#600)

* GetClosedOrder implemented for Kraken and Binance, fixed Binance MARKET order creaton, added rate, fee and cost fileds on SubmitOrder responce

* return Trades on Binance SubmitOrder, new validation methods on Binance and kraken GetClosedOrderInfo

* removed the Binance extra method GetClosedOrder

* func description corrected

* removed price, fee and cost from SimulateOrder response, as we get all necessary info in response to calculate them on client side

* GetClosedOrder implementation moved to GetOrderInfo

* changed GetOrderInfo params

* removed Canceled order.Type used for Kraken

* update QueryOrder in gctscript

* add missed params to QueryOrder validator (gctscript)

* fixed testing issues

* GetClosedOrder implemented for Kraken and Binance, fixed Binance MARKET order creaton, added rate, fee and cost fileds on SubmitOrder responce

* return Trades on Binance SubmitOrder, new validation methods on Binance and kraken GetClosedOrderInfo

* removed the Binance extra method GetClosedOrder

* func description corrected

* removed price, fee and cost from SimulateOrder response, as we get all necessary info in response to calculate them on client side

* GetClosedOrder implementation moved to GetOrderInfo

* changed GetOrderInfo params

* removed Canceled order.Type used for Kraken

* update QueryOrder in gctscript

* add missed params to QueryOrder validator (gctscript)

* fixed testing issues

* pull previous changes

* linter issues fix

* updated query_order exmple in gctscript, fixed params check

* removed orderPair unnecessary conversion

* added wsCancelAllOrders, fixed bugs

* fixed Kraken wsAddOrder method

* cleanup

* CancelBatchOrders implementation

* changed CancelBatchOrders signature

* fixed tests and wrappers

* btcmarkets_test fix

* cleanup

* cleanup

* changed CancelBatchOrders signature

* fmt

* Update configtest.json

* Update configtest.json

* rollback configtest

* refactored Kraken wsHandleData to allow tests

* removed unnecessary error test in TestWsAddOrderJSON

* dependencies updates

* fixed issue with PortfolioSleepDelay set on startup

* add GetWithdrawalsHistory method to exchanges interface

* param name changes

* add extra params for Binance WithdrawStatus method

* add Binance TestWithdrawHistory

* linter errors fix

Co-authored-by: Vazha Bezhanishvili <vazha.bezhanishvili@elegro.eu>
This commit is contained in:
Vazha
2020-12-04 07:34:50 +02:00
committed by GitHub
parent 8cc1e585d8
commit e3ad2d5731
48 changed files with 1597 additions and 1185 deletions

View File

@@ -746,6 +746,48 @@ func (b *Binance) WithdrawCrypto(asset, address, addressTag, name, amount string
return resp.ID, nil
}
// WithdrawStatus gets the status of recent withdrawals
// status `param` used as string to prevent default value 0 (for int) interpreting as EmailSent status
func (b *Binance) WithdrawStatus(c currency.Code, status string, startTime, endTime int64) ([]WithdrawStatusResponse, error) {
var response struct {
Success bool `json:"success"`
WithdrawList []WithdrawStatusResponse `json:"withdrawList"`
}
path := b.API.Endpoints.URL + withdrawalHistory
params := url.Values{}
params.Set("asset", c.String())
if status != "" {
i, err := strconv.Atoi(status)
if err != nil {
return response.WithdrawList, fmt.Errorf("wrong param (status): %s. Error: %v", status, err)
}
switch i {
case EmailSent, Cancelled, AwaitingApproval, Rejected, Processing, Failure, Completed:
default:
return response.WithdrawList, fmt.Errorf("wrong param (status): %s", status)
}
params.Set("status", status)
}
if startTime > 0 {
params.Set("startTime", strconv.FormatInt(startTime, 10))
}
if endTime > 0 {
params.Set("endTime", strconv.FormatInt(endTime, 10))
}
if err := b.SendAuthHTTPRequest(http.MethodGet, path, params, request.Unset, &response); err != nil {
return response.WithdrawList, err
}
return response.WithdrawList, nil
}
// GetDepositAddressForCurrency retrieves the wallet address for a given currency
func (b *Binance) GetDepositAddressForCurrency(currency string) (string, error) {
path := b.API.Endpoints.URL + depositAddress

View File

@@ -709,6 +709,21 @@ func TestWithdraw(t *testing.T) {
}
}
func TestWithdrawHistory(t *testing.T) {
t.Parallel()
if areTestAPIKeysSet() && !canManipulateRealOrders && !mockTests {
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
}
_, err := b.GetWithdrawalsHistory(currency.XBT)
switch {
case areTestAPIKeysSet() && err != nil:
t.Error("GetWithdrawalsHistory() error", err)
case !areTestAPIKeysSet() && err == nil && !mockTests:
t.Error("GetWithdrawalsHistory() expecting an error when no keys are set")
}
}
func TestWithdrawFiat(t *testing.T) {
t.Parallel()

View File

@@ -6,6 +6,17 @@ import (
"github.com/thrasher-corp/gocryptotrader/currency"
)
// withdrawals status codes description
const (
EmailSent = iota
Cancelled
AwaitingApproval
Rejected
Processing
Failure
Completed
)
// Response holds basic binance api response data
type Response struct {
Code int `json:"code"`
@@ -607,6 +618,19 @@ type WithdrawResponse struct {
ID string `json:"id"`
}
// WithdrawStatusResponse defines a withdrawal status response
type WithdrawStatusResponse struct {
Amount float64 `json:"amount"`
TransactionFee float64 `json:"transactionFee"`
Address string `json:"address"`
TxID string `json:"txId"`
ID string `json:"id"`
Asset string `json:"asset"`
ApplyTime int64 `json:"applyTime"`
Status int64 `json:"status"`
Network string `json:"network"`
}
// UserAccountStream contains a key to maintain an authorised
// websocket connection
type UserAccountStream struct {

View File

@@ -498,6 +498,29 @@ func (b *Binance) GetFundingHistory() ([]exchange.FundHistory, error) {
return nil, common.ErrFunctionNotSupported
}
// GetWithdrawalsHistory returns previous withdrawals data
func (b *Binance) GetWithdrawalsHistory(c currency.Code) (resp []exchange.WithdrawalHistory, err error) {
w, err := b.WithdrawStatus(c, "", 0, 0)
if err != nil {
return nil, err
}
for i := range w {
resp = append(resp, exchange.WithdrawalHistory{
Status: strconv.FormatInt(w[i].Status, 10),
TransferID: w[i].ID,
Currency: w[i].Asset,
Amount: w[i].Amount,
Fee: w[i].TransactionFee,
CryptoToAddress: w[i].Address,
CryptoTxID: w[i].TxID,
Timestamp: time.Unix(w[i].ApplyTime/1000, 0),
})
}
return resp, nil
}
// GetRecentTrades returns the most recent trades for a currency and asset
func (b *Binance) GetRecentTrades(p currency.Pair, assetType asset.Item) ([]trade.Data, error) {
var err error