Quote cancel
This commit is contained in:
@ -423,3 +423,47 @@ func (cont *Controller) SendQuote(ctx *gin.Context) {
|
||||
|
||||
ctx.JSON(http.StatusOK, Msg{Text: "Quote sent"})
|
||||
}
|
||||
|
||||
// CancelQuote godoc
|
||||
// @Summary Cancel a Quote for a QuoteRequest
|
||||
// @Description Builds and sends a QuoteCancel (35=Z) to TW for an existing QuoteRequest
|
||||
// @Tags fix
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body CancelQuoteRequest true "Quote cancel request"
|
||||
// @Success 200 {object} Msg
|
||||
// @Failure 400 {object} HTTPError
|
||||
// @Failure 401 {object} HTTPError
|
||||
// @Failure 404 {object} HTTPError
|
||||
// @Failure 409 {object} HTTPError
|
||||
// @Failure 500 {object} HTTPError
|
||||
// @Router /qfixdpl/v1/quotes/cancel [post]
|
||||
func (cont *Controller) CancelQuote(ctx *gin.Context) {
|
||||
setHeaders(ctx, cont.config)
|
||||
|
||||
var req CancelQuoteRequest
|
||||
if err := ctx.ShouldBindJSON(&req); err != nil {
|
||||
ctx.JSON(http.StatusBadRequest, HTTPError{Error: err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
if !cont.checkServiceAPIKey(req.APIKey) {
|
||||
ctx.JSON(http.StatusUnauthorized, HTTPError{Error: "Not allowed to perform this request"})
|
||||
return
|
||||
}
|
||||
|
||||
if err := cont.tradeProvider.CancelQuote(req.QuoteReqID, req.Text); err != nil {
|
||||
msg := err.Error()
|
||||
switch {
|
||||
case strings.Contains(msg, "not found"):
|
||||
ctx.JSON(http.StatusNotFound, HTTPError{Error: "quoteReqID not found"})
|
||||
case strings.Contains(msg, "cannot respond"):
|
||||
ctx.JSON(http.StatusConflict, HTTPError{Error: "quote request cannot be cancelled"})
|
||||
default:
|
||||
ctx.JSON(http.StatusInternalServerError, HTTPError{Error: "failed to cancel quote"})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK, Msg{Text: "Quote cancel sent"})
|
||||
}
|
||||
|
||||
@ -23,6 +23,12 @@ type SendQuoteRequest struct {
|
||||
Price string `json:"Price" binding:"required" example:"99.6"`
|
||||
}
|
||||
|
||||
type CancelQuoteRequest struct {
|
||||
APIKey string `json:"APIKey" binding:"required"`
|
||||
QuoteReqID string `json:"QuoteReqID" binding:"required"`
|
||||
Text string `json:"Text,omitempty"`
|
||||
}
|
||||
|
||||
type AllMessagesRequest struct {
|
||||
APIKey string
|
||||
In int
|
||||
|
||||
@ -29,6 +29,7 @@ func SetRoutes(api *API) {
|
||||
services := v1.Group("/")
|
||||
services.POST("/messages", cont.AllMessages)
|
||||
services.POST("/quotes", cont.SendQuote)
|
||||
services.POST("/quotes/cancel", cont.CancelQuote)
|
||||
|
||||
backoffice := qfixdpl.Group("/backoffice")
|
||||
backoffice.Use(cont.BackOfficeUser)
|
||||
|
||||
@ -22,6 +22,7 @@ type TradeProvider interface {
|
||||
GetTrades() []domain.ListTrade
|
||||
GetPendingQuoteRequests() []domain.ListTrade
|
||||
SendQuote(quoteReqID string, price decimal.Decimal) error
|
||||
CancelQuote(quoteReqID, text string) error
|
||||
GetAllMessages(inSeq, outSeq int) []domain.Message
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user