Skip to content

Commit

Permalink
Merge master maybe?
Browse files Browse the repository at this point in the history
  • Loading branch information
cranktakular committed May 30, 2024
2 parents 01ccd01 + aeb4a87 commit 228c3ba
Show file tree
Hide file tree
Showing 146 changed files with 204,487 additions and 38,584 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ jobs:
with:
go-version: '1.22.x'
- name: golangci-lint
uses: golangci/golangci-lint-action@v5
uses: golangci/golangci-lint-action@v6
with:
version: v1.56.1
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.31.0
- uses: bufbuild/buf-setup-action@v1.32.1

- name: buf generate
working-directory: ./gctrpc
Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:

- name: Setup Postgres
if: matrix.psql == true
uses: ikalnytskyi/action-setup-postgres@v5
uses: ikalnytskyi/action-setup-postgres@v6
with:
database: gct_dev_ci
id: postgres
Expand Down Expand Up @@ -74,9 +74,14 @@ jobs:
- name: Additional steps for 386 architecture
if: matrix.goarch == '386'
run: |
echo "CGO_ENABLED=1" >> $GITHUB_ENV
sudo apt-get update
sudo apt-get install gcc-multilib g++-multilib
sudo apt-get install -y gcc-multilib
shell: bash

- name: Set CGO_ENABLED for 386 and macos-latest
if: matrix.goarch == '386' || matrix.os == 'macos-latest'
run: |
echo "CGO_ENABLED=1" >> $GITHUB_ENV
shell: bash

- name: Test
Expand Down
14 changes: 7 additions & 7 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ dependabot-preview[bot] | https://github.com/apps/dependabot-preview
gbjk | https://github.com/gbjk
xtda | https://github.com/xtda
lrascao | https://github.com/lrascao
ydm | https://github.com/ydm
vazha | https://github.com/vazha
Rots | https://github.com/Rots
Beadko | https://github.com/Beadko
Rots | https://github.com/Rots
vazha | https://github.com/vazha
ydm | https://github.com/ydm
ermalguni | https://github.com/ermalguni
MadCozBadd | https://github.com/MadCozBadd
vadimzhukck | https://github.com/vadimzhukck
Expand All @@ -26,19 +26,19 @@ khcchiu | https://github.com/khcchiu
yangrq1018 | https://github.com/yangrq1018
woshidama323 | https://github.com/woshidama323
crackcomm | https://github.com/crackcomm
mshogin | https://github.com/mshogin
herenow | https://github.com/herenow
tk42 | https://github.com/tk42
soxipy | https://github.com/soxipy
andreygrehov | https://github.com/andreygrehov
azhang | https://github.com/azhang
bretep | https://github.com/bretep
Christian-Achilli | https://github.com/Christian-Achilli
cornelk | https://github.com/cornelk
gam-phon | https://github.com/gam-phon
herenow | https://github.com/herenow
if1live | https://github.com/if1live
lozdog245 | https://github.com/lozdog245
MarkDzulko | https://github.com/MarkDzulko
mshogin | https://github.com/mshogin
soxipy | https://github.com/soxipy
tk42 | https://github.com/tk42
blombard | https://github.com/blombard
cavapoo2 | https://github.com/cavapoo2
CodeLingoTeam | https://github.com/CodeLingoTeam
Expand Down
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader
| Bybit | Yes | Yes | NA |
| CoinbasePro | Yes | Yes | No|
| COINUT | Yes | Yes | NA |
| Deribit | Yes | Yes | No |
| Exmo | Yes | NA | NA |
| GateIO | Yes | Yes | NA |
| Gemini | Yes | Yes | No |
Expand Down Expand Up @@ -141,18 +142,18 @@ Binaries will be published once the codebase reaches a stable condition.

