FTX: order cancellation improvement (#727)

* exchanges/request: Requester.doRequest() now always parses returned response body into JSON even in the case of an artificial error after the request itself

* exchanges/ftx: consider order cancellation successful under two new conditions, reported by the exchange: (1) order is already closed or (2) order is already queued for cancellation

* exchanges/ftx: fix a typo in a comment

* exchanges/request: keep the same behavior of doRequest() when there is an unmarshaling error

* exchanges/ftx: FTX.DeleteOrderByClientID now also reports no errors when requesting the cancellation of orders that are already canceled on the exchange

* exchanges/ftx: order deletion methods are now unified

* exchanges/ftx: DeleteOrder* methods now check if the given ID is not empty
This commit is contained in:
Yordan Miladinov
2021-07-31 08:13:52 +03:00
committed by GitHub
parent bf5a24b3d7
commit 3b1fe81d8b
2 changed files with 29 additions and 33 deletions

View File

@@ -197,6 +197,12 @@ func (r *Requester) doRequest(req *http.Request, p *Item) error {
if err != nil {
return err
}
// Even in the case of an erroneous condition below, yield the parsed
// response to caller.
var unmarshallError error
if p.Result != nil {
unmarshallError = json.Unmarshal(contents, p.Result)
}
if p.HTTPRecording {
// This dumps http responses for future mocking implementations
@@ -242,10 +248,7 @@ func (r *Requester) doRequest(req *http.Request, p *Item) error {
string(contents))
}
}
if p.Result != nil {
return json.Unmarshal(contents, p.Result)
}
return nil
return unmarshallError
}
}