Exception string indices must be integers intermittently


  • @admin I am a proficient Python/REST API programmer. When I try to use api.placeOrder(orderParams)
    with the following parameters, I am getting the exception "string indices must be integers" intermittently.
    I have seen a resolution in another thread suggesting to use all parameter values as string. I followed the same. Still I am getting the exception. For the sake of completeness, I am setting all 15 parameters. Please help me to resolve the issue ASAP as it is blocking me. Here is the set of parameters that I am using:

    {
    "variety": "NORMAL",
    "tradingsymbol": "MARUTI30JUN22FUT",
    "symboltoken": "56863",
    "transactiontype": "BUY",
    "exchange": "NFO",
    "ordertype": "MARKET",
    "producttype": "CARRYFORWARD",
    "duration": "DAY",
    "price": "0",
    "quantity": "100",
    "triggerprice": "0",
    "squareoff": "0",
    "stoploss": "0",
    "disclosedquantity": "0",
    "ordertag": "api-order"
    }

    I installed SmartAPI with the command "pip install smartapi-python" without giving any version number.


  • @Mnagesh That is awesome. In short, setting all price values to float and quantity values to int will work. It is very logical and according to JSON spec. Thanks for your prompt and very accurate reply.


  • @cthomas {
    "variety": "NORMAL",
    "tradingsymbol": "MARUTI30JUN22FUT",
    "symboltoken": "56863",
    "transactiontype": "BUY",
    "exchange": "NFO",
    "ordertype": "MARKET",
    "producttype": "CARRYFORWARD",
    "duration": "DAY",
    "price": "0",
    "quantity": "100",
    "triggerprice": "0",
    "squareoff": "0",
    "stoploss": "0",
    "disclosedquantity": "0",
    "ordertag": "api-order"
    }

    in documentation it will show as string but are integers anf few are float type

    "price": "0", # must be float type
    "quantity": "100", # must be integer
    "triggerprice": "0", # must be float
    "squareoff": "0", # must be float
    "stoploss": "0", # must be float
    "disclosedquantity": "0", # must be integer

    while passing parameters we must send as integers or float

    but while reciving them they will be returned as string because of javascript type json or so ....

    so we must know when to treat them as strings or when to treat them as numbers