mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 15:09:42 +00:00
account: refactor for save holdings (#1846)
* account: refactor for save holdings Signed-off-by: Ye Sijun <junnplus@gmail.com> * Update exchanges/account/account.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * Update exchanges/account/account.go Co-authored-by: Scott <gloriousCode@users.noreply.github.com> * account: minor changes Signed-off-by: Ye Sijun <junnplus@gmail.com> --------- Signed-off-by: Ye Sijun <junnplus@gmail.com> Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> Co-authored-by: Scott <gloriousCode@users.noreply.github.com>
This commit is contained in:
@@ -653,36 +653,6 @@ func (s *RPCServer) GetAccountInfoStream(r *gctrpc.GetAccountInfoRequest, stream
|
||||
return err
|
||||
}
|
||||
|
||||
initAcc, err := exch.GetCachedAccountInfo(stream.Context(), assetType)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
accounts := make([]*gctrpc.Account, len(initAcc.Accounts))
|
||||
for x := range initAcc.Accounts {
|
||||
subAccounts := make([]*gctrpc.AccountCurrencyInfo, len(initAcc.Accounts[x].Currencies))
|
||||
for y := range initAcc.Accounts[x].Currencies {
|
||||
subAccounts[y] = &gctrpc.AccountCurrencyInfo{
|
||||
Currency: initAcc.Accounts[x].Currencies[y].Currency.String(),
|
||||
TotalValue: initAcc.Accounts[x].Currencies[y].Total,
|
||||
Hold: initAcc.Accounts[x].Currencies[y].Hold,
|
||||
UpdatedAt: timestamppb.New(initAcc.Accounts[x].Currencies[y].UpdatedAt),
|
||||
}
|
||||
}
|
||||
accounts[x] = &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
|
||||
@@ -694,16 +664,23 @@ func (s *RPCServer) GetAccountInfoStream(r *gctrpc.GetAccountInfoRequest, stream
|
||||
log.Errorln(log.DispatchMgr, pipeErr)
|
||||
}
|
||||
}()
|
||||
init := make(chan struct{}, 1)
|
||||
init <- struct{}{}
|
||||
|
||||
for {
|
||||
data, ok := <-pipe.Channel()
|
||||
if !ok {
|
||||
return errDispatchSystem
|
||||
select {
|
||||
case <-stream.Context().Done():
|
||||
return stream.Context().Err()
|
||||
case _, ok := <-pipe.Channel():
|
||||
if !ok {
|
||||
return errDispatchSystem
|
||||
}
|
||||
case <-init:
|
||||
}
|
||||
|
||||
holdings, ok := data.(*account.Holdings)
|
||||
if !ok {
|
||||
return common.GetTypeAssertError("*account.Holdings", data)
|
||||
holdings, err := exch.GetCachedAccountInfo(stream.Context(), assetType)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
accounts := make([]*gctrpc.Account, len(holdings.Accounts))
|
||||
|
||||
Reference in New Issue
Block a user