Exemple #1
0
def position_book_request(scrip: Scrip = None):
    unique_id, ref_no, modified = config_manager.get_api_credentials()
    data = {k.unique_id: unique_id, k.ref_no: ref_no}
    if scrip:
        data.update({k.token_no: scrip.token_no})
    response = send_request(position_book_func, data)
    reader.read_position_book_response(response)
Exemple #2
0
def order_book_request(order_id: int = None, scrip: Scrip = None):
    unique_id, ref_no, modified = config_manager.get_api_credentials()
    data = {k.unique_id: unique_id, k.ref_no: ref_no}
    if order_id:
        data.update({k.order_no: order_id})
    if scrip:
        data.update({k.token_no: scrip.token_no})
    response = send_request(order_book_func, data)
    reader.read_order_book_response(response)
Exemple #3
0
def modify_order(order_id: int, price: float, qty: int, validity: str, order_type, trigger_price: float = None, ):
    unique_id, ref_no, modified = config_manager.get_api_credentials()
    data = {k.unique_id: unique_id, k.ref_no: ref_no, k.order_no: order_id}
    data.update({k.price: price, k.qty: qty})
    if order_type in [o.RL, o.SL]:
        if order_type == o.SL:
            if trigger_price is not None:
                data.update({k.trigger_price: trigger_price, k.book_type: order_type})
            else:
                _logger.warning("Trigger price is required for SL order")
        if order_type == o.RL:
            data.update({k.book_type: order_type})
    data.update({k.validity: validity})
    response = send_request(modify_order_func, data)
    # print(response)
    reader.read_order_modify_response(response)
Exemple #4
0
def place_order(scrip: Scrip, buy_sell: str, qty: int, order_type: str, validity: str, price: float = None,
                trigger_price: float = None):
    unique_id, ref_no, modified = config_manager.get_api_credentials()
    login_id, password = config_manager.get_credentials()
    data = {k.unique_id: unique_id, k.key_login_id: login_id, k.ref_no: ref_no}
    if scrip:
        data.update({k.gateway: scrip.exchange, k.exchange: scrip.exchange, k.token_no: scrip.token_no})
        data.update({k.client_code: login_id})
        data.update({k.buy_sell: buy_sell}) if buy_sell in [o.BUY, o.SELL] else _logger.debug(
            "Incorrect value for parameter: buy_sell")
        data.update({k.qty: qty}) if int(qty) else _logger.debug("parameter qty can only be of type int")
        data.update({k.price: price}) if price else _logger.debug("Not a limit order")
        if order_type in [o.RL, o.SL]:
            if order_type == o.SL:
                if trigger_price is not None:
                    data.update({k.trigger_price: trigger_price, k.book_type: order_type})
                else:
                    _logger.warning("Trigger price is required for SL order")
            if order_type == o.RL:
                data.update({k.book_type: order_type})
        data.update({k.validity: validity})
    response = send_request(order_func, data)
    reader.read_order_response(response)
Exemple #5
0
def order_status(order_id: int):
    unique_id, ref_no, modified = config_manager.get_api_credentials()
    data = {k.unique_id: unique_id, k.ref_no: ref_no, k.order_no: order_id}
    response = send_request(order_status_func, data)
    reader.read_order_status_response(order_id, response)