Navigation

    SmartAPI Forum
    • Register
    • Login
    • Search
    • Categories
    • Popular
    • Groups
    • FAQs
    • API Docs

    Exception string indices must be integers intermittently

    Python SDK
    0
    3
    30
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C
      cthomas last edited by

      @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.

      1 Reply Last reply Reply Quote 0
      • Mnagesh
        Mnagesh last edited by

        @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

        Now I am full time Algo Trader and successfully developed my own Apps for my personal use.

        C 1 Reply Last reply Reply Quote 0
        • C
          cthomas @Mnagesh last edited by

          @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.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post