service backend
This commit is contained in:
60
api/fx/oracle/client/fake.go
Normal file
60
api/fx/oracle/client/fake.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
fxv1 "github.com/tech/sendico/pkg/proto/common/fx/v1"
|
||||
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1"
|
||||
)
|
||||
|
||||
// Fake implements Client for tests.
|
||||
type Fake struct {
|
||||
LatestRateFn func(ctx context.Context, req LatestRateParams) (*RateSnapshot, error)
|
||||
GetQuoteFn func(ctx context.Context, req GetQuoteParams) (*Quote, error)
|
||||
CloseFn func() error
|
||||
}
|
||||
|
||||
func (f *Fake) LatestRate(ctx context.Context, req LatestRateParams) (*RateSnapshot, error) {
|
||||
if f.LatestRateFn != nil {
|
||||
return f.LatestRateFn(ctx, req)
|
||||
}
|
||||
return &RateSnapshot{
|
||||
Pair: &fxv1.CurrencyPair{Base: "USD", Quote: "EUR"},
|
||||
Mid: "1.1000",
|
||||
Bid: "1.0995",
|
||||
Ask: "1.1005",
|
||||
SpreadBps: "5",
|
||||
Provider: "fake",
|
||||
RateRef: "fake",
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (f *Fake) GetQuote(ctx context.Context, req GetQuoteParams) (*Quote, error) {
|
||||
if f.GetQuoteFn != nil {
|
||||
return f.GetQuoteFn(ctx, req)
|
||||
}
|
||||
return &Quote{
|
||||
QuoteRef: "fake-quote",
|
||||
Pair: req.Pair,
|
||||
Side: req.Side,
|
||||
Price: "1.1000",
|
||||
BaseAmount: &moneyv1.Money{
|
||||
Amount: "100.00",
|
||||
Currency: req.Pair.GetBase(),
|
||||
},
|
||||
QuoteAmount: &moneyv1.Money{
|
||||
Amount: "110.00",
|
||||
Currency: req.Pair.GetQuote(),
|
||||
},
|
||||
Provider: "fake",
|
||||
RateRef: "fake",
|
||||
Firm: req.Firm,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (f *Fake) Close() error {
|
||||
if f.CloseFn != nil {
|
||||
return f.CloseFn()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user