mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
Add bash/zsh autocomplete files and minor fixes
This commit is contained in:
@@ -56,6 +56,7 @@ func main() {
|
||||
app := cli.NewApp()
|
||||
app.Name = "gctcli"
|
||||
app.Version = core.Version(true)
|
||||
app.EnableBashCompletion = true
|
||||
app.Usage = "command line interface for managing the gocryptotrader daemon"
|
||||
app.Flags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
|
||||
23
contrib/bash_autocomplete
Normal file
23
contrib/bash_autocomplete
Normal file
@@ -0,0 +1,23 @@
|
||||
#! /bin/bash
|
||||
# bash programmable completion for gctcli
|
||||
# copy to /etc/bash_completion.d/gctcli and source it or restart your shell
|
||||
|
||||
: ${PROG:=$(basename ${BASH_SOURCE})}
|
||||
|
||||
_gctcli() {
|
||||
if [[ "${COMP_WORDS[0]}" != "source" ]]; then
|
||||
local cur opts base
|
||||
COMPREPLY=()
|
||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
if [[ "$cur" == "-"* ]]; then
|
||||
opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} ${cur} --generate-bash-completion )
|
||||
else
|
||||
opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash-completion )
|
||||
fi
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
complete -o bashdefault -o default -o nospace -F _gctcli $PROG
|
||||
unset PROG
|
||||
14
contrib/zsh_autocomplete
Normal file
14
contrib/zsh_autocomplete
Normal file
@@ -0,0 +1,14 @@
|
||||
# zsh programmable completion for gctcli
|
||||
# source zsh_autocomplete
|
||||
|
||||
_gctcli() {
|
||||
|
||||
local -a opts
|
||||
opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} --generate-bash-completion)}")
|
||||
|
||||
_describe 'values' opts
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
compdef _gctcli gctcli
|
||||
@@ -74,7 +74,7 @@ func printTickerSummary(result *ticker.Price, p currency.Pair, assetType asset.I
|
||||
log.Infof(log.Ticker, "%s %s %s: TICKER: Last %s Ask %s Bid %s High %s Low %s Volume %.8f\n",
|
||||
exchangeName,
|
||||
FormatCurrency(p).String(),
|
||||
assetType,
|
||||
strings.ToUpper(assetType.String()),
|
||||
printConvertCurrencyFormat(origCurrency, result.Last),
|
||||
printConvertCurrencyFormat(origCurrency, result.Ask),
|
||||
printConvertCurrencyFormat(origCurrency, result.Bid),
|
||||
@@ -87,7 +87,7 @@ func printTickerSummary(result *ticker.Price, p currency.Pair, assetType asset.I
|
||||
log.Infof(log.Ticker, "%s %s %s: TICKER: Last %s Ask %s Bid %s High %s Low %s Volume %.8f\n",
|
||||
exchangeName,
|
||||
FormatCurrency(p).String(),
|
||||
assetType,
|
||||
strings.ToUpper(assetType.String()),
|
||||
printCurrencyFormat(result.Last),
|
||||
printCurrencyFormat(result.Ask),
|
||||
printCurrencyFormat(result.Bid),
|
||||
@@ -98,7 +98,7 @@ func printTickerSummary(result *ticker.Price, p currency.Pair, assetType asset.I
|
||||
log.Infof(log.Ticker, "%s %s %s: TICKER: Last %.8f Ask %.8f Bid %.8f High %.8f Low %.8f Volume %.8f\n",
|
||||
exchangeName,
|
||||
FormatCurrency(p).String(),
|
||||
assetType,
|
||||
strings.ToUpper(assetType.String()),
|
||||
result.Last,
|
||||
result.Ask,
|
||||
result.Bid,
|
||||
@@ -128,7 +128,7 @@ func printOrderbookSummary(result *orderbook.Base, p currency.Pair, assetType as
|
||||
log.Infof(log.OrderBook, "%s %s %s: ORDERBOOK: Bids len: %d Amount: %f %s. Total value: %s Asks len: %d Amount: %f %s. Total value: %s\n",
|
||||
exchangeName,
|
||||
FormatCurrency(p).String(),
|
||||
assetType,
|
||||
strings.ToUpper(assetType.String()),
|
||||
len(result.Bids),
|
||||
bidsAmount,
|
||||
p.Base.String(),
|
||||
@@ -144,7 +144,7 @@ func printOrderbookSummary(result *orderbook.Base, p currency.Pair, assetType as
|
||||
log.Infof(log.OrderBook, "%s %s %s: ORDERBOOK: Bids len: %d Amount: %f %s. Total value: %s Asks len: %d Amount: %f %s. Total value: %s\n",
|
||||
exchangeName,
|
||||
FormatCurrency(p).String(),
|
||||
assetType,
|
||||
strings.ToUpper(assetType.String()),
|
||||
len(result.Bids),
|
||||
bidsAmount,
|
||||
p.Base.String(),
|
||||
@@ -158,7 +158,7 @@ func printOrderbookSummary(result *orderbook.Base, p currency.Pair, assetType as
|
||||
log.Infof(log.OrderBook, "%s %s %s: ORDERBOOK: Bids len: %d Amount: %f %s. Total value: %f Asks len: %d Amount: %f %s. Total value: %f\n",
|
||||
exchangeName,
|
||||
FormatCurrency(p).String(),
|
||||
assetType,
|
||||
strings.ToUpper(assetType.String()),
|
||||
len(result.Bids),
|
||||
bidsAmount,
|
||||
p.Base.String(),
|
||||
|
||||
@@ -607,7 +607,6 @@ func (s *RPCServer) GetForexRates(ctx context.Context, r *gctrpc.GetForexRatesRe
|
||||
func (s *RPCServer) GetOrders(ctx context.Context, r *gctrpc.GetOrdersRequest) (*gctrpc.GetOrdersResponse, error) {
|
||||
exch := GetExchangeByName(r.Exchange)
|
||||
if exch == nil {
|
||||
log.Debugln(log.GRPCSys, exch)
|
||||
return nil, errors.New("exchange is not loaded/doesn't exist")
|
||||
}
|
||||
|
||||
|
||||
@@ -48,13 +48,11 @@ func NewCurrencyPairSyncer(c CurrencyPairSyncerConfig) (*ExchangeCurrencyPairSyn
|
||||
|
||||
s.tickerBatchLastRequested = make(map[string]time.Time)
|
||||
|
||||
log.Debugln(log.SyncMgr, "Exchange currency pair syncer config:")
|
||||
log.Debugf(log.SyncMgr, "SyncContinuously: %v\n", s.Cfg.SyncContinuously)
|
||||
log.Debugf(log.SyncMgr, "SyncTicker: %v\n", s.Cfg.SyncTicker)
|
||||
log.Debugf(log.SyncMgr, "SyncOrderbook: %v\n", s.Cfg.SyncOrderbook)
|
||||
log.Debugf(log.SyncMgr, "SyncTrades: %v\n", s.Cfg.SyncTrades)
|
||||
log.Debugf(log.SyncMgr, "NumWorkers: %v\n", s.Cfg.NumWorkers)
|
||||
|
||||
log.Debugf(log.SyncMgr,
|
||||
"Exchange currency pair syncer config: continuous: %v ticker: %v"+
|
||||
" orderbook: %v trades: %v workers: %v verbose: %v\n",
|
||||
s.Cfg.SyncContinuously, s.Cfg.SyncTicker, s.Cfg.SyncOrderbook,
|
||||
s.Cfg.SyncTrades, s.Cfg.NumWorkers, s.Cfg.Verbose)
|
||||
return &s, nil
|
||||
}
|
||||
|
||||
@@ -92,8 +90,12 @@ func (e *ExchangeCurrencyPairSyncer) add(c *CurrencyPairSyncAgent) {
|
||||
defer e.mux.Unlock()
|
||||
|
||||
if e.Cfg.SyncTicker {
|
||||
log.Debugf(log.SyncMgr, "%s: Added ticker sync item %v: using websocket: %v using REST: %v\n",
|
||||
c.Exchange, FormatCurrency(c.Pair).String(), c.Ticker.IsUsingWebsocket, c.Ticker.IsUsingREST)
|
||||
if e.Cfg.Verbose {
|
||||
log.Debugf(log.SyncMgr,
|
||||
"%s: Added ticker sync item %v: using websocket: %v using REST: %v\n",
|
||||
c.Exchange, FormatCurrency(c.Pair).String(), c.Ticker.IsUsingWebsocket,
|
||||
c.Ticker.IsUsingREST)
|
||||
}
|
||||
if atomic.LoadInt32(&e.initSyncCompleted) != 1 {
|
||||
e.initSyncWG.Add(1)
|
||||
createdCounter++
|
||||
@@ -101,8 +103,12 @@ func (e *ExchangeCurrencyPairSyncer) add(c *CurrencyPairSyncAgent) {
|
||||
}
|
||||
|
||||
if e.Cfg.SyncOrderbook {
|
||||
log.Debugf(log.SyncMgr, "%s: Added orderbook sync item %v: using websocket: %v using REST: %v\n",
|
||||
c.Exchange, FormatCurrency(c.Pair).String(), c.Orderbook.IsUsingWebsocket, c.Orderbook.IsUsingREST)
|
||||
if e.Cfg.Verbose {
|
||||
log.Debugf(log.SyncMgr,
|
||||
"%s: Added orderbook sync item %v: using websocket: %v using REST: %v\n",
|
||||
c.Exchange, FormatCurrency(c.Pair).String(), c.Orderbook.IsUsingWebsocket,
|
||||
c.Orderbook.IsUsingREST)
|
||||
}
|
||||
if atomic.LoadInt32(&e.initSyncCompleted) != 1 {
|
||||
e.initSyncWG.Add(1)
|
||||
createdCounter++
|
||||
@@ -110,8 +116,12 @@ func (e *ExchangeCurrencyPairSyncer) add(c *CurrencyPairSyncAgent) {
|
||||
}
|
||||
|
||||
if e.Cfg.SyncTrades {
|
||||
log.Debugf(log.SyncMgr, "%s: Added trade sync item %v: using websocket: %v using REST: %v\n",
|
||||
c.Exchange, FormatCurrency(c.Pair).String(), c.Trade.IsUsingWebsocket, c.Trade.IsUsingREST)
|
||||
if e.Cfg.Verbose {
|
||||
log.Debugf(log.SyncMgr,
|
||||
"%s: Added trade sync item %v: using websocket: %v using REST: %v\n",
|
||||
c.Exchange, FormatCurrency(c.Pair).String(), c.Trade.IsUsingWebsocket,
|
||||
c.Trade.IsUsingREST)
|
||||
}
|
||||
if atomic.LoadInt32(&e.initSyncCompleted) != 1 {
|
||||
e.initSyncWG.Add(1)
|
||||
createdCounter++
|
||||
@@ -280,7 +290,8 @@ func (e *ExchangeCurrencyPairSyncer) worker() {
|
||||
if Bot.Exchanges[x].SupportsWebsocket() && Bot.Exchanges[x].IsWebsocketEnabled() {
|
||||
ws, err := Bot.Exchanges[x].GetWebsocket()
|
||||
if err != nil {
|
||||
log.Errorf(log.SyncMgr, "%s unable to get websocket pointer. Err: %s\n", exchangeName, err)
|
||||
log.Errorf(log.SyncMgr, "%s unable to get websocket pointer. Err: %s\n",
|
||||
exchangeName, err)
|
||||
usingREST = true
|
||||
}
|
||||
|
||||
@@ -348,7 +359,8 @@ func (e *ExchangeCurrencyPairSyncer) worker() {
|
||||
e.setProcessing(c.Exchange, c.Pair, c.AssetType, SyncItemTicker, true)
|
||||
c.Ticker.IsUsingWebsocket = false
|
||||
c.Ticker.IsUsingREST = true
|
||||
log.Warnf(log.SyncMgr, "%s %s: No ticker update after 10 seconds, switching from websocket to rest\n",
|
||||
log.Warnf(log.SyncMgr,
|
||||
"%s %s: No ticker update after 10 seconds, switching from websocket to rest\n",
|
||||
c.Exchange, FormatCurrency(p).String())
|
||||
e.setProcessing(c.Exchange, c.Pair, c.AssetType, SyncItemTicker, false)
|
||||
}
|
||||
@@ -410,7 +422,8 @@ func (e *ExchangeCurrencyPairSyncer) worker() {
|
||||
e.setProcessing(c.Exchange, c.Pair, c.AssetType, SyncItemOrderbook, true)
|
||||
c.Orderbook.IsUsingWebsocket = false
|
||||
c.Orderbook.IsUsingREST = true
|
||||
log.Warnf(log.SyncMgr, "%s %s: No orderbook update after 15 seconds, switching from websocket to rest\n",
|
||||
log.Warnf(log.SyncMgr,
|
||||
"%s %s: No orderbook update after 15 seconds, switching from websocket to rest\n",
|
||||
c.Exchange, FormatCurrency(c.Pair).String())
|
||||
e.setProcessing(c.Exchange, c.Pair, c.AssetType, SyncItemOrderbook, false)
|
||||
}
|
||||
@@ -461,21 +474,20 @@ func (e *ExchangeCurrencyPairSyncer) Start() {
|
||||
supportsREST := Bot.Exchanges[x].SupportsREST()
|
||||
|
||||
if !supportsREST && !supportsWebsocket {
|
||||
log.Warnf(log.SyncMgr, "Loaded exchange %s does not support REST or Websocket.\n", exchangeName)
|
||||
log.Warnf(log.SyncMgr,
|
||||
"Loaded exchange %s does not support REST or Websocket.\n",
|
||||
exchangeName)
|
||||
continue
|
||||
}
|
||||
|
||||
var usingWebsocket bool
|
||||
var usingREST bool
|
||||
|
||||
if supportsWebsocket {
|
||||
if supportsWebsocket && Bot.Exchanges[x].IsWebsocketEnabled() {
|
||||
ws, err := Bot.Exchanges[x].GetWebsocket()
|
||||
if err != nil {
|
||||
log.Errorf(log.SyncMgr, "%s failed to get websocket. Err: %s\n", exchangeName, err)
|
||||
usingREST = true
|
||||
}
|
||||
|
||||
if !ws.IsEnabled() {
|
||||
log.Errorf(log.SyncMgr, "%s failed to get websocket. Err: %s\n",
|
||||
exchangeName, err)
|
||||
usingREST = true
|
||||
}
|
||||
|
||||
@@ -484,7 +496,8 @@ func (e *ExchangeCurrencyPairSyncer) Start() {
|
||||
|
||||
err = ws.Connect()
|
||||
if err != nil {
|
||||
log.Errorf(log.SyncMgr, "%s websocket failed to connect. Err: %s\n", exchangeName, err)
|
||||
log.Errorf(log.SyncMgr, "%s websocket failed to connect. Err: %s\n",
|
||||
exchangeName, err)
|
||||
usingREST = true
|
||||
} else {
|
||||
usingWebsocket = true
|
||||
|
||||
Reference in New Issue
Block a user