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

@@ -173,6 +173,9 @@ func (h *FakePassingExchange) GetOrderInfo(_ string, _ currency.Pair, _ asset.It
ID: "fakeOrder",
}, nil
}
func (h *FakePassingExchange) GetWithdrawalsHistory(_ currency.Code) ([]exchange.WithdrawalHistory, error) {
return nil, nil
}
func (h *FakePassingExchange) GetDepositAddress(_ currency.Code, _ string) (string, error) {
return "", nil
}

View File

@@ -1303,6 +1303,20 @@ func (s *RPCServer) WithdrawalEventByID(_ context.Context, r *gctrpc.WithdrawalE
// WithdrawalEventsByExchange returns previous withdrawal request details by exchange
func (s *RPCServer) WithdrawalEventsByExchange(_ context.Context, r *gctrpc.WithdrawalEventsByExchangeRequest) (*gctrpc.WithdrawalEventsByExchangeResponse, error) {
if !s.Config.Database.Enabled {
if r.Id == "" {
exch := s.GetExchangeByName(r.Exchange)
if exch == nil {
return nil, errExchangeNotLoaded
}
c := currency.NewCode(strings.ToUpper(r.Currency))
ret, err := exch.GetWithdrawalsHistory(c)
if err != nil {
return nil, err
}
return parseWithdrawalsHistory(ret, exch.GetName(), int(r.Limit)), nil
}
return nil, database.ErrDatabaseSupportDisabled
}
if r.Id == "" {

View File

@@ -6,6 +6,7 @@ import (
"github.com/golang/protobuf/ptypes"
withdrawDataStore "github.com/thrasher-corp/gocryptotrader/database/repository/withdraw"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
"github.com/thrasher-corp/gocryptotrader/gctrpc"
"github.com/thrasher-corp/gocryptotrader/log"
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
@@ -159,6 +160,43 @@ func parseMultipleEvents(ret []*withdraw.Response) *gctrpc.WithdrawalEventsByExc
return v
}
func parseWithdrawalsHistory(ret []exchange.WithdrawalHistory, exchName string, limit int) *gctrpc.WithdrawalEventsByExchangeResponse {
v := &gctrpc.WithdrawalEventsByExchangeResponse{}
for x := range ret {
if limit > 0 && x >= limit {
return v
}
tempEvent := &gctrpc.WithdrawalEventResponse{
Id: ret[x].TransferID,
Exchange: &gctrpc.WithdrawlExchangeEvent{
Name: exchName,
Status: ret[x].Status,
},
Request: &gctrpc.WithdrawalRequestEvent{
Currency: ret[x].Currency,
Description: ret[x].Description,
Amount: ret[x].Amount,
},
}
updatedAtPtype, err := ptypes.TimestampProto(ret[x].Timestamp)
if err != nil {
log.Errorf(log.Global, "failed to convert time: %v", err)
}
tempEvent.UpdatedAt = updatedAtPtype
tempEvent.Request.Crypto = &gctrpc.CryptoWithdrawalEvent{
Address: ret[x].CryptoToAddress,
Fee: ret[x].Fee,
TxId: ret[x].CryptoTxID,
}
v.Event = append(v.Event, tempEvent)
}
return v
}
func parseSingleEvents(ret *withdraw.Response) *gctrpc.WithdrawalEventsByExchangeResponse {
tempEvent := &gctrpc.WithdrawalEventResponse{
Id: ret.ID.String(),