Navigation

    SmartAPI Forum
    • Register
    • Login
    • Search
    • Categories
    • Popular
    • Groups
    • FAQs
    • API Docs
    1. Home
    2. sohambanik
    S
    • Profile
    • Following 0
    • Followers 0
    • Topics 2
    • Posts 2
    • Best 0
    • Groups 0

    sohambanik

    @sohambanik

    -1
    Reputation
    4
    Profile views
    2
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    sohambanik Unfollow Follow

    Latest posts made by sohambanik

    • 'NoneType' object is not subscriptable

      Getting error "'NoneType' object is not subscriptable". My username and password is correct as I am logging in successfully in the web platform with the same. Please help.

      posted in Python SDK
      S
      sohambanik
    • 'NoneType' object is not subscriptable

      Hi,

      Getting error in order placement, which says"Order placement failed: 'NoneType' object is not subscriptable". Username, password and api key are valid. Plz help!```
      code_text

      package import statement

      from time import sleep
      import pandas as pd
      from datetime import datetime
      import requests
      import numpy as np

      from smartapi import SmartConnect #or from smartapi.smartConnect import SmartConnect
      import smartapi.smartExceptions

      total_money = 2000

      create object of call

      obj=SmartConnect(api_key="Wj7BmSKt")

      #login api call

      data = obj.generateSession("S750557","thefretr21")
      refreshToken = data['data']['refreshToken']

      #fetch the feedtoken
      feedToken=obj.getfeedToken()

      #fetch User Profile
      userProfile= obj.getProfile(refreshToken)

      def getTokenInfo(df, exch_seg, instrument_type, symbol):
      symbol = symbol + "-EQ"
      df_script = token_df.loc[token_df['symbol'] == symbol]
      return df_script.iat[0,0]

      def round_of_num(number):
      return round(number * 2) / 2

      def place_order(stock, price):
      global token_df
      url = "https://margincalculator.angelbroking.com/OpenAPI_File/files/OpenAPIScripMaster.json"
      d = requests.get(url).json()
      token_df = pd.DataFrame.from_dict(d)
      script_token = getTokenInfo(token_df, 'NSE', '', stock)

      quantity = int(total_money / float(price))
      #place order
      try:
          orderparams = {
              "variety": "NORMAL",
              "tradingsymbol": stock,
              "symboltoken": script_token,
              "transactiontype": "BUY",
              "exchange": "NSE",
              "ordertype": "MARKET",
              "producttype": "INTRADAY",
              "duration": "DAY",
              # "price": "19500",
              # "squareoff": "0",
              # "stoploss": "0",
              "quantity": quantity
              }
          orderId=obj.placeOrder(orderparams)
          print("The order id is: {}".format(orderId))
      except Exception as e:
          print("Order placement failed: {}".format(e))
      

      def process_data(data):
      my_list = data['stocks'].split(",")
      prices = data['trigger_prices'].split(",")
      positions = obj.position()

      for i, stock in enumerate(my_list):
          # if stock not in positions['net']:
          place_order(stock,prices[i])
          sleep(0.5)
      

      def lambda_handler(event, context):
      process_data(event)
      return "Success"angel.png

      posted in Python SDK
      S
      sohambanik