mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-03 15:10:49 +00:00
Expose auth validator functionality for wrapper (#416)
* expose auth validator functionality for wrapper * Add REST validation after keys set, package account types for future syncing * Add transient error checking for initial creddemtial validation * fix command types * Addressed nits from glorious person * Amalgamate body within error when not between 2xx status, added btcmarket specific auth error check * nit fix for glorious person * Format fix * removed unused code * check transient first then validate if its an exchange specific authentication error, all others will be disregarded * Addressed glorious nits * Addressed glorious nits * Moved account processing to updateaccountinfo func and added in fetch account info * Add GRPC Account streaming (NOTE: could not complete until sync item added) * RM exchange check * Address xtda nits * RM comment code * Fix linter issues * used most recent protoc version * lbank linter issues fixed * Addressed nits and changed len check to range in for loops * Fixed timeout issue * thrasher nits addressed * add string holdings
This commit is contained in:
@@ -24,6 +24,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/database/models/postgres"
|
||||
"github.com/thrasher-corp/gocryptotrader/database/models/sqlite3"
|
||||
"github.com/thrasher-corp/gocryptotrader/database/repository/audit"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/account"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
||||
@@ -448,7 +449,7 @@ func (s *RPCServer) GetAccountInfo(ctx context.Context, r *gctrpc.GetAccountInfo
|
||||
return nil, errors.New("exchange is not loaded/doesn't exist")
|
||||
}
|
||||
|
||||
resp, err := exch.GetAccountInfo()
|
||||
resp, err := exch.FetchAccountInfo()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -470,6 +471,87 @@ func (s *RPCServer) GetAccountInfo(ctx context.Context, r *gctrpc.GetAccountInfo
|
||||
return &gctrpc.GetAccountInfoResponse{Exchange: r.Exchange, Accounts: accounts}, nil
|
||||
}
|
||||
|
||||
// GetAccountInfoStream streams an account balance for a specific exchange
|
||||
func (s *RPCServer) GetAccountInfoStream(r *gctrpc.GetAccountInfoRequest, stream gctrpc.GoCryptoTrader_GetAccountInfoStreamServer) error {
|
||||
if r.Exchange == "" {
|
||||
return errors.New(errExchangeNameUnset)
|
||||
}
|
||||
|
||||
exch := GetExchangeByName(r.Exchange)
|
||||
if exch == nil {
|
||||
return errors.New("exchange is not loaded/doesn't exist")
|
||||
}
|
||||
|
||||
initAcc, err := exch.FetchAccountInfo()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var accounts []*gctrpc.Account
|
||||
for x := range initAcc.Accounts {
|
||||
var subAccounts []*gctrpc.AccountCurrencyInfo
|
||||
for y := range initAcc.Accounts[x].Currencies {
|
||||
subAccounts = append(subAccounts, &gctrpc.AccountCurrencyInfo{
|
||||
Currency: initAcc.Accounts[x].Currencies[y].CurrencyName.String(),
|
||||
TotalValue: initAcc.Accounts[x].Currencies[y].TotalValue,
|
||||
Hold: initAcc.Accounts[x].Currencies[y].Hold,
|
||||
})
|
||||
}
|
||||
accounts = append(accounts, &gctrpc.Account{
|
||||
Id: initAcc.Accounts[x].ID,
|
||||
Currencies: subAccounts,
|
||||
})
|
||||
}
|
||||
|
||||
err = stream.Send(&gctrpc.GetAccountInfoResponse{
|
||||
Exchange: initAcc.Exchange,
|
||||
Accounts: accounts,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pipe, err := account.SubscribeToExchangeAccount(r.Exchange)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer pipe.Release()
|
||||
|
||||
for {
|
||||
data, ok := <-pipe.C
|
||||
if !ok {
|
||||
return errors.New(errDispatchSystem)
|
||||
}
|
||||
|
||||
acc := (*data.(*interface{})).(account.Holdings)
|
||||
|
||||
var accounts []*gctrpc.Account
|
||||
for x := range acc.Accounts {
|
||||
var subAccounts []*gctrpc.AccountCurrencyInfo
|
||||
for y := range acc.Accounts[x].Currencies {
|
||||
subAccounts = append(subAccounts, &gctrpc.AccountCurrencyInfo{
|
||||
Currency: acc.Accounts[x].Currencies[y].CurrencyName.String(),
|
||||
TotalValue: acc.Accounts[x].Currencies[y].TotalValue,
|
||||
Hold: acc.Accounts[x].Currencies[y].Hold,
|
||||
})
|
||||
}
|
||||
accounts = append(accounts, &gctrpc.Account{
|
||||
Id: acc.Accounts[x].ID,
|
||||
Currencies: subAccounts,
|
||||
})
|
||||
}
|
||||
|
||||
err := stream.Send(&gctrpc.GetAccountInfoResponse{
|
||||
Exchange: acc.Exchange,
|
||||
Accounts: accounts,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GetConfig returns the bots config
|
||||
func (s *RPCServer) GetConfig(ctx context.Context, r *gctrpc.GetConfigRequest) (*gctrpc.GetConfigResponse, error) {
|
||||
return &gctrpc.GetConfigResponse{}, common.ErrNotYetImplemented
|
||||
|
||||
Reference in New Issue
Block a user