Skip to content

Commit

Permalink
Merge branch 'master' into gateio_sub_out_batch
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan O'Hara-Reid committed Jan 22, 2025
2 parents 0cafc46 + f0c785d commit 3a82828
Show file tree
Hide file tree
Showing 58 changed files with 2,047 additions and 1,278 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/proto-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
- uses: bufbuild/buf-setup-action@v1.47.2
- uses: bufbuild/buf-setup-action@v1.50.0

- name: buf generate
working-directory: ./gctrpc
Expand Down
42 changes: 42 additions & 0 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: stale-checks
on:
schedule:
- cron: '0 0 * * 1-5'
workflow_dispatch:

permissions:
contents: read

env:
DAYS_BEFORE_STALE: ${{ vars.DAYS_BEFORE_STALE }}
DAYS_BEFORE_CLOSE: ${{ vars.DAYS_BEFORE_CLOSE }}
EXEMPT_ISSUE_LABELS: ${{ vars.EXEMPT_ISSUE_LABELS }}
EXEMPT_PR_LABELS: ${{ vars.EXEMPT_PR_LABELS }}

jobs:
stale:
name: Stale issues and PRs check
runs-on: ubuntu-latest
environment: ci
permissions:
issues: write
pull-requests: write
steps:
- uses: actions/stale@v9
with:
# General settings
days-before-stale: ${{ env.DAYS_BEFORE_STALE }}
days-before-close: ${{ env.DAYS_BEFORE_CLOSE }}
exempt-issue-labels: ${{ env.EXEMPT_ISSUE_LABELS }}
exempt-pr-labels: ${{ env.EXEMPT_PR_LABELS }}
enable-statistics: true

# Issue settings
stale-issue-message: 'This issue is stale because it has been open ${{ env.DAYS_BEFORE_STALE }} days with no activity. Please provide an update or this issue will be automatically closed in ${{ env.DAYS_BEFORE_CLOSE }} days.'
close-issue-message: 'This issue was closed because it has been stalled for ${{ env.DAYS_BEFORE_CLOSE }} days with no activity.'
stale-issue-label: 'stale'

# PR settings
stale-pr-message: 'This PR is stale because it has been open ${{ env.DAYS_BEFORE_STALE }} days with no activity. Please provide an update on the progress of this PR.'
days-before-pr-close: -1
stale-pr-label: 'stale'
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ issues:
- text: "Expect WriteFile permissions to be 0600 or less"
linters:
- gosec
- text: 'shadow: declaration of "err" shadows declaration at'
linters: [ govet ]


exclude-dirs:
- vendor
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ Binaries will be published once the codebase reaches a stable condition.

