Commit Graph

1423 Commits

Author SHA1 Message Date
Ryan O'Hara-Reid
5dfbbf84de engine/exchanges: Add exchange currency state subsystem (#774)
* state: Add management system (init)

* linter: fix

* engine: gofmt

* gct: after merge fixup

* documentation: add

* rpc: implement services for testing

* gctcli: gofmt state_management.go

* documentation: reinstate lost information

* state: Add pair check to determine trading operation

* exchanges: add interface for specific state scoped subsystem functionality

* engine/order_man: reduce code footprint using new method

* RPC: implement pair trading request and change exported name to something specific to state

* engine: add tests

* engine: Add to withdraw manager

* documentation: reinstate soxipy in contrib. list

* engine: const fake name

* Glorious: NITERINOS

* merge: fix issues

* engine: csm incorporate service name into log output

* engine: fix linter issues

* gct: fix tests

* currencystate: remove management type

* rpc: fix tests

* backtester: fix tests

* Update engine/currency_state_manager.go

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* Update engine/currency_state_manager.go

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* Update exchanges/currencystate/currency_state.go

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* Update exchanges/alert/alert.go

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* Update exchanges/alert/alert.go

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* glorious: nits

* config: integrate with config and remove flag delay adjustment

* gctcli: fix issues after name changes

* engine: gofmt manager file

* Update engine/rpcserver.go

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* engine: Add enable/disable manager functions, add default popoulation for potential assets

* linter: fix

* engine/test: bump subsystem count

* Update engine/currency_state_manager.go

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* Update exchanges/bithumb/bithumb.go

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* glorious: nits addressed

* alert: fix commenting for its generalized purpose

* glorious: nits

* engine: use standard string in log output

* bitfinex: apply patch, thanks @thrasher-

* bitfinex: fix spelling

* engine/currencystate: Add logs/fix logs

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>
2021-09-27 13:33:49 +10:00
Luis Rascão
1d7c656665 huobi: don't overwrite account balances when request spot asset (#785) 2021-09-21 14:01:22 +10:00
dependabot[bot]
d7345e1152 build(deps): bump github.com/spf13/viper from 1.8.1 to 1.9.0 (#786)
Bumps [github.com/spf13/viper](https://github.com/spf13/viper) from 1.8.1 to 1.9.0.
- [Release notes](https://github.com/spf13/viper/releases)
- [Commits](https://github.com/spf13/viper/compare/v1.8.1...v1.9.0)

---
updated-dependencies:
- dependency-name: github.com/spf13/viper
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-09-21 11:13:50 +10:00
TaltaM
fd600972ba engine/order manager: Initial REST managed order updating (resolves #772) (#775)
* Initial REST managed order updating

* Apply gloriousCode's changes.go patch

* Update internal order ID handling

* Check error

* Replace string with string pointer

* Avoid nil pointers in upsert

* Update test for UpdateOrderFromDetail()

* Add tests for orders.go

* Remove unnecessary newline

* Address comments

* Add missing nil check

* Add tests for new functions in order_manager.go

* Remove empty line

* Change log level for updates from Info to Debug (keep added orders at Info)

* Initialize orders before running the timer

* [TEMP] Add verbosity for debugging

* Nil checking on exchangeManager in GetExchanges()

- exchangeManager.GetExchanges() and iExchangeManager.GetExchanges() return an error on nil
- bot.GetExchanges() wraps exchangeManager.GetExchanges() and returns an empty slice

* Revert b5afe1a46b

* Do not start the order manager runner thread

Instead, mark the order manager as running

* Remove redundant error.Is() and remove print wrapper on msg

* Add atomic blocker and waitgroup on processOrders()

* Disable unnecessary orderManager runner thread for rpcserver_test

* Remove redundant err from orderStore.getActiveOrders()

* [FIX] Populate requiresProcessing using UpsertResponse data instead of REST return data

.. because the data returned by the REST calls do not include the internal user ID's

* [TEST] Verify that processOrders() actually processes queried order data

* Remove leftover warning and add nil check on wg.Done()

* Apply suggestions from code review

Log category changes - as suggested

Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>

* Return when no exchanges available

Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
2021-09-15 09:28:31 +10:00
Luis Rascão
068b375867 ftx: honour subaccount setting when fetching balances (#780)
FTX won't allow us to fetch balances for all accounts when
using a subaccount API key.
2021-09-14 11:10:31 +10:00
Ryan O'Hara-Reid
7ab861fe4d kraken: fix GetTrades test (#782) 2021-09-13 09:29:14 +10:00
Ryan O'Hara-Reid
d636049fb2 exchanges: Initial context propagation (#744)
* gct: phase one context awareness pass

* exchanges: context propagation pass

* common/requester: force context requirement

* gctcli/exchanges: linter fix

* rpcserver: fix test using dummy rpc server

* backtester: fix comments

* grpc: add correct cancel and timeout for commands

* rpcserver_test: add comment on dummy server

* common: deprecated SendHTTPGetRequest

* linter: fix

* linter: turn on no context check

* apichecker: fix context linter issue

* binance: use param context

* common: remove checks as this gets executed before main

* common: change mutex to RW as clients can be used by multiple go routines.

* common: remove init and JIT default client. Unexport global variables and add protection.

* common: Add comments

* bithumb: after dinner mints fix
2021-09-11 13:52:07 +10:00
dependabot[bot]
72516f7268 build(deps): bump github.com/grpc-ecosystem/grpc-gateway/v2 (#778)
Bumps [github.com/grpc-ecosystem/grpc-gateway/v2](https://github.com/grpc-ecosystem/grpc-gateway) from 2.5.0 to 2.6.0.
- [Release notes](https://github.com/grpc-ecosystem/grpc-gateway/releases)
- [Changelog](https://github.com/grpc-ecosystem/grpc-gateway/blob/master/.goreleaser.yml)
- [Commits](https://github.com/grpc-ecosystem/grpc-gateway/compare/v2.5.0...v2.6.0)

---
updated-dependencies:
- dependency-name: github.com/grpc-ecosystem/grpc-gateway/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-09-09 09:36:22 +10:00
Yordan Miladinov
9e745d20a3 Account: Add account.Balance.Available() method (#777)
* add account.Balance.Available() method that returns the amount of an asset not locked/held

* account: comment Balance.Available()

* account: test Balance.Available()
2021-09-09 09:35:10 +10:00
dependabot[bot]
4e5d094975 build(deps): bump github.com/lib/pq from 1.10.2 to 1.10.3 (#776)
Bumps [github.com/lib/pq](https://github.com/lib/pq) from 1.10.2 to 1.10.3.
- [Release notes](https://github.com/lib/pq/releases)
- [Commits](https://github.com/lib/pq/compare/v1.10.2...v1.10.3)

---
updated-dependencies:
- dependency-name: github.com/lib/pq
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-09-06 09:49:34 +10:00
Ryan O'Hara-Reid
66fbd43cf0 websocket: fix deadlock when enabling/disabling via gctrpc (#754)
* websocket: select case error if no receiver, add in functionality to reset to initial sync for books on a new websocket connection

* websocket: fix tests

* websocket: log error instead of losing it

* websocket: fix whoopsie

* exchanges: fix test

* websocket: force requirement of specific functionality

* exchanges: fix tests

* exchanges/websocket: move waitgroup add before scheduling across exchanges

* gateio: add feature subscribe

* bithumb/bittrex: include connection state reset, fix reconnection bug for Bithumb

* huobi: Add listen to shutdown to routine so it actually returns and stops being a naughty boy.

* huobi: add missing waitgroup add.

* exchanges: bleed comms channels

* binance: fix reconnection bug with buffer

* bithumb: fix reconnection bug with ws orderbook when websocket is diabled/enabled

* bithumb/bittrex: add bleeders for ws orderbook jobs

* linter: fix

* kraken: reduce code block from double assertion

* This bug ruined my day.

* glorious: error checking

* zb: add correct path for websocket connection

* exchange: Add verbosity when config conflicts and overwrites default values

* zb: add https to path

* exchanges: glorious nits

* stream: Add checkAndSetMonitoring to reduce potential routine bundling, increase timeout and check state in tests

* stream: remove check that is not needed.

* glorious: nits addr.

* lint: test
2021-09-03 17:21:23 +10:00
Ryan O'Hara-Reid
a54c5107f4 engine: GetSubsystemsStatus fix (#773)
* engine: GetSubsystemsStatus fix

* engine: force map literal to stop doubling up on keys, expanded test coverage

* engine: Deploy default for migration requirement.

* glorious: nits addr

* glorious: suggestion

* tests: fix
2021-09-03 11:59:52 +10:00
Scott
a1a667bab9 FTX: allow authenticated tests to run 2021-08-31 10:44:48 +10:00
Ryan O'Hara-Reid
4d1994afb6 bithumb: Add missing functionality (#770)
* bithumb: Add missing functionality

* glorious: nits
2021-08-31 09:57:04 +10:00
phieudu241
1e79384b25 Binance: Fix UKlineData func (#768) 2021-08-30 14:29:55 +10:00
Ryan O'Hara-Reid
8020e1ec6a linter: Enable error checking linter (#766)
* golangci: Enable err checking linter to expose unchecked errors.

* gct: handle errors across the board

* gct: handle errors NOTE: Found bug in FTX (WIP)

* linter: fix issues

* ftx/exchanges: fix bug where error was being returned when setting pair management variables to an already enabled state

* bitmex: fix bug where a dangly supported asset in config danglied up the place.

* linter: fix more linter issues

* linter: fix my terrible spelling.

* currency: fix test

* exchanges: fix tests

* logger: fix test

* exchanges: fix tests

* glorious: nits

* vm: revert rm variable and instigate test
2021-08-30 14:06:40 +10:00
Luis Rascão
c9ab0b1164 exchanges: Add UpdateTickers method and reserve UpdateTicker for single ticker symbol update requests (if supported) (#764)
* exchanges: add an UpdateTickers method to the main exchange interface

This method will fetch all currency pair tickers of a given asset type
and update them internally, does nothing for now.

* exchanges: refactor UpdateTicker on all exchanges

Keep the exact previous behaviour but implement the UpdateTickers
method and refactor UpdateTicker by using it where applicable.

* sync_manager: update all tickers when batching is enabled

* binance: UpdateTicker to fetch single ticker symbol

* ftx: UpdateTicker to fetch single ticker symbol
2021-08-27 12:31:34 +10:00
Ryan O'Hara-Reid
4851e94eba Engine/ExchangeManager: Return error for method GetExchangeByName (#760)
* engine: Add error returns

* engine: after merge fixes

* engine: remove interface

* linter: fix shadow declarations

* engine: fix tests

* niterinos: fixed

* GLORIOUS NITS!
2021-08-26 13:09:14 +10:00
Adrian Gallagher
056a809d93 Bitstamp: Fix currency pair handling (#762)
* Fix Bitstamp pair handling

* Fix spelling

* Populate namerinos

* Address nitterinos

* Revert trade currency code, introduces races between engine / this and rely on OB test instead

* One liner
2021-08-26 11:40:14 +10:00
Luis Rascão
9bb4348613 gctcli: remove all exchange name client-side validation (#758)
* gctcli: remove all exchange name client-side validation

Since now exchange names can be user-assigned we can no longer have
client-side validation, all exchange name validation must now occur
on the server (it was already doing that).

* engine: add server side exchange name check on some RPCs
2021-08-24 09:45:26 +10:00
Yordan Miladinov
a15cbf6651 docs: Establish a standard for trade/order-update websocket events (#755)
* docs: initially commit WS_TRADE_UPDATES.md

* docs/WS_TRADE_UPDATES: shorter text

* docs: rename WS_TRADE_UPDATES to WS_ORDER_EVENTS as that is more descriptive of what it documents

* docs/ADD_NEW_EXCHANGE: reference the newly added WS_ORDER_EVENTS file

* WS_ORDER_EVENTS: common terminology

* WS_ORDER_EVENTS: turn the code segment into a markdown table

* WS_ORDER_EVENTS: AverageExecutedPrice is now not mandatory

* exchanges/README: link to WS_ORDER_EVENTS
2021-08-23 09:48:16 +10:00
Yordan Miladinov
3467914ab7 Binance/FTX: spot websocket fixes (#753)
* exchange/binance/websocket:

1. resolve order type by reading the dedicated executionReport field (X)

2. populate average price (computed as advised in docs: Z/z)

3. fee taken is now assigned to order.Detail.Fee (not to order.Detail.Cost)

4. proper order.Detail.Cost and order.Detail.CostAsset

* order.Detail: add a new field: FeeAsset

* exchange/binance/websocket: wsOrderUpdate: assign FeeAsset

* exchange/binance/websocket: wsOrderUpdate: use TransactionTime instead of EventTime (more precise) and populate order.Detail.TargetAmount

* exchange/binance/websocket: wsOrderUpdate: use full name for variables (isn't obvious otherwise), do not mix var and :=, order temporary variable by their order in order.Detail

* exchange/binance/websocket: order fields of WsOrderUpdateData by the documented/received-over-the-websocket order of fields

* exchange/binance/websocket: add explicitly "M" as WsOrderUpdateData.Ignored2, which would otherwise override small "m"

* exchange/binance/websocket: check for zero when computing averagePrice

* exchange/binance/test: update TestExecutionTypeToOrderStatus and TestWsOrderExecutionReport

* exchange/binance/websocket: wsOrderUpdate now reports cost thus far, not the total order cost as that cannot be predicted in the case of partially filled orders

* exchange/ftx/websocket: WsOrderDataStore now reports cost thus far, not the total order cost as that cannot be predicted in the case of partially filled orders

* exchange/binance/websocket: executionReport now does not set TargetAmount as it is not applicable

* exchanges: binance/websocket and ftx/websocket now properly set Date and LastUpdated time fields when reporting a trade

* exchange/binance/websocket: check if WsOrderUpdateData.CommissionAsset is populated when assigning feeAsset

* exchange/binance/test: fix TestWsOrderExecutionReport
2021-08-18 18:31:03 +10:00
TaltaM
4ba2c710b5 Bittrex: Enable ws orderbook sync recovery (resolves #746) (#747)
* [FIX] Enable ws orderbook sync recovery by:

- Testing if books have been cleared
- Assigning options when loading snapshot

* orderbooks: remove setlastupdate method and on select depth method that updates linked list, this reduced lock contention across code base and fixes buffer bug on applying buffered updates

* WS - Introduce signaling for the need to fetch the orderbook

* Address nits

* Update error messages to include exchange name

Co-authored-by: shazbert <oharareid.ryan@gmail.com>
2021-08-18 11:43:46 +10:00
Adrian Gallagher
08df015a57 gctcli: Fix enable flag for various commands (#752) 2021-08-18 10:44:43 +10:00
Rocky Yang
c38757a689 Binance websocket: Order Detail Execution Report (#750)
* * Binance websocket: set commission of order Detail

* * Binance websocket: set commissionAsset of order.Detail

* * Binance websocket: change CostAsset to type currency.Code

* * Binance websocket: call NewCode after checking CommissionAsset is not empty. This guarantees that NULL CommissionAsset is mapped to an empty order.Detail.CostAsset. Otherwise, reflect.DeepEqual will fail on test. Update TestWsOrderExecutionReport json message to BTC commission.

* * Binance websocket: binance websocket "ExecutionReport" only provides "trade" status (partially filled), so check that executed amount == total amount before change status to filled
2021-08-17 14:33:54 +10:00
Luis Rascão
96669e29cf engine/exchange manager: Add support for custom exchanges (#749)
* engine: Setup exchange manager earlier

So it's available for applications before starting.

* engine: Add a custom exchange builder interface

Allows applications that import GCT as a lib to build new
custom exchanges without further modifications.
2021-08-17 14:03:05 +10:00
Ryan O'Hara-Reid
736c92a99b bithumb: Add websocket support (#745)
* bithumb: Add websocket support (WIP)

* bithumb: cont impl.

* bithumb: finish, issues with orderbook needs review

* linter issues

* bithumb: move to separate file

* bithumb: change to pointer for book

* bithumb: Add tests

* bithumb: Address nits

* websocket: Export subscription error and wrap returns

* bithumb: cleanup/ fix tests

* gctrpc/bithumb: fix misspelling

* bithumb: gofmt

* readme: update support table, regen doc

* tradesReadme: update

* readme: update template
2021-08-16 16:53:23 +10:00
dependabot[bot]
e77baf3ad4 build(deps): bump google.golang.org/grpc from 1.39.1 to 1.40.0 (#748)
Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.39.1 to 1.40.0.
- [Release notes](https://github.com/grpc/grpc-go/releases)
- [Commits](https://github.com/grpc/grpc-go/compare/v1.39.1...v1.40.0)

---
updated-dependencies:
- dependency-name: google.golang.org/grpc
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-08-13 10:49:38 +10:00
Scott
126187b31b Bugfix: Syncer & websocket circular dependency (#743)
* Fixes cyclical dependency

* why not lint

* Addresses potential wait if websocket subsystem is disabled
2021-08-11 17:06:01 +10:00
Yordan Miladinov
c7c8cac21f exchanges/ftx: Order improvements: submission + websocket reports (#741)
* exchanges/ftx: add support for ReduceOnly, ImmediateOrCancel and PostOnly orders

* exchanges/ftx: adapt tests to ReduceOnly/ImmediateOrCancel/PostOnly boolean flags

* exchanges/ftx: wrong json key of WsFillsDataStore.FillsData was causing json.Unmarshal() to yield an empty struct

* exchanges/ftx: update WsFills to latest API

* exchanges/ftx: add TestFTX_wsHandleData_wsFills

* exchanges/ftx: WsOrders.FilledSize was never parsed properly because of a key error (was spelled `filedSize` -- with one L);  enrich data structure to support latest API fields

* exchanges/ftx: when order is closed, set status to closed, not canceled

* exchanges/ftx: compatibleOrderVars: compare floats for almost-equality

* order.Detail: add field: AverageExecutedPrice float64

* exchanges/ftx: FTX.wsHandleData() now populates all order.Detail fields properly on update/orders websocket message

* exchanges/ftx: implement TestFTX_wsHandleData_Details()

* exchanges/ftx: make golangci-lint happy

* exchanges/ftx: make golangci-lint happy

* exchanges/ftx/test: delete redundant commented code

* exchanges/ftx: move websocket tests from ftx_test.go to ftx_websocket_test.go

* exchanges/ftx: remove redundant line

* exchange/ftx: greatly simplify TestFTX_wsHandleData (thanks to @shazbert)

* exchanges/ftx: make golangci-lint/whitespace happy

* exchanges/ftx: requested review change: delete a redundant line

* exchanges/ftx/test: use predefined currency constants
2021-08-11 10:28:47 +10:00
Ryan O'Hara-Reid
232d6ebc1f rate limit: make context aware (#731)
* rate limits: Make context aware

* binance: rate limit allow for cancellation of reservation when deadline is exceeded

* request: add context.done() before initiating any bulk work.

* binance: update error return for rate limiting

* request: updated dealine check to remove after time.Now procedure as this will obfuscate a deadline which will be limited by the context check on every attempt, so no need to sleep with delay.
2021-08-10 12:08:27 +10:00
dependabot[bot]
4602ade809 build(deps): bump google.golang.org/grpc from 1.39.0 to 1.39.1 (#742)
Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.39.0 to 1.39.1.
- [Release notes](https://github.com/grpc/grpc-go/releases)
- [Commits](https://github.com/grpc/grpc-go/compare/v1.39.0...v1.39.1)

---
updated-dependencies:
- dependency-name: google.golang.org/grpc
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-08-09 09:28:42 +10:00
Ryan O'Hara-Reid
279b53827f requester: defer execution of request.Item generation in closure (#723)
* requester: defer execution of request.Item generation in closure.

* bithumb: fix issue

* coinut/itbit: fix linter issues

* binance: fix bug on recvWindow setting

* requester: standardize sendpayload + add readme update

* nonce: remove inc() function

* request: defer unlockiflocked

* binance: revert changes for open orders

* btcmarkets: defer auth generation functionality, rm context deadline as this will be created just before sending HTTP request.

* binance: move const to top

* exmo: remove debug output as its generated in the requester function

* ftx: defer auth functionality

* requester: move error to top

* bittrex: defer auth functionality

* bitmex: defer auth functionality and remove deadline as generation occurs after rate limiting.

* btse: defer auth functionality

* coinbasepro: defer auth functionality and removed context deadline as this is generated after rate limiting

* coinbene: defer auth functionality and remove context deadline as this is generated after rate limiting

* huobi: defer auth functionality and remove context deadline as this is generated after rate limiting

* huobi-futures: defer auth functionality and remove context deadline as this is generated after rate limiting

* kraken: defer auth functionality and remove context deadline as this is generated after rate limiting

* kraken: remove deadline protection for timestamp generation

* okgroup: defer auth functionality and remove context deadline as this is generated after rate limiting

* poloniex: defer auth functionality

* zb: defer auth functionality and remove context deadline as this is generated after rate limiting

* exchanges: clean up log output which are done and inspected in the requester package

* binance: fix path bug on every retry, rm timeout context as this is not needed

* coinbene: fix path bug on retry

* binance: consolidate functionality

* coinbene: fix linter issues

* poloniex: linter fix

* kraken: change add -> set

* bitstamp: fix path bug for retry

* BTSE: fix retry path bug

* coinbene: fix path bug whoopsie by me

* gateio: fix bug where on retry it does not reset reader

* localbitcoins: fix path bug on retry

* zb: change domain to land

* exchanges: make sure io.Reader is generated every request

* exchanges: move reader generation into function scope

* wrapper_issues: setup exchange manager

* engine: expand withdraw manager test

* engine: dont look for environment

* bitstamp: fix pathing bug (@thrasher-)

* engine/withdraw_manager: purge tests as this is covered in repository withdraw
2021-08-06 17:24:38 +10:00
Yordan Miladinov
2da239735f gctrpc/order manager: Add ModifyOrder endpoint (#724)
* gctcli: modifyorder stubs

* gctcli: add ModifyOrderRequest and ModifyOrderResponse in rpc.proto

* gctcli: regenerate rpc.pb.go after the addition of ModifyOrder structs

* gctrpc: add ModifyOrder() and regenerate dependent files

* gctcli: modifyorder command now uses newly generated ModifyOrder() RPC

* exchanges/order/orders.go: use time.Time.Equal() instead of ==

* gctrpc: update ModifyOrderRequest and ModifyResponse and regenerate gRPC

* gctcli/commands: rework modifyorder

* engine: implement RPCServer.ModifyOrder

* engine: commit an initial version OrderManager.Modify(), still does not update state of managed orders

* engine: OrderManager.Modify now updates the inner state of managed orders, but introduces race conditions, needs fixes

* engine/order_manager.go: comply with golangci-lint

* gctcli: fix getOrderCommand.ArgsUsage

* gctcli: fix getModifyOrderCommand args and ArgsUsage

* engine: OrderManager.Modify() now correctly updates price of modified order

* engine: RPCServer.ModifyOrder now uses checkParams() as advised

* exchanges: (1) IBotExchange.ModifyOrder now returns a Modify struct, (2) all exchanges are updated to comply with that change

* exchanges/order: Detail.UpdateOrderFromModify also updates the ID

* engine/order_manager: add store.modifyExisting() and use it in OrderManager.Modify to update (on success) the state of the modified order

* exchanges: Bitfinex.ModifyOrder() now returns the ID in case of an error

* engine: OrdetManager.Modify() now emits an order event

* exchanges/bithumb: proper order.payment_currency key

* engine/order_manager: populate more Modify fields as they are needed by (some) exchanges, add comments

* engine: test OrderManager.Modify()

* engine: test store.modifyExisting()

* engine: write a docstring for store.modifyExisting

* engine: OrderManager.Modify() now also sets Modify.Price and Modify.Amount in case of zero values

* engine: TestOrderManager_Modify() now verify the effects of price and/or amount set to 0

* engine: OrderManger.Modify() now uses the commsManager to let observers know of errors

* engine: TestOrderManager_Modify() uses t.Fatal()

* engine: TestOrderManager_Modify() and TestStore_modifyOrder() supply t.Error() with proper messages

* exchanges/order_manager_test: fix a golangci-lint complaint

* engine/order_manager: fix an error comparison bug and simplify

* gctcli/commands: check if either price or amount is set, otherwise we would waste an API call
2021-08-06 10:09:14 +10:00
Scott
547d123984 Fixes holding amounts got btse and gemini (#738) 2021-08-05 12:02:00 +10:00
Yordan Miladinov
d638f0b9fb exchanges/binance: Binance.UpdateAccountInfo() now correctly assigns Balance.Hold for spot (#736) 2021-08-05 12:01:14 +10:00
Scott
48434dfd46 Feature: Candle conversion & Candle validation (#716)
* Remove old concept. Introduce new job types and candle scaling

* Adds extra processing, commands

* new concept for queued jobs. Jobs can pause. New commands to manage status

* =End of day commit designing tables and implementing prerequisites further.

* Adds postgres data history relations

* Fixes table design for sqlite. Fixes all issues from merge

* Fixes craziness of database design. Adds some functions to get related jobs

* Fixes errors

* Updates some documentation, manages prerequisite jobs a little better, adds rpc funcs

* Fixes database design and adjust repo functions

* Tests database relationship

* Test coverage of new job functions

* Finishes coverage of new functions

* Commands and RPC coverage

* New database modifications for new job types

* Adds db support of new columns. Adds conversion validation. lint

* command blurb changes

* Allows websocket test to pass consistently

* Fixes merge issue preventing datahistorymanager from starting via config

* Minor fixes for different job type processing

* Fixes rangeholder issue, fixes validation, does not address jobs not starting or wrong status

* Fixes database tests, but at what cost. Fixes dhm tests

* Fixes dhj completion issue. Adds prerequisite by nickname

* Fixes validation processing. Adds db tests and validation

* Fixes validation job processing range

* Fixes trade sql. Reduces defaults. Validation processing and errors

* Updates cli job commands. adds validation decimal. fix job validation

* Expands run job handling and tests

* Validation work

* Fixes validation processing

* candle relations. new job type. updating database design

* Adds secondary exchange support. Sets stage for candle override

* Re adds accidentally deleted relationship

* Updates loading and saving candles to have relationship data when relevant

* Now validates and replaces candle data appropriately

* Fixes getting and setting datahistory data. Neatens DHM

* Test coverage

* Updates proto for new db types. New test coverage. Secondary exchange work

* Investigation into never-ending validation jobs. Now that intervals are ruled out, now need to complete the job....

* Fixes issues with validation job completion. Fixes validation volume issue for secondary exchange

* Adds candle warning support to the backtester

* Fixes warnings

* lint and begin docs

* Documentation updates. Final testing changes

* Minor fixes

* docs, prerequisite checks, more testing

* Fixes binance trade test. Rename err

* Documentation fixes. Figure fixes

* documentation update

* Fixes remote PSQL tests

* Fix binance mock test

* Remove unnecessary JSON

* regen proto

* Some minor nit fixes

* Var usage, query sorting, log improving, sql mirroring

* Extra coverage

* Experimental removal of m.jobs and mutex. Fix messaging

* Fixes error

* Lint fixes, command description improvements. More isRunning gates

* description improvements

* Lint

* BUFF regenerate

* Rough concept to fix insertions taking up long periods of time

* New calculation for trade data. Adds batch saving

This also adds an experimental request feature to shut down lingering requests. However, its uncertain whether or not this is having any impact. Initially thought it was the trades that was taking time and not SQL. Will investigate further

* Removes experimental requester. Adds documentation. Fixes typo

* rm unused error

* re-adds more forgotten contributors

* Now with proper commit count
2021-08-05 10:27:27 +10:00
Yordan Miladinov
3b1fe81d8b FTX: order cancellation improvement (#727)
* exchanges/request: Requester.doRequest() now always parses returned response body into JSON even in the case of an artificial error after the request itself

* exchanges/ftx: consider order cancellation successful under two new conditions, reported by the exchange: (1) order is already closed or (2) order is already queued for cancellation

* exchanges/ftx: fix a typo in a comment

* exchanges/request: keep the same behavior of doRequest() when there is an unmarshaling error

* exchanges/ftx: FTX.DeleteOrderByClientID now also reports no errors when requesting the cancellation of orders that are already canceled on the exchange

* exchanges/ftx: order deletion methods are now unified

* exchanges/ftx: DeleteOrder* methods now check if the given ID is not empty
2021-07-31 15:13:52 +10:00
Scott
bf5a24b3d7 FTX: Fix incorrect partially-cancelled order assignment (#730)
* Fixed issues that led to incorrect partially-cancelled status

* Fixes all compatibleOrderVars args.Adds tests.Allow Offline fee testing

Co-authored-by: Mark Dzulko <mark@dzulko-clan.de>
2021-07-30 12:17:13 +10:00
Ryan O'Hara-Reid
431c0fdde7 bithumb: Add basic exchange order execution limits (#726)
* bithumn: Add basic exchange order execution limits

* WOW

* bithumb: add calculation for minimum amounts based off front end calculations regards @thrasher

* bithumb: fix nits
2021-07-29 15:02:07 +10:00
Ryan O'Hara-Reid
a2381310da GCT: general updates across codebase (#699)
* orderbook: export orderbook nodes for external strategy inspection

* orderbook: Add in methods for locking and unlocking multiple books at the same time e.g. book1.LockWith(book2); defer book1.UnlockWith(book2)

* include waiting functionality for depth change alert

* backtester: add word.

* log: include logger changes to impl with downstream integration

* engine: reduce params for loading exchange

* assort: rm verbose in tests, change wording in ob, expose sync.waitgroup for ext. sync options

* ticker: reduce map look ups and contention when using RW mutex when there are over 80% writes adds find last function to get the latest rate

* engine/syncmanager: add in waitgroup for step over for external package calls

* cleaup

* engine: linter fix

* currency/fx: include all references to fiat currencies to default

* orderbook: Add in fields to Unsafe type for strategies to detect potential out of sync book operations

* syncmanager: changed config variable to display correct time

* ordermanager: Add time when none provided

* currency/manager: update getasset param to get enabled assets for minor optimizations

* ftx: use get all wallet balances for a better accounts breakdown

* orderbook: unlock in reverse order

* bithumb: fixes bug on market buy and sell orders

* bithumb: fix bug for nonce is also time window sensitive

* bithumb: get orders add required parameter

* bithumb: Add asset type to account struct

* currency: improve log output when checking currency and it fails

* bithumb: Add error return on incomplete pair

* ticker:unexport all service related methods

* ticker/currency: fixes

* orderbook: fix comment

* engine: revert variable name in LoadExchange method

* sync_manager: fix panic when enabling disabling manager

* engine: fix naming convention of exported function and comments

* engine: update comment

* orderbook: fix comment for unsafe type
2021-07-29 14:42:28 +10:00
Yordan Miladinov
4f5ab42bd8 build: Enrich .gitignore (#728)
* gitignore: ignore __debug_bin (compiled by delve)

* gitignore: ignore coverage reports
2021-07-29 09:37:38 +10:00
Ryan O'Hara-Reid
9ea72f2193 ftx: add basic exchange order execution limits for lower bound (#725)
* ftx: add basic exchange order execution limits for lower bound

* ftx/binance: conform to standard logger output

* ftx: fix field from SizeIncrement -> MinProvideSize

* limits: fix whoopsie

* limit: add tests

* ftx: fix comment
2021-07-29 09:15:02 +10:00
Luis Rascão
a6e158ab0c Switch protobuf generation to buf cli tool (#720)
Current generation of protobuf stubs is hard and there's open issues
around it:
   https://github.com/grpc-ecosystem/grpc-gateway/issues/1065

grpc-gateway author and README suggest to use `buf` instead which
intends to be a simpler and more reliable method of protobuf stub
generation.
2021-07-28 10:34:46 +10:00
Yordan Miladinov
4d9a49e7f7 gctrpc: endpoints now optionally return timestamps in nanoseconds (configurable) (#718)
* config: add remoteControl/gRPC/timeInNanoSeconds

* grpc: consult with remoteControl/gRPC/timeInNanoSeconds whether timestamps should be in seconds or nanos

* engine: test if RPCServer.unixTimestamp() respects config/remoteControl/gRPC/timeInNanoSeconds

* engine: implement TestRPCServer_GetTicker_LastUpdatedNanos that makes sure TickerResponse.LastUpdated is returned in nanoseconds if configured

* config_example.json: add remoteControl/gRPC/timeInNanoSeconds

* engine: (1) test RPCServer.unixTimestamp() in parallel, (2) increase time tolerance of TestRPCServer_GetTicker_LastUpdatedNanos()

* engine: TestRPCServer_GetTicker_LastUpdatedNanos() now fetches a mock-up ticker to check timestamps
2021-07-28 09:22:20 +10:00
Scott
b5aa3eddb2 backtester: Fix selling bug, add planned features list (#722)
* Fixes sell bug. Updates docs. Adds test

* Doc fixes

* reorder and lint

* Lint again!

* Minor improvement to ensure theoretical upsized orders don't exceed portfolio limits

* Fixes test error

* %vamoose!

* Fixes defaulting to int
2021-07-27 12:50:07 +10:00
Yordan Miladinov
c23d66b873 gctrpc: generate protobuf files with latest versions of tools (#721)
* gctrpc: generate protobuf files with latest versions of tools

* gctrpc: generation scripts now use protoc-gen-openapiv2 (instead of protoc-gen-swagger)

* gtcrpc: update readme
2021-07-27 12:37:30 +10:00
Yordan Miladinov
44ae89542f connchecker: initialCheck() now also respects CheckInterval (#719) 2021-07-26 12:31:47 +10:00
Luis Rascão
cb21caccd0 backtester: Improve test coverage (#717)
* Improve config test coverage

* Improve common test coverage

* Improve data test coverage

* Silence false positives on table tests
2021-07-23 13:14:22 +10:00
Mark Dzulko
e1eceeafe8 gctrpc/ordermanager/binance: Add new getManagedOrders command and various improvements (#712)
* first draft of getmanaged orders RPC call

* - ClientIDs for binance, especially spot asset
- applied old ClientOrderId for cancelled orders
- added clientOrderId to GCTRPC

* added tests for Matchfilter and GetManagedOrders

* smaller fixes

* comment fix
added getFilteredOrders to store
changed store mutex to RWMutex
smaller fixes

* fixed bug in Detail Copy and added test

* fixes for Scotts review

* processSubmittedOrder was missing clientOrderId

* changed: TestGetOrdersFiltered expanded
fixed: warning, where variable name collided with package name
fixed: used req.AssetType in binance_wrapper.go

Co-authored-by: Mark Dzulko <81071907+Mark-numus@users.noreply.github.com>
2021-07-20 10:27:16 +10:00