* @method * @name whitebit#fetchOrder * @description fetches information on an order by the id * @see https://docs.whitebit.com/private/http-trade-v4/#query-unexecutedactive-orders * @see https://docs.whitebit.com/private/http-trade-v4/#query-executed-orders * @param {string
(id: string, symbol: Str = undefined, params = {})
| 1402 | * @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure} |
| 1403 | */ |
| 1404 | async fetchOrder (id: string, symbol: Str = undefined, params = {}): Promise<Order> { |
| 1405 | await this.loadMarkets (); |
| 1406 | // Extract control parameters from params |
| 1407 | const checkActive = this.safeBool (params, 'checkActive', true); |
| 1408 | const checkExecuted = this.safeBool (params, 'checkExecuted', true); |
| 1409 | const request: Dict = { |
| 1410 | 'orderId': id, |
| 1411 | }; |
| 1412 | let market: Market = undefined; |
| 1413 | if (symbol !== undefined) { |
| 1414 | market = this.market (symbol); |
| 1415 | request['market'] = market['id']; |
| 1416 | } |
| 1417 | // Try active orders first (if enabled) |
| 1418 | if (checkActive) { |
| 1419 | try { |
| 1420 | const response = await this.v4PrivatePostOrders (this.extend (request, params)); |
| 1421 | // Search for order in active orders response (array format) |
| 1422 | for (let i = 0; i < response.length; i++) { |
| 1423 | const order = response[i]; |
| 1424 | const orderId = this.safeString (order, 'orderId'); |
| 1425 | if (orderId === id) { |
| 1426 | const marketId = this.safeString (order, 'market'); |
| 1427 | const marketNew = this.safeMarket (marketId, undefined, '_'); |
| 1428 | return this.parseOrder (order, marketNew); |
| 1429 | } |
| 1430 | } |
| 1431 | } catch (error) { |
| 1432 | if (!(error instanceof OrderNotFound)) { |
| 1433 | throw error; |
| 1434 | } |
| 1435 | } |
| 1436 | } |
| 1437 | // Try executed orders (if enabled) |
| 1438 | if (checkExecuted) { |
| 1439 | try { |
| 1440 | const response = await this.v4PrivatePostTradeAccountOrderHistory (this.extend (request, params)); |
| 1441 | // Search for order in executed orders response (object format) |
| 1442 | const marketIds = Object.keys (response); |
| 1443 | for (let i = 0; i < marketIds.length; i++) { |
| 1444 | const marketId = marketIds[i]; |
| 1445 | const marketNew = this.safeMarket (marketId, undefined, '_'); |
| 1446 | const orders = response[marketId]; |
| 1447 | for (let j = 0; j < orders.length; j++) { |
| 1448 | const order = orders[j]; |
| 1449 | const orderId = this.safeString (order, 'id'); |
| 1450 | if (orderId === id) { |
| 1451 | return this.parseOrder (order, marketNew); |
| 1452 | } |
| 1453 | } |
| 1454 | } |
| 1455 | } catch (error) { |
| 1456 | if (!(error instanceof OrderNotFound)) { |
| 1457 | throw error; |
| 1458 | } |
| 1459 | } |
| 1460 | } |
| 1461 | // If both checks failed or were disabled, throw OrderNotFound |
nothing calls this directly
no test coverage detected