Skip to content

Commit

Permalink
feat: quote margin
Browse files Browse the repository at this point in the history
  • Loading branch information
brokeyourbike committed Apr 16, 2024
1 parent 67827a8 commit a2d7a47
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
11 changes: 6 additions & 5 deletions fx.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ const (
)

type FXQuotePayload struct {
SellCurrency string
BuyCurrency string
InstructedAmount float64
FixedSide QuoteFixedSide
ValueDate string
SellCurrency string `json:"SellCurrency"`
BuyCurrency string `json:"BuyCurrency"`
InstructedAmount float64 `json:"InstructedAmount"`
FixedSide QuoteFixedSide `json:"FixedSide"`
ValueDate string `json:"ValueDate"`
Margin *float64 `json:"Margin,omitempty"`
}

type FXQuoteResponse struct {
Expand Down
15 changes: 15 additions & 0 deletions fx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
_ "embed"
"encoding/json"
"io"
"net/http"
"slices"
Expand Down Expand Up @@ -127,3 +128,17 @@ func TestFXQuoteResponse(t *testing.T) {
r2 := clearbank.FXQuoteResponse{SellCurrency: "EUR", BuyCurrency: "GBP", CurrencyPair: "GBP/EUR", ExchangeRate: 1.23}
require.Equal(t, 1/1.23, r2.GetRate())
}

func TestFXQuotePayload(t *testing.T) {
p1 := clearbank.FXQuotePayload{BuyCurrency: "USD", SellCurrency: "GBP"}
got1, err := json.Marshal(p1)
require.NoError(t, err)
require.Equal(t, `{"SellCurrency":"GBP","BuyCurrency":"USD","InstructedAmount":0,"FixedSide":"","ValueDate":""}`, string(got1))

margin := 0.002

p2 := clearbank.FXQuotePayload{BuyCurrency: "USD", SellCurrency: "GBP", Margin: &margin}
got2, err := json.Marshal(p2)
require.NoError(t, err)
require.Equal(t, `{"SellCurrency":"GBP","BuyCurrency":"USD","InstructedAmount":0,"FixedSide":"","ValueDate":"","Margin":0.002}`, string(got2))
}

0 comments on commit a2d7a47

Please sign in to comment.