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"})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user