Flow 8.4 list trading working
This commit is contained in:
@ -33,21 +33,19 @@ type Controller struct {
|
||||
userData app.UserDataProvider
|
||||
store *store.Store
|
||||
orderStore domain.OrderStore
|
||||
fixSender domain.FIXSender
|
||||
config Config
|
||||
notify domain.Notifier
|
||||
authMutex deadlock.Mutex
|
||||
}
|
||||
|
||||
func newController(pool *redis.Pool, userData app.UserDataProvider,
|
||||
s *store.Store, orderStore domain.OrderStore, fixSender domain.FIXSender, config Config, n domain.Notifier,
|
||||
s *store.Store, orderStore domain.OrderStore, config Config, n domain.Notifier,
|
||||
) *Controller {
|
||||
return &Controller{
|
||||
pool: pool,
|
||||
userData: userData,
|
||||
store: s,
|
||||
orderStore: orderStore,
|
||||
fixSender: fixSender,
|
||||
config: config,
|
||||
notify: n,
|
||||
}
|
||||
@ -305,39 +303,3 @@ func (cont *Controller) GetOrders(ctx *gin.Context) {
|
||||
ctx.JSON(http.StatusOK, orders)
|
||||
}
|
||||
|
||||
// SendQuote godoc
|
||||
// @Summary Send a FIX Quote
|
||||
// @Description Sends a Quote (MsgType S) back to the FIX client for a given order
|
||||
// @Tags fix
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param quote body QuoteRequest true "Quote details"
|
||||
// @Success 200 {object} Msg
|
||||
// @Failure 400 {object} HTTPError
|
||||
// @Failure 404 {object} HTTPError
|
||||
// @Failure 500 {object} HTTPError
|
||||
// @Router /qfixdpl/v1/quotes [post]
|
||||
func (cont *Controller) SendQuote(ctx *gin.Context) {
|
||||
var req QuoteRequest
|
||||
if err := ctx.ShouldBindJSON(&req); err != nil {
|
||||
ctx.JSON(http.StatusBadRequest, HTTPError{Error: err.Error()})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
bidPx, offerPx, _, _, err := req.toDecimals()
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusBadRequest, HTTPError{Error: err.Error()})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if err = cont.fixSender.SendQuote(
|
||||
req.ClOrdID, req.QuoteID, req.Symbol, req.SecurityIDSource, req.Currency, bidPx, offerPx); err != nil {
|
||||
ctx.JSON(http.StatusInternalServerError, HTTPError{Error: err.Error()})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK, Msg{Text: "quote sent"})
|
||||
}
|
||||
|
||||
@ -1,10 +1,5 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
type HTTPError struct {
|
||||
Error string
|
||||
@ -23,26 +18,3 @@ type Session struct {
|
||||
Email string
|
||||
}
|
||||
|
||||
type QuoteRequest struct {
|
||||
ClOrdID string `json:"cl_ord_id" binding:"required"`
|
||||
QuoteID string `json:"quote_id" binding:"required"`
|
||||
Symbol string `json:"symbol" binding:"required"`
|
||||
Currency string `json:"currency"`
|
||||
BidPx string `json:"bid_px" binding:"required"`
|
||||
OfferPx string `json:"offer_px" binding:"required"`
|
||||
SecurityIDSource string `json:"security_id_source" binding:"required"`
|
||||
}
|
||||
|
||||
func (r QuoteRequest) toDecimals() (bidPx, offerPx, bidSize, offerSize decimal.Decimal, err error) {
|
||||
bidPx, err = decimal.NewFromString(r.BidPx)
|
||||
if err != nil {
|
||||
return bidPx, offerPx, bidSize, offerSize, fmt.Errorf("invalid bid_px: %w", err)
|
||||
}
|
||||
|
||||
offerPx, err = decimal.NewFromString(r.OfferPx)
|
||||
if err != nil {
|
||||
return bidPx, offerPx, bidSize, offerSize, fmt.Errorf("invalid offer_px: %w", err)
|
||||
}
|
||||
|
||||
return bidPx, offerPx, bidSize, offerSize, nil
|
||||
}
|
||||
|
||||
@ -22,7 +22,6 @@ func SetRoutes(api *API) {
|
||||
qfixdpl.Use(cont.AuthRequired)
|
||||
qfixdpl.GET("/health", cont.HealthCheck)
|
||||
qfixdpl.GET("/orders", cont.GetOrders)
|
||||
qfixdpl.POST("/quotes", cont.SendQuote)
|
||||
|
||||
backoffice := qfixdpl.Group("/backoffice")
|
||||
backoffice.Use(cont.BackOfficeUser)
|
||||
|
||||
@ -32,7 +32,7 @@ type Config struct {
|
||||
EnableJWTAuth bool
|
||||
}
|
||||
|
||||
func New(userData app.UserDataProvider, storeInstance *store.Store, orderStore domain.OrderStore, fixSender domain.FIXSender, config Config, notify domain.Notifier) *API {
|
||||
func New(userData app.UserDataProvider, storeInstance *store.Store, orderStore domain.OrderStore, config Config, notify domain.Notifier) *API {
|
||||
// Set up Gin
|
||||
var engine *gin.Engine
|
||||
if version.Environment() == version.EnvironmentTypeProd {
|
||||
@ -58,7 +58,7 @@ func New(userData app.UserDataProvider, storeInstance *store.Store, orderStore d
|
||||
}
|
||||
|
||||
api := &API{
|
||||
Controller: newController(NewPool(), userData, storeInstance, orderStore, fixSender, config, notify),
|
||||
Controller: newController(NewPool(), userData, storeInstance, orderStore, config, notify),
|
||||
Router: engine,
|
||||
Port: config.Port,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user