Skip to content

Commit

Permalink
Futures order position tracking & FTX scaled collateral calculation (t…
Browse files Browse the repository at this point in the history
…hrasher-corp#868)

* implements futures functions and GRPC functions on new branch

* lint and test fixes

* Fix uneven split pnl. Adds collateral weight test. docs. New clear func

* Test protection if someone has zero collateral

* Uses string instead of double for accuracy

* Fixes old code panic

* context, match, docs

* Addresses Shazniterinos, var names, expanded tests

* Returns subaccount name, provides USD values when offlinecalc

* Fixes oopsie

* Fixes cool bug which allowed made up subaccount results

* Subaccount override on FTX, subaccount results for collateral

* Strenghten collateral account info checks. Improve FTX test

* English is my first language

* Fixes oopsies

* Fixes for unrealised PNL & collateral rendering

* Fixes lint and tests

* Shaznit fixes

* Secret Shaznit

* Updates account information across wrappers to include more fields

* Updates online collateral calculations. Updates RPC data

* Accurately calculates collateral offline and online minus testing

* Tests and lint chocolate

* Simplifies accountinfo results

* Fixes shaznits

* Adds new func

* Increases collateral accuracy again again again x 200

* Increases accuracy of collateral rendering

* Fixes minor merge/test issues

* Linterino

* Fixes ws test. Improves collateral calculations and rendering

* Make it prettier

* Removes the lock I put on 👀

* Adds `additional_collateral_used` field, renders orig currency

* Fixes unrelated test

* Fix test

* Correctly calculate spot margin borrow collateral

* Address fun lint surprise

See golangci/golangci-lint#741 (comment)

* Strange lint fixing x2

* Continued lint journey

* Nolint the nolint to not lint the lint

* Adds two new fields to response

* More linting issues arising

* fIX3s_c4s|NG

* Fixes command flags' incorrect numbering

* FairMarket = Won
  • Loading branch information
gloriousCode authored Feb 28, 2022
1 parent 5c8113b commit 86d3724
Show file tree
Hide file tree
Showing 89 changed files with 69,872 additions and 15,196 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
run:
timeout: 3m
timeout: 6m
issues-exit-code: 1
tests: true
skip-dirs:
Expand Down
4 changes: 2 additions & 2 deletions backtester/eventhandlers/exchange/exchange_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ func TestPlaceOrder(t *testing.T) {
}
f := &fill.Fill{}
_, err = e.placeOrder(context.Background(), decimal.NewFromInt(1), decimal.NewFromInt(1), false, true, f, bot.OrderManager)
if err != nil && err.Error() != "order exchange name must be specified" {
t.Error(err)
if !errors.Is(err, engine.ErrExchangeNameIsEmpty) {
t.Errorf("received: %v, expected: %v", err, engine.ErrExchangeNameIsEmpty)
}

f.Exchange = testExchange
Expand Down
4 changes: 2 additions & 2 deletions backtester/funding/funding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -757,10 +757,10 @@ func TestGenerateReport(t *testing.T) {
t.Parallel()
f := FundManager{}
report := f.GenerateReport()
if report == nil {
if report == nil { //nolint:staticcheck,nolintlint // SA5011 Ignore the nil warnings
t.Fatal("shouldn't be nil")
}
if len(report.Items) > 0 {
if len(report.Items) > 0 { //nolint:staticcheck,nolintlint // SA5011 Ignore the nil warnings
t.Error("expected 0")
}
item := &Item{
Expand Down
4 changes: 3 additions & 1 deletion cmd/apichecker/apicheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,9 @@ loop:
}
}
}
resp = resp[:1]
if len(resp) > 1 {
resp = resp[:1]
}
return resp, nil
}

Expand Down
1 change: 1 addition & 0 deletions cmd/documentation/engine_templates/order_manager.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
+ The order manager subsystem stores and monitors all orders from enabled exchanges with API keys and `authenticatedSupport` enabled
+ It can be enabled or disabled via runtime command `-ordermanager=false` and defaults to true
+ All orders placed via GoCryptoTrader will be added to the order manager store
+ Any futures based order will be tracked via the [futures positions controller](/exchanges/order/README.md) which can be used to track PNL. Use GRPC command [getfuturesposition](https://api.gocryptotrader.app/#gocryptotrader_getfuturesposition) to view position data for an exchange, asset, pair

### Please click GoDocs chevron above to view current GoDoc information for this package
{{template "contributions"}}
Expand Down
4 changes: 3 additions & 1 deletion cmd/documentation/exchanges_templates/orders.tmpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{define "exchanges orders" -}}
{{define "exchanges order" -}}
{{template "header" .}}
## Current Features for {{.Name}}

Expand All @@ -7,6 +7,8 @@
- Deletion of order
- Order tracking

+ For futures orders, this package also contains a futures position controller. It is responsible for tracking all futures orders that GoCryptoTrader processes. It keeps a running history of realised and unreaslied PNL to allow a trader to track their profits. Positions are closed once the exposure reaches zero, then upon a new futures order being processed, a new position is created. To view futures positions, see the GRPC command `getfuturesposition`

### Please click GoDocs chevron above to view current GoDoc information for this package
{{template "contributions"}}
{{template "donations" .}}
Expand Down
Loading

0 comments on commit 86d3724

Please sign in to comment.