Files
sendico/api/fx/oracle/client/fake.go
Stephan D 62a6631b9a
All checks were successful
ci/woodpecker/push/db Pipeline was successful
ci/woodpecker/push/nats Pipeline was successful
service backend
2025-11-07 18:35:26 +01:00

61 lines
1.4 KiB
Go

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
}