MCPcopy Create free account
hub / github.com/ccxt/ccxt / assert_order_state

Function assert_order_state

python/ccxt/test/exchange/base/test_shared_methods.py:424–480  ·  view source on GitHub ↗
(exchange, skipped_properties, method, order, asserted_status, strict_check)

Source from the content-addressed store, hash-verified

422
423
424def assert_order_state(exchange, skipped_properties, method, order, asserted_status, strict_check):
425 # note, `strictCheck` is `true` only from "fetchOrder" cases
426 log_text = log_template(exchange, method, order)
427 msg = 'order should be ' + asserted_status + ', but it was not asserted' + log_text
428 filled = exchange.safe_string(order, 'filled')
429 amount = exchange.safe_string(order, 'amount')
430 # shorthand variables
431 status_undefined = (order['status'] is None)
432 status_open = (order['status'] == 'open')
433 status_closed = (order['status'] == 'closed')
434 status_clanceled = (order['status'] == 'canceled')
435 filled_defined = (filled is not None)
436 amount_defined = (amount is not None)
437 condition = None
438 #
439 # ### OPEN STATUS
440 #
441 # if strict check, then 'status' must be 'open' and filled amount should be less then whole order amount
442 strict_open = status_open and (filled_defined and amount_defined and filled < amount)
443 # if non-strict check, then accept & ignore undefined values
444 nonstrict_open = (status_open or status_undefined) and ((not filled_defined or not amount_defined) or Precise.string_lt(filled, amount))
445 # check
446 if asserted_status == 'open':
447 condition = strict_open if strict_check else nonstrict_open
448 assert condition, msg
449 return
450 #
451 # ### CLOSED STATUS
452 #
453 # if strict check, then 'status' must be 'closed' and filled amount should be equal to the whole order amount
454 closed_strict = status_closed and (filled_defined and amount_defined and Precise.string_eq(filled, amount))
455 # if non-strict check, then accept & ignore undefined values
456 closed_non_strict = (status_closed or status_undefined) and ((not filled_defined or not amount_defined) or Precise.string_eq(filled, amount))
457 # check
458 if asserted_status == 'closed':
459 condition = closed_strict if strict_check else closed_non_strict
460 assert condition, msg
461 return
462 #
463 # ### CANCELED STATUS
464 #
465 # if strict check, then 'status' must be 'canceled' and filled amount should be less then whole order amount
466 canceled_strict = status_clanceled and (filled_defined and amount_defined and Precise.string_lt(filled, amount))
467 # if non-strict check, then accept & ignore undefined values
468 canceled_non_strict = (status_clanceled or status_undefined) and ((not filled_defined or not amount_defined) or Precise.string_lt(filled, amount))
469 # check
470 if asserted_status == 'canceled':
471 condition = canceled_strict if strict_check else canceled_non_strict
472 assert condition, msg
473 return
474 #
475 # ### CLOSED_or_CANCELED STATUS
476 #
477 if asserted_status == 'closed_or_canceled':
478 condition = (closed_strict or canceled_strict) if strict_check else (closed_non_strict or canceled_non_strict)
479 assert condition, msg
480 return
481

Callers

nothing calls this directly

Calls 4

log_templateFunction · 0.85
safe_stringMethod · 0.80
string_ltMethod · 0.80
string_eqMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…