mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-23 23:16:49 +00:00
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
This commit is contained in:
@@ -36,6 +36,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/banking"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
"github.com/thrasher-corp/goose"
|
||||
"google.golang.org/grpc/metadata"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -50,7 +51,7 @@ type fExchange struct {
|
||||
exchange.IBotExchange
|
||||
}
|
||||
|
||||
func (f fExchange) GetHistoricCandles(p currency.Pair, a asset.Item, timeStart, _ time.Time, interval kline.Interval) (kline.Item, error) {
|
||||
func (f fExchange) GetHistoricCandles(ctx context.Context, p currency.Pair, a asset.Item, timeStart, _ time.Time, interval kline.Interval) (kline.Item, error) {
|
||||
return kline.Item{
|
||||
Exchange: "fake",
|
||||
Pair: p,
|
||||
@@ -69,7 +70,7 @@ func (f fExchange) GetHistoricCandles(p currency.Pair, a asset.Item, timeStart,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (f fExchange) GetHistoricCandlesExtended(p currency.Pair, a asset.Item, timeStart, _ time.Time, interval kline.Interval) (kline.Item, error) {
|
||||
func (f fExchange) GetHistoricCandlesExtended(ctx context.Context, p currency.Pair, a asset.Item, timeStart, _ time.Time, interval kline.Interval) (kline.Item, error) {
|
||||
return kline.Item{
|
||||
Exchange: "fake",
|
||||
Pair: p,
|
||||
@@ -90,7 +91,7 @@ func (f fExchange) GetHistoricCandlesExtended(p currency.Pair, a asset.Item, tim
|
||||
|
||||
// FetchAccountInfo overrides testExchange's fetch account info function
|
||||
// to do the bare minimum required with no API calls or credentials required
|
||||
func (f fExchange) FetchAccountInfo(a asset.Item) (account.Holdings, error) {
|
||||
func (f fExchange) FetchAccountInfo(ctx context.Context, a asset.Item) (account.Holdings, error) {
|
||||
return account.Holdings{
|
||||
Exchange: f.GetName(),
|
||||
Accounts: []account.SubAccount{
|
||||
@@ -105,7 +106,7 @@ func (f fExchange) FetchAccountInfo(a asset.Item) (account.Holdings, error) {
|
||||
|
||||
// UpdateAccountInfo overrides testExchange's update account info function
|
||||
// to do the bare minimum required with no API calls or credentials required
|
||||
func (f fExchange) UpdateAccountInfo(a asset.Item) (account.Holdings, error) {
|
||||
func (f fExchange) UpdateAccountInfo(ctx context.Context, a asset.Item) (account.Holdings, error) {
|
||||
if a == asset.Futures {
|
||||
return account.Holdings{}, errAssetTypeDisabled
|
||||
}
|
||||
@@ -875,6 +876,18 @@ func TestGetRecentTrades(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// dummyServer implements a basic RPC server interface for deployment in a test
|
||||
// when streaming occurs, so we can deliver a context value.
|
||||
type dummyServer struct{}
|
||||
|
||||
func (d *dummyServer) Send(*gctrpc.SavedTradesResponse) error { return nil }
|
||||
func (d *dummyServer) SetHeader(metadata.MD) error { return nil }
|
||||
func (d *dummyServer) SendHeader(metadata.MD) error { return nil }
|
||||
func (d *dummyServer) SetTrailer(metadata.MD) {}
|
||||
func (d *dummyServer) Context() context.Context { return context.Background() }
|
||||
func (d *dummyServer) SendMsg(m interface{}) error { return nil }
|
||||
func (d *dummyServer) RecvMsg(m interface{}) error { return nil }
|
||||
|
||||
func TestGetHistoricTrades(t *testing.T) {
|
||||
engerino := RPCTestSetup(t)
|
||||
defer CleanRPCTest(t, engerino)
|
||||
@@ -907,7 +920,7 @@ func TestGetHistoricTrades(t *testing.T) {
|
||||
AssetType: asset.Spot.String(),
|
||||
Start: time.Date(2020, 0, 0, 0, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormat),
|
||||
End: time.Date(2020, 0, 0, 1, 0, 0, 0, time.UTC).Format(common.SimpleTimeFormat),
|
||||
}, nil)
|
||||
}, &dummyServer{})
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user