|User|Contribution Amount|
|--|--|
| [thrasher-](https://github.com/thrasher-) | 700 |
| [shazbert](https://github.com/shazbert) | 345 |
| [dependabot[bot]](https://github.com/apps/dependabot) | 317 |
| [gloriousCode](https://github.com/gloriousCode) | 234 |
| [gbjk](https://github.com/gbjk) | 93 |
| [thrasher-](https://github.com/thrasher-) | 703 |
| [shazbert](https://github.com/shazbert) | 355 |
| [dependabot[bot]](https://github.com/apps/dependabot) | 331 |
| [gloriousCode](https://github.com/gloriousCode) | 236 |
| [gbjk](https://github.com/gbjk) | 107 |
| [dependabot-preview[bot]](https://github.com/apps/dependabot-preview) | 88 |
| [xtda](https://github.com/xtda) | 47 |
| [lrascao](https://github.com/lrascao) | 27 |
Expand Down
21 changes: 16 additions & 5 deletions cmd/documentation/exchanges_templates/deribit.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,23 @@ if err != nil {
}
```

### How to do Websocket public/private calls
### Subscriptions

```go
// Exchanges will be abstracted out in further updates and examples will be
// supplied then
```
All default subscriptions are for all enabled assets.

Default Public Subscriptions:
- Candles ( Timeframe: 1 day )
- Orderbook ( Full depth @ Interval: 100ms )
- Ticker ( Interval: 100ms )
- All Trades ( Interval: 100ms )

Default Authenticated Subscriptions:
- My Account Orders
- My Account Trades

kline.Raw Interval configurable for a raw orderbook subscription when authenticated

Subscriptions are subject to enabled assets and pairs.

### Please click GoDocs chevron above to view current GoDoc information for this package
{{template "contributions"}}
Expand Down
3 changes: 3 additions & 0 deletions cmd/documentation/exchanges_templates/kucoin.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ Default Authenticated Subscriptions:

Subscriptions are subject to enabled assets and pairs.

Margin subscriptions for ticker, orderbook and All trades are merged into Spot subscriptions because duplicates are not allowed,
unless Spot subscription does not exist, i.e. Spot asset not enabled, or subscription configured only for Margin

Limitations:
- 100 symbols per subscription
- 300 symbols per connection
Expand Down
9 changes: 5 additions & 4 deletions currency/pairs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import (
"strings"
)

// Public Errors
var (
ErrPairDuplication = errors.New("currency pair duplication")
)

var (
errSymbolEmpty = errors.New("symbol is empty")
errNoDelimiter = errors.New("no delimiter was supplied")
errPairFormattingInconsistent = errors.New("pair formatting is inconsistent")

// ErrPairDuplication defines an error when there is multiple of the same
// currency pairs found.
ErrPairDuplication = errors.New("currency pair duplication")
)

// NewPairsFromStrings takes in currency pair strings and returns a currency
Expand Down
74 changes: 37 additions & 37 deletions engine/currency_state_manager.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# GoCryptoTrader package Currency state manager

<img src="/common/gctlogo.png?raw=true" width="350px" height="350px" hspace="70">


[![Build Status](https://github.com/thrasher-corp/gocryptotrader/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/thrasher-corp/gocryptotrader/actions/workflows/tests.yml)
[![Software License](https://img.shields.io/badge/License-MIT-orange.svg?style=flat-square)](https://github.com/thrasher-corp/gocryptotrader/blob/master/LICENSE)
[![GoDoc](https://godoc.org/github.com/thrasher-corp/gocryptotrader?status.svg)](https://godoc.org/github.com/thrasher-corp/gocryptotrader/engine/currency_state_manager)
[![Coverage Status](https://codecov.io/gh/thrasher-corp/gocryptotrader/graph/badge.svg?token=41784B23TS)](https://codecov.io/gh/thrasher-corp/gocryptotrader)
[![Go Report Card](https://goreportcard.com/badge/github.com/thrasher-corp/gocryptotrader)](https://goreportcard.com/report/github.com/thrasher-corp/gocryptotrader)


This currency_state_manager package is part of the GoCryptoTrader codebase.

## This is still in active development

You can track ideas, planned features and what's in progress on our [GoCryptoTrader Kanban board](https://github.com/orgs/thrasher-corp/projects/3).

Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader Slack](https://join.slack.com/t/gocryptotrader/shared_invite/enQtNTQ5NDAxMjA2Mjc5LTc5ZDE1ZTNiOGM3ZGMyMmY1NTAxYWZhODE0MWM5N2JlZDk1NDU0YTViYzk4NTk3OTRiMDQzNGQ1YTc4YmRlMTk)
# GoCryptoTrader package Currency state manager

<img src="/common/gctlogo.png?raw=true" width="350px" height="350px" hspace="70">


[![Build Status](https://github.com/thrasher-corp/gocryptotrader/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/thrasher-corp/gocryptotrader/actions/workflows/tests.yml)
[![Software License](https://img.shields.io/badge/License-MIT-orange.svg?style=flat-square)](https://github.com/thrasher-corp/gocryptotrader/blob/master/LICENSE)
[![GoDoc](https://godoc.org/github.com/thrasher-corp/gocryptotrader?status.svg)](https://godoc.org/github.com/thrasher-corp/gocryptotrader/engine/currency_state_manager)
[![Coverage Status](https://codecov.io/gh/thrasher-corp/gocryptotrader/graph/badge.svg?token=41784B23TS)](https://codecov.io/gh/thrasher-corp/gocryptotrader)
[![Go Report Card](https://goreportcard.com/badge/github.com/thrasher-corp/gocryptotrader)](https://goreportcard.com/report/github.com/thrasher-corp/gocryptotrader)


This currency_state_manager package is part of the GoCryptoTrader codebase.

## This is still in active development

You can track ideas, planned features and what's in progress on our [GoCryptoTrader Kanban board](https://github.com/orgs/thrasher-corp/projects/3).

Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader Slack](https://join.slack.com/t/gocryptotrader/shared_invite/enQtNTQ5NDAxMjA2Mjc5LTc5ZDE1ZTNiOGM3ZGMyMmY1NTAxYWZhODE0MWM5N2JlZDk1NDU0YTViYzk4NTk3OTRiMDQzNGQ1YTc4YmRlMTk)

## Current Features for Currency state manager
+ The state manager keeps currency states up to date, which include:
Expand All @@ -27,22 +27,22 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader
+ This allows for an internal state check to compliment internal and external
strategies.


## Contribution

Please feel free to submit any pull requests or suggest any desired features to be added.

When submitting a PR, please abide by our coding guidelines:

+ Code must adhere to the official Go [formatting](https://golang.org/doc/effective_go.html#formatting) guidelines (i.e. uses [gofmt](https://golang.org/cmd/gofmt/)).
+ Code must be documented adhering to the official Go [commentary](https://golang.org/doc/effective_go.html#commentary) guidelines.
+ Code must adhere to our [coding style](https://github.com/thrasher-corp/gocryptotrader/blob/master/doc/coding_style.md).
+ Pull requests need to be based on and opened against the `master` branch.

## Donations

<img src="https://github.com/thrasher-corp/gocryptotrader/blob/master/web/src/assets/donate.png?raw=true" hspace="70">

If this framework helped you in any way, or you would like to support the developers working on it, please donate Bitcoin to:


## Contribution

Please feel free to submit any pull requests or suggest any desired features to be added.

When submitting a PR, please abide by our coding guidelines:

+ Code must adhere to the official Go [formatting](https://golang.org/doc/effective_go.html#formatting) guidelines (i.e. uses [gofmt](https://golang.org/cmd/gofmt/)).
+ Code must be documented adhering to the official Go [commentary](https://golang.org/doc/effective_go.html#commentary) guidelines.
+ Code must adhere to our [coding style](https://github.com/thrasher-corp/gocryptotrader/blob/master/doc/coding_style.md).
+ Pull requests need to be based on and opened against the `master` branch.

## Donations

<img src="https://github.com/thrasher-corp/gocryptotrader/blob/master/web/src/assets/donate.png?raw=true" hspace="70">

If this framework helped you in any way, or you would like to support the developers working on it, please donate Bitcoin to:

***bc1qk0jareu4jytc0cfrhr5wgshsq8282awpavfahc***
46 changes: 13 additions & 33 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,17 +791,11 @@ func (bot *Engine) LoadExchange(name string) error {

localWG.Wait()
if !bot.Settings.EnableExchangeHTTPRateLimiter {
gctlog.Warnf(gctlog.ExchangeSys,
"Loaded exchange %s rate limiting has been turned off.\n",
exch.GetName(),
)
err = exch.DisableRateLimiter()
if err != nil {
gctlog.Errorf(gctlog.ExchangeSys,
"Loaded exchange %s rate limiting cannot be turned off: %s.\n",
exch.GetName(),
err,
)
gctlog.Errorf(gctlog.ExchangeSys, "%s error disabling rate limiter: %v", exch.GetName(), err)
} else {
gctlog.Warnf(gctlog.ExchangeSys, "%s rate limiting has been turned off", exch.GetName())
}
}

Expand All @@ -820,29 +814,18 @@ func (bot *Engine) LoadExchange(name string) error {
return err
}

base := exch.GetBase()
if base.API.AuthenticatedSupport ||
base.API.AuthenticatedWebsocketSupport {
assetTypes := base.GetAssetTypes(false)
var useAsset asset.Item
for a := range assetTypes {
err = base.CurrencyPairs.IsAssetEnabled(assetTypes[a])
if err != nil {
continue
}
useAsset = assetTypes[a]
break
}
err = exch.ValidateAPICredentials(context.TODO(), useAsset)
b := exch.GetBase()
if b.API.AuthenticatedSupport || b.API.AuthenticatedWebsocketSupport {
err = exch.ValidateAPICredentials(context.TODO(), asset.Spot)
if err != nil {
gctlog.Warnf(gctlog.ExchangeSys,
"%s: Cannot validate credentials, authenticated support has been disabled, Error: %s\n",
base.Name,
err)
base.API.AuthenticatedSupport = false
base.API.AuthenticatedWebsocketSupport = false
gctlog.Warnf(gctlog.ExchangeSys, "%s: Error validating credentials: %v", b.Name, err)
b.API.AuthenticatedSupport = false
b.API.AuthenticatedWebsocketSupport = false
exchCfg.API.AuthenticatedSupport = false
exchCfg.API.AuthenticatedWebsocketSupport = false
if b.Websocket != nil {
b.Websocket.SetCanUseAuthenticatedEndpoints(false)
}
}
}

Expand All @@ -854,10 +837,7 @@ func (bot *Engine) dryRunParamInteraction(param string) {
return
}

gctlog.Warnf(gctlog.Global,
"Command line argument '-%s' induces dry run mode."+
" Set -dryrun=false if you wish to override this.",
param)
gctlog.Warnf(gctlog.Global, "Command line argument '-%s' induces dry run mode. Set -dryrun=false if you wish to override this.", param)

if !bot.Settings.EnableDryRun {
bot.Settings.EnableDryRun = true
Expand Down
5 changes: 2 additions & 3 deletions engine/rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ var (
errGRPCShutdownSignalIsNil = errors.New("cannot shutdown, gRPC shutdown channel is nil")
errInvalidStrategy = errors.New("invalid strategy")
errSpecificPairNotEnabled = errors.New("specified pair is not enabled")
errPairNotEnabled = errors.New("pair is not enabled")
)

// RPCServer struct
Expand Down Expand Up @@ -4723,7 +4722,7 @@ func (s *RPCServer) GetFundingRates(ctx context.Context, r *gctrpc.GetFundingRat
}

if !pairs.Contains(cp, true) {
return nil, fmt.Errorf("%w %v", errPairNotEnabled, cp)
return nil, fmt.Errorf("%w %v", currency.ErrPairNotEnabled, cp)
}

funding, err := exch.GetHistoricalFundingRates(ctx, &fundingrate.HistoricalRatesRequest{
Expand Down Expand Up @@ -4821,7 +4820,7 @@ func (s *RPCServer) GetLatestFundingRate(ctx context.Context, r *gctrpc.GetLates
}

if !pairs.Contains(cp, true) {
return nil, fmt.Errorf("%w %v", errPairNotEnabled, cp)
return nil, fmt.Errorf("%w %v", currency.ErrPairNotEnabled, cp)
}

fundingRates, err := exch.GetLatestFundingRates(ctx, &fundingrate.LatestRateRequest{
Expand Down
24 changes: 13 additions & 11 deletions exchanges/bitfinex/bitfinex_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,17 +456,20 @@ func (b *Bitfinex) handleWSEvent(respRaw []byte) error {
if err != nil {
return fmt.Errorf("%w 'chanId': %w from message: %s", errParsingWSField, err, respRaw)
}
if !b.Websocket.Match.IncomingWithData("unsubscribe:"+chanID, respRaw) {
return fmt.Errorf("%w: unsubscribe:%v", stream.ErrNoMessageListener, chanID)
err = b.Websocket.Match.RequireMatchWithData("unsubscribe:"+chanID, respRaw)
if err != nil {
return fmt.Errorf("%w: unsubscribe:%v", err, chanID)
}
case wsEventError:
if subID, err := jsonparser.GetUnsafeString(respRaw, "subId"); err == nil {
if !b.Websocket.Match.IncomingWithData("subscribe:"+subID, respRaw) {
return fmt.Errorf("%w: subscribe:%v", stream.ErrNoMessageListener, subID)
err = b.Websocket.Match.RequireMatchWithData("subscribe:"+subID, respRaw)
if err != nil {
return fmt.Errorf("%w: subscribe:%v", err, subID)
}
} else if chanID, err := jsonparser.GetUnsafeString(respRaw, "chanId"); err == nil {
if !b.Websocket.Match.IncomingWithData("unsubscribe:"+chanID, respRaw) {
return fmt.Errorf("%w: unsubscribe:%v", stream.ErrNoMessageListener, chanID)
err = b.Websocket.Match.RequireMatchWithData("unsubscribe:"+chanID, respRaw)
if err != nil {
return fmt.Errorf("%w: unsubscribe:%v", err, chanID)
}
} else {
return fmt.Errorf("unknown channel error; Message: %s", respRaw)
Expand Down Expand Up @@ -531,17 +534,16 @@ func (b *Bitfinex) handleWSSubscribed(respRaw []byte) error {
c.Key = int(chanID)

// subscribeToChan removes the old subID keyed Subscription
if err := b.Websocket.AddSuccessfulSubscriptions(b.Websocket.Conn, c); err != nil {
err = b.Websocket.AddSuccessfulSubscriptions(b.Websocket.Conn, c)
if err != nil {
return fmt.Errorf("%w: %w subID: %s", stream.ErrSubscriptionFailure, err, subID)
}

if b.Verbose {
log.Debugf(log.ExchangeSys, "%s Subscribed to Channel: %s Pair: %s ChannelID: %d\n", b.Name, c.Channel, c.Pairs, chanID)
}
if !b.Websocket.Match.IncomingWithData("subscribe:"+subID, respRaw) {
return fmt.Errorf("%w: subscribe:%v", stream.ErrNoMessageListener, subID)
}
return nil

return b.Websocket.Match.RequireMatchWithData("subscribe:"+subID, respRaw)
}

func (b *Bitfinex) handleWSChannelUpdate(s *subscription.Subscription, eventType string, d []interface{}) error {
Expand Down
5 changes: 3 additions & 2 deletions exchanges/bitmex/bitmex_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,9 @@ func (b *Bitmex) wsHandleData(respRaw []byte) error {
if e2 != nil {
return fmt.Errorf("%w parsing stream", e2)
}
if !b.Websocket.Match.IncomingWithData(op+":"+streamID, msg) {
return fmt.Errorf("%w: %s:%s", stream.ErrNoMessageListener, op, streamID)
err = b.Websocket.Match.RequireMatchWithData(op+":"+streamID, msg)
if err != nil {
return fmt.Errorf("%w: %s:%s", err, op, streamID)
}
return nil
}
Expand Down
5 changes: 1 addition & 4 deletions exchanges/bitstamp/bitstamp_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,7 @@ func (b *Bitstamp) handleWSSubscription(event string, respRaw []byte) error {
return fmt.Errorf("%w `channel`: %w", errParsingWSField, err)
}
event = strings.TrimSuffix(event, "scription_succeeded")
if !b.Websocket.Match.IncomingWithData(event+":"+channel, respRaw) {
return fmt.Errorf("%w: %s", stream.ErrNoMessageListener, event+":"+channel)
}
return nil
return b.Websocket.Match.RequireMatchWithData(event+":"+channel, respRaw)
}

func (b *Bitstamp) handleWSTrade(msg []byte) error {
Expand Down
Loading

0 comments on commit 3a82828

Please sign in to comment.