mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-14 07:26:47 +00:00
accounts: Move to instance methods, fix races and isolate tests (#1923)
* Bybit: Fix race in TestUpdateAccountInfo and TestWSHandleData * DriveBy rename TestWSHandleData * This doesn't address running with -race=2+ due to the singleton * Accounts: Add account.GetService() * exchange: Assertify TestSetupDefaults * Exchanges: Add account.Service override for testing * Exchanges: Remove duplicate IsWebsocketEnabled test from TestSetupDefaults * Dispatch: Replace nil checks with NilGuard * Engine: Remove deprecated printAccountHoldingsChangeSummary * Dispatcher: Add EnsureRunning method * Accounts: Move singleton accounts service to exchange Accounts * Move singleton accounts service to exchange Accounts This maintains the concept of a global store, whilst allowing exchanges to override it when needed, particularly for testing. APIServer: * Remove getAllActiveAccounts from apiserver Deprecated apiserver only thing using this, so remove it instead of updating it * Update comment for UpdateAccountBalances everywhere * Docs: Add punctuation to function comments * Bybit: Coverage for wsProcessWalletPushData Save
This commit is contained in:
@@ -575,24 +575,26 @@ func getTickers(c *cli.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
var getAccountInfoCommand = &cli.Command{
|
||||
Name: "getaccountinfo",
|
||||
Usage: "gets the exchange account balance info",
|
||||
var getAccountBalancesCommand = &cli.Command{
|
||||
Name: "getaccountbalances",
|
||||
Usage: "gets the exchange account balances",
|
||||
ArgsUsage: "<exchange> <asset>",
|
||||
Action: getAccountInfo,
|
||||
Action: getAccountBalances,
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "exchange",
|
||||
Usage: "the exchange to get the account info for",
|
||||
Name: "exchange",
|
||||
Usage: "the exchange to get the account balances for",
|
||||
Required: true,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "asset",
|
||||
Usage: "the asset type to get the account info for",
|
||||
Name: "asset",
|
||||
Usage: "the asset type to get the account balances for",
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func getAccountInfo(c *cli.Context) error {
|
||||
func getAccountBalances(c *cli.Context) error {
|
||||
if c.NArg() == 0 && c.NumFlags() == 0 {
|
||||
return cli.ShowSubcommandHelp(c)
|
||||
}
|
||||
@@ -621,8 +623,8 @@ func getAccountInfo(c *cli.Context) error {
|
||||
defer closeConn(conn, cancel)
|
||||
|
||||
client := gctrpc.NewGoCryptoTraderServiceClient(conn)
|
||||
result, err := client.GetAccountInfo(c.Context,
|
||||
&gctrpc.GetAccountInfoRequest{
|
||||
result, err := client.GetAccountBalances(c.Context,
|
||||
&gctrpc.GetAccountBalancesRequest{
|
||||
Exchange: exchange,
|
||||
AssetType: assetType,
|
||||
},
|
||||
@@ -635,24 +637,24 @@ func getAccountInfo(c *cli.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
var getAccountInfoStreamCommand = &cli.Command{
|
||||
Name: "getaccountinfostream",
|
||||
Usage: "gets the account info stream for a specific exchange",
|
||||
var getAccountBalancesStreamCommand = &cli.Command{
|
||||
Name: "getaccountbalancesstream",
|
||||
Usage: "gets the account balances stream for a specific exchange",
|
||||
ArgsUsage: "<exchange> <asset>",
|
||||
Action: getAccountInfoStream,
|
||||
Action: getAccountBalancesStream,
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "exchange",
|
||||
Usage: "the exchange to get the account info stream from",
|
||||
Usage: "the exchange to get the account balances stream from",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "asset",
|
||||
Usage: "the asset type to get the account info stream for",
|
||||
Usage: "the asset type to get the account balances stream for",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func getAccountInfoStream(c *cli.Context) error {
|
||||
func getAccountBalancesStream(c *cli.Context) error {
|
||||
if c.NArg() == 0 && c.NumFlags() == 0 {
|
||||
return cli.ShowSubcommandHelp(c)
|
||||
}
|
||||
@@ -683,8 +685,8 @@ func getAccountInfoStream(c *cli.Context) error {
|
||||
defer closeConn(conn, cancel)
|
||||
|
||||
client := gctrpc.NewGoCryptoTraderServiceClient(conn)
|
||||
result, err := client.GetAccountInfoStream(c.Context,
|
||||
&gctrpc.GetAccountInfoRequest{Exchange: exchangeName, AssetType: assetType})
|
||||
result, err := client.GetAccountBalancesStream(c.Context,
|
||||
&gctrpc.GetAccountBalancesRequest{Exchange: exchangeName, AssetType: assetType})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -706,24 +708,24 @@ func getAccountInfoStream(c *cli.Context) error {
|
||||
}
|
||||
}
|
||||
|
||||
var updateAccountInfoCommand = &cli.Command{
|
||||
Name: "updateaccountinfo",
|
||||
Usage: "updates the exchange account balance info",
|
||||
var updateAccountBalancesCommand = &cli.Command{
|
||||
Name: "updateaccountbalances",
|
||||
Usage: "updates the exchange account balances",
|
||||
ArgsUsage: "<exchange> <asset>",
|
||||
Action: updateAccountInfo,
|
||||
Action: updateAccountBalances,
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "exchange",
|
||||
Usage: "the exchange to get the account info for",
|
||||
Usage: "the exchange to get the account balances for",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "asset",
|
||||
Usage: "the asset type to get the account info for",
|
||||
Usage: "the asset type to get the account balances for",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func updateAccountInfo(c *cli.Context) error {
|
||||
func updateAccountBalances(c *cli.Context) error {
|
||||
if c.NArg() == 0 && c.NumFlags() == 0 {
|
||||
return cli.ShowSubcommandHelp(c)
|
||||
}
|
||||
@@ -753,8 +755,8 @@ func updateAccountInfo(c *cli.Context) error {
|
||||
defer closeConn(conn, cancel)
|
||||
|
||||
client := gctrpc.NewGoCryptoTraderServiceClient(conn)
|
||||
result, err := client.UpdateAccountInfo(c.Context,
|
||||
&gctrpc.GetAccountInfoRequest{
|
||||
result, err := client.UpdateAccountBalances(c.Context,
|
||||
&gctrpc.GetAccountBalancesRequest{
|
||||
Exchange: exchange,
|
||||
AssetType: assetType,
|
||||
},
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
"github.com/thrasher-corp/gocryptotrader/core"
|
||||
"github.com/thrasher-corp/gocryptotrader/encoding/json"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/account"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchange/accounts"
|
||||
"github.com/thrasher-corp/gocryptotrader/gctrpc/auth"
|
||||
"github.com/thrasher-corp/gocryptotrader/signaler"
|
||||
"github.com/urfave/cli/v2"
|
||||
@@ -28,7 +28,7 @@ var (
|
||||
pairDelimiter string
|
||||
certPath string
|
||||
timeout time.Duration
|
||||
exchangeCreds account.Credentials
|
||||
exchangeCreds accounts.Credentials
|
||||
verbose bool
|
||||
ignoreTimeout bool
|
||||
)
|
||||
@@ -172,9 +172,9 @@ func main() {
|
||||
getExchangeInfoCommand,
|
||||
getTickerCommand,
|
||||
getTickersCommand,
|
||||
getAccountInfoCommand,
|
||||
getAccountInfoStreamCommand,
|
||||
updateAccountInfoCommand,
|
||||
getAccountBalancesCommand,
|
||||
getAccountBalancesStreamCommand,
|
||||
updateAccountBalancesCommand,
|
||||
getConfigCommand,
|
||||
getPortfolioCommand,
|
||||
getPortfolioSummaryCommand,
|
||||
|
||||
Reference in New Issue
Block a user