en-US/about_MyWebApi_Timeouts.help.txt
|
TOPIC about_MyWebApi_Timeouts SHORT DESCRIPTION Request timeouts, timeout outcomes and the retry policy of the MyWebApi module. LONG DESCRIPTION Timeouts and retries Every REST cmdlet takes -RequestTimeout (seconds, 1-300): how long the server waits for the trading platform before it answers. The value is sent as the X-Request-Timeout header. Connect-MyWebApi -RequestTimeout sets a default for the whole session; a cmdlet's own -RequestTimeout wins. Without either, the server applies the operation's default: trade operation 5 s read 10 s change 15 s history or report 30 s server maintenance 60 s Get-Help <cmdlet> -Parameter RequestTimeout shows the default of a cmdlet. HTTP deadline The HTTP call waits for the requested (or default) server timeout plus 30 s, so the server's own answer arrives instead of an ambiguous client-side abort. An -HttpTimeoutSeconds set on Connect-MyWebApi is a hard cap for calls that do not pass -RequestTimeout explicitly. Errors A timeout is a terminating error with FullyQualifiedErrorId "MyWebApiError,<code>". $_.TargetObject and $_.Exception.Data carry Code, Outcome (the X-Request-Outcome response header), Retryable, RequestTimeoutApplied, ActivityId, IdempotencyKey and Guidance; the guidance text is also in $_.ErrorDetails.RecommendedAction. Timeout (outcome "timeout") A read did not finish in time. Nothing was changed; the request is safe to repeat. Allow more time with -RequestTimeout. OutcomeUnknown (outcome "unknown") A trade or change did not finish in time and may still be applied by the trading platform. Never repeat it blindly: repeat with the same -IdempotencyKey to receive the original result, or check the result first. OutcomeUnknown (outcome "in-progress") A request with the same Idempotency-Key is still being processed; this repeat was not executed. Repeat later with the same key. Busy (outcome "not-started") The request was refused before it reached the trading platform. Nothing was changed; repeat it after a short pause. Validation The request was rejected, for example a timeout outside 1-300 s. When no HTTP response arrives within the deadline the error id is MyWebApiHttpTimeout with TargetObject.Source = 'client'. For a write its Outcome is "unknown", and the OutcomeUnknown rule applies. Retries GET, HEAD and OPTIONS are retried automatically, at most MaxGetRetries times (Connect-MyWebApi -MaxGetRetries, default 2), on transport failures, HTTP 408/425/429/5xx and Busy. A Timeout is not retried automatically. Writes are never retried, with or without an Idempotency-Key. Real-time Hub calls addressed to a trading platform, and the v2 hub connect, are failed by the server after 60 s; streams are not affected. EXAMPLES $key = [guid]::NewGuid().ToString() try { Invoke-MT4TradeTransaction -TradePlatform $tp -Body $order -IdempotencyKey $key -RequestTimeout 10 } catch { if ($_.TargetObject.Code -ne 'OutcomeUnknown') { throw } Start-Sleep -Seconds 2 # The same key returns the original result instead of executing twice. Invoke-MT4TradeTransaction -TradePlatform $tp -Body $order -IdempotencyKey $key } SEE ALSO Connect-MyWebApi about_CommonParameters KEYWORDS RequestTimeout, X-Request-Timeout, OutcomeUnknown, Idempotency-Key, retry |