コード例 #1
0
def confirm_order(
    confirmation_id: str,
    order: Order,
    session_id: str,
    credentials: Credentials,
    raw: bool = False,
    session: requests.Session = None,
    logger: logging.Logger = None,
) -> Union[Order.ConfirmationResponse, bool]:
    if logger is None:
        logger = build_logger()
    if session is None:
        session = build_session()

    int_account = credentials.int_account
    url = URLs.ORDER_CONFIRM
    url = f'{url}/{confirmation_id};jsessionid={session_id}?intAccount={int_account}&sessionId={session_id}'

    order_dict = {
        'buySell': order.action,
        'orderType': order.order_type,
        'price': order.price,
        'productId': order.product_id,
        'size': order.size,
        'timeType': order.time_type,
    }

    request = requests.Request(method='POST', url=url, json=order_dict)
    prepped = session.prepare_request(request)
    response_raw = None

    try:
        response_raw = session.send(prepped, verify=False)

        response_dict = response_raw.json()
    except Exception as e:
        logger.fatal(response_raw.status_code)
        logger.fatal(response_raw.text)
        logger.fatal(e)
        return False

    if \
        isinstance(response_dict, dict) \
        and 'data' in response_dict \
        and 'orderId' in response_dict['data']:

        if raw == True:
            order.id = response_dict['data']['orderId']
            response = response_dict
        else:
            order.id = response_dict['data']['orderId']
            response = payload_handler.confirmation_response_to_grpc(
                payload=response_dict, )
    else:
        response = False

    return response
コード例 #2
0
def confirm_order(
    confirmation_id: str,
    order: Order,
    session_id: str,
    credentials: Credentials,
    raw: bool = False,
    session: requests.Session = None,
    logger: logging.Logger = None,
) -> Union[Order.ConfirmationResponse, bool]:
    if logger is None:
        logger = build_logger()
    if session is None:
        session = build_session()

    int_account = credentials.int_account
    url = urls.ORDER_CONFIRM
    url = f'{url}/{confirmation_id};jsessionid={session_id}'

    params = {
        'intAccount': int_account,
        'sessionId': session_id,
    }

    order_dict = payload_handler.order_to_api(order=order)

    request = requests.Request(
        method='POST',
        url=url,
        json=order_dict,
        params=params,
    )
    prepped = session.prepare_request(request)
    response_raw = None

    try:
        response_raw = session.send(prepped, verify=False)
        response_dict = response_raw.json()
    except Exception as e:
        logger.fatal(response_raw.status_code)
        logger.fatal(response_raw.text)
        logger.fatal(e)
        return False

    if isinstance(response_dict, dict) \
            and 'data' in response_dict \
            and 'orderId' in response_dict['data']:
        if raw is True:
            order.id = response_dict['data']['orderId']
            response = response_dict
        else:
            order.id = response_dict['data']['orderId']
            response = payload_handler.confirmation_response_to_grpc(
                payload=response_dict, )
    else:
        response = False

    return response