|User|Contribution Amount|
|--|--|
| [thrasher-](https://github.com/thrasher-) | 689 |
| [shazbert](https://github.com/shazbert) | 316 |
| [dependabot[bot]](https://github.com/apps/dependabot) | 254 |
| [gloriousCode](https://github.com/gloriousCode) | 229 |
| [thrasher-](https://github.com/thrasher-) | 690 |
| [shazbert](https://github.com/shazbert) | 326 |
| [dependabot[bot]](https://github.com/apps/dependabot) | 276 |
| [gloriousCode](https://github.com/gloriousCode) | 233 |
| [dependabot-preview[bot]](https://github.com/apps/dependabot-preview) | 88 |
| [gbjk](https://github.com/gbjk) | 61 |
| [gbjk](https://github.com/gbjk) | 72 |
| [xtda](https://github.com/xtda) | 47 |
| [lrascao](https://github.com/lrascao) | 27 |
| [ydm](https://github.com/ydm) | 15 |
| [vazha](https://github.com/vazha) | 15 |
| [Beadko](https://github.com/Beadko) | 17 |
| [Rots](https://github.com/Rots) | 15 |
| [Beadko](https://github.com/Beadko) | 15 |
| [vazha](https://github.com/vazha) | 15 |
| [ydm](https://github.com/ydm) | 15 |
| [ermalguni](https://github.com/ermalguni) | 14 |
| [MadCozBadd](https://github.com/MadCozBadd) | 13 |
| [vadimzhukck](https://github.com/vadimzhukck) | 10 |
Expand All @@ -171,6 +172,10 @@ Binaries will be published once the codebase reaches a stable condition.
| [herenow](https://github.com/herenow) | 2 |
| [tk42](https://github.com/tk42) | 2 |
| [soxipy](https://github.com/soxipy) | 2 |
| [andreygrehov](https://github.com/andreygrehov) | 2 |
| [azhang](https://github.com/azhang) | 2 |
| [bretep](https://github.com/bretep) | 2 |
| [Christian-Achilli](https://github.com/Christian-Achilli) | 2 |
| [cornelk](https://github.com/cornelk) | 2 |
| [gam-phon](https://github.com/gam-phon) | 2 |
| [herenow](https://github.com/herenow) | 2 |
Expand Down
2 changes: 1 addition & 1 deletion backtester/engine/grpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (s *GRPCServer) StartRPCRESTProxy() error {
targetDir := utils.GetTLSDir(s.config.GRPC.TLSDir)
creds, err := credentials.NewClientTLSFromFile(filepath.Join(targetDir, "cert.pem"), "")
if err != nil {
return fmt.Errorf("unabled to start gRPC proxy. Err: %w", err)
return fmt.Errorf("unable to start gRPC proxy. Err: %w", err)
}

mux := runtime.NewServeMux()
Expand Down
12 changes: 6 additions & 6 deletions backtester/engine/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ func (bt *BackTest) loadData(cfg *config.Config, exch gctexchange.IBotExchange,
cfg.DataSettings.Interval)
}
err = bt.exchangeManager.Add(exch)
if err != nil {
if err != nil && !errors.Is(err, engine.ErrExchangeAlreadyLoaded) {
return nil, err
}
err = bt.LiveDataHandler.AppendDataSource(&liveDataSourceSetup{
Expand Down Expand Up @@ -955,7 +955,8 @@ func setExchangeCredentials(cfg *config.Config, base *gctexchange.Base) error {
cfg.DataSettings.LiveData.ExchangeCredentials[i].Keys.IsEmpty() {
return fmt.Errorf("%v %w, please review your live, real order config", base.GetName(), gctexchange.ErrCredentialsAreEmpty)
}

base.API.AuthenticatedSupport = true
base.API.AuthenticatedWebsocketSupport = true
base.SetCredentials(
cfg.DataSettings.LiveData.ExchangeCredentials[i].Keys.Key,
cfg.DataSettings.LiveData.ExchangeCredentials[i].Keys.Secret,
Expand All @@ -964,10 +965,9 @@ func setExchangeCredentials(cfg *config.Config, base *gctexchange.Base) error {
cfg.DataSettings.LiveData.ExchangeCredentials[i].Keys.PEMKey,
cfg.DataSettings.LiveData.ExchangeCredentials[i].Keys.OneTimePassword,
)
validated := base.AreCredentialsValid(context.TODO())
base.API.AuthenticatedSupport = validated
if !validated {
return fmt.Errorf("%v %w", base.GetName(), errInvalidCredentials)
_, err := base.GetCredentials(context.TODO())
if err != nil {
return err
}
}

Expand Down
26 changes: 10 additions & 16 deletions backtester/eventhandlers/exchange/slippage/slippage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"testing"

"github.com/shopspring/decimal"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
"github.com/thrasher-corp/gocryptotrader/exchanges/bitstamp"
Expand All @@ -14,31 +16,23 @@ import (
func TestRandomSlippage(t *testing.T) {
t.Parallel()
resp := EstimateSlippagePercentage(decimal.NewFromInt(80), decimal.NewFromInt(100))
if resp.LessThan(decimal.NewFromFloat(0.8)) || resp.GreaterThan(decimal.NewFromInt(1)) {
t.Error("expected result > 0.8 and < 100")
}
assert.True(t, resp.GreaterThan(decimal.NewFromFloat(0.8)), "result should be more than 0.8")
assert.True(t, resp.LessThan(decimal.NewFromInt(1)), "result should be less than 1")
}

func TestCalculateSlippageByOrderbook(t *testing.T) {
t.Parallel()
b := bitstamp.Bitstamp{}
b.SetDefaults()
err := b.CurrencyPairs.SetAssetEnabled(asset.Spot, true)
if err != nil {
t.Fatal(err)
}

cp := currency.NewPair(currency.BTC, currency.USD)
ob, err := b.FetchOrderbook(context.Background(), cp, asset.Spot)
if err != nil {
t.Error(err)
}
require.NoError(t, err, "FetchOrderbook must not error")

amountOfFunds := decimal.NewFromInt(1000)
feeRate := decimal.NewFromFloat(0.03)
price, amount, err := CalculateSlippageByOrderbook(ob, gctorder.Buy, amountOfFunds, feeRate)
if err != nil {
t.Fatal(err)
}
if price.Mul(amount).Add(price.Mul(amount).Mul(feeRate)).GreaterThan(amountOfFunds) {
t.Error("order size must be less than funds")
}
require.NoError(t, err, "CalculateSlippageByOrderbook must not error")
orderSize := price.Mul(amount).Add(price.Mul(amount).Mul(feeRate))
assert.True(t, orderSize.LessThan(amountOfFunds), "order size must be less than funds")
}
20 changes: 20 additions & 0 deletions cmd/documentation/documentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,26 @@ func main() {

// Github API missing contributors
contributors = append(contributors, []Contributor{
{
Login: "andreygrehov",
URL: "https://github.com/andreygrehov",
Contributions: 2,
},
{
Login: "azhang",
URL: "https://github.com/azhang",
Contributions: 2,
},
{
Login: "bretep",
URL: "https://github.com/bretep",
Contributions: 2,
},
{
Login: "Christian-Achilli",
URL: "https://github.com/Christian-Achilli",
Contributions: 2,
},
{
Login: "cornelk",
URL: "https://github.com/cornelk",
Expand Down
106 changes: 106 additions & 0 deletions cmd/documentation/exchanges_templates/deribit.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{{define "exchanges deribit" -}}
{{template "header" .}}
## Deribit Exchange

### Current Features

+ REST Support
+ Websocket Support

### How to enable

+ [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example)

+ Individual package example below:

```go
// Exchanges will be abstracted out in further updates and examples will be
// supplied then
```

### How to do REST public/private calls

+ If enabled via "configuration".json file the exchange will be added to the
IBotExchange array in the ```go var bot Bot``` and you will only be able to use
the wrapper interface functions for accessing exchange data. View routines.go
for an example of integration usage with GoCryptoTrader. Rudimentary example
below:

main.go
```go
var d exchange.IBotExchange

for i := range bot.Exchanges {
if bot.Exchanges[i].GetName() == "Deribit" {
d = bot.Exchanges[i]
}
}

// Public calls - wrapper functions

// Fetches current ticker information
tick, err := d.FetchTicker()
if err != nil {
// Handle error
}

// Fetches current orderbook information
ob, err := d.FetchOrderbook()
if err != nil {
// Handle error
}

// Private calls - wrapper functions - make sure your APIKEY and APISECRET are
// set and AuthenticatedAPISupport is set to true

// Fetches current account information
accountInfo, err := d.GetAccountInfo()
if err != nil {
// Handle error
}
```

+ If enabled via individually importing package, rudimentary example below:

```go
// Public calls

// Fetches current ticker information
tick, err := d.GetTicker()
if err != nil {
// Handle error
}

// Fetches current orderbook information
ob, err := d.GetOrderBook()
if err != nil {
// Handle error
}

// Private calls - make sure your APIKEY and APISECRET are set and
// AuthenticatedAPISupport is set to true

// GetUserInfo returns account info
accountInfo, err := d.GetUserInfo(...)
if err != nil {
// Handle error
}

// Submits an order and the exchange and returns its tradeID
tradeID, err := d.Trade(...)
if err != nil {
// Handle error
}
```

### How to do Websocket public/private calls

```go
// Exchanges will be abstracted out in further updates and examples will be
// supplied then
```

### Please click GoDocs chevron above to view current GoDoc information for this package
{{template "contributions"}}
{{template "donations" .}}
{{end}}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ _b in this context is an `IBotExchange` implemented struct_
| Bybit | Yes | Yes | Yes |
| CoinbasePro | Yes | Yes | No|
| COINUT | Yes | Yes | No |
| Deribit | Yes | Yes | Yes |
| Exmo | Yes | NA | No |
| GateIO | Yes | Yes | No |
| Gemini | Yes | Yes | Yes |
Expand Down
1 change: 1 addition & 0 deletions cmd/documentation/root_templates/root_readme.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader
| Bybit | Yes | Yes | NA |
| CoinbasePro | Yes | Yes | No|
| COINUT | Yes | Yes | NA |
| Deribit | Yes | Yes | No |
| Exmo | Yes | NA | NA |
| GateIO | Yes | Yes | NA |
| Gemini | Yes | Yes | No |
Expand Down
8 changes: 4 additions & 4 deletions cmd/exchange_template/wrapper_file.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -281,17 +281,17 @@ func ({{.Variable}} *{{.CapitalName}}) UpdateOrderbook(ctx context.Context, pair
return book, err
}

book.Bids = make([]orderbook.Item, len(orderbookNew.Bids))
book.Bids = make([]orderbook.Tranche, len(orderbookNew.Bids))
for x := range orderbookNew.Bids {
book.Bids[x] = orderbook.Item{
book.Bids[x] = orderbook.Tranche{
Amount: orderbookNew.Bids[x].Quantity,
Price: orderbookNew.Bids[x].Price,
}
}

book.Asks = make([]orderbook.Item, len(orderbookNew.Asks))
book.Asks = make([]orderbook.Tranche, len(orderbookNew.Asks))
for x := range orderbookNew.Asks {
book.Asks[x] = orderbook.Item{
book.Asks[x] = orderbook.Tranche{
Amount: orderBookNew.Asks[x].Quantity,
Price: orderBookNew.Asks[x].Price,
}
Expand Down
Loading

0 comments on commit 228c3ba

Please sign in to comment.