.NET VERSION



  • @surya I am started developing vb.net app. Please see the below code and let me know whether I am in the right direction. Also let me know how I can pass -d (Order_Object) to the web server.

    Dim strURL As String = "https://api.upstox.com/live/orders"
        Dim strResult As String
        Dim objResponse As WebResponse
        Dim objRequest As WebRequest
        objRequest = HttpWebRequest.Create(strURL)
        objRequest.ContentType = "application/json"
        objRequest.Headers.Add("x-api-key: your_api_key")
        objRequest.Headers.Add("authorization: Bearer your_access_token")
        Dim mycache As New CredentialCache
        mycache.Add(New Uri(strURL), "Basic", New NetworkCredential("your_api_key", "your_api_secret"))
        objRequest.Credentials = mycache
        objRequest.Method = "POST"
        ''objRequest.
        objResponse = objRequest.GetResponse()
        Using sr As New StreamReader(objResponse.GetResponseStream())
            strResult = sr.ReadToEnd()
            sr.Close()
        End Using


  • @160694 Yes you are in right track.

    postdata = "param1=value1&param2=value2&message=test+message"
    postdatabytes = New System.Text.UTF8Encoding().GetBytes(postdata)
            objRequest.Method = "POST"
            objRequest.ContentType = "application/x-www-form-urlencoded"
            objRequest.ContentLength = postdatabytes.Length
    
            Using stream = objRequest.GetRequestStream()
                stream.Write(postdatabytes, 0, postdatabytes.Length)
            End Using
            Dim result = objRequest.GetResponse()
    

    You can try working with above rough code. Basically you need to convert data into ByteArray and write the data on RequestStream

    Hope that helps :)



  • @surya When I try to get access token below error "The remote server returned an error: (400) Bad Request." is coming. I am trying with vb.net. Please see below code. is there anything missing. Values in code from Login, Api key and Api secret are correctly provided.

     Try
            Dim strURL As String = "https://api.upstox.com/index/oauth/token"
    
            Dim postdata As String
            postdata = "code=" & txtCodeFromLoginResponse.Text & "&grant_type=authorization_code&redirect_uri=" & Common.getAppSettings("REDIRECTURL")
            Dim postdatabytes As Byte()
            postdatabytes = New System.Text.UTF8Encoding().GetBytes(postdata)
            Dim objRequest As WebRequest
            objRequest = HttpWebRequest.Create(strURL)
            Dim mycache As New CredentialCache
            Dim apikey As String = Common.getAppSettings("APIKEY")
            Dim apisecret As String = Common.getAppSettings("APISECRET")
            objRequest.Credentials = New NetworkCredential(apikey, apisecret)
            objRequest.ContentType = "application/x-www-form-urlencoded"
            objRequest.ContentLength = postdatabytes.Length
            objRequest.Headers.Add("x-api-key: " + apikey)
            objRequest.Method = "POST"
            Using stream = objRequest.GetRequestStream()
                stream.Write(postdatabytes, 0, postdatabytes.Length)
            End Using
            Dim result As WebResponse
            result = objRequest.GetResponse()
            txtAccessToken.Text = result.ToString
        Catch ex As Exception
            txtErrorData.Text = "Get Access Token button : " & ex.Message & vbCrLf & txtErrorData.Text
        End Try


  • Any one can help me on above issue? I am able to get access token using curl with same parameters. I am facing one more issue. When I place order using API below error is coming.

    {"code":400,"status":"Bad Request","timestamp":"2017-06-20T16:56:24+05:30","message":"Bad Request","error":{"reason":"Invalid Order Entry - Wrong quantity, found : 10, expected : Should be Number"}}

    Parameter I passed is
    transaction_type=B&exchange=NSE_EQ&symbol=INDIACEM&quantity=10&order_type=L&product=D&price=118


  • Global Moderator

    Hi,

    This issue is happening as you are passing quantity in - quotes ("10").
    Can you please try removing quotes in quantity.

    Let me know if this works at your end.


  • Global Moderator

    @160694

    We have updated the parameter validations for quantity.

    Please verify at your end, if you are able to place an order successfully.
    Let me know if you still face any issue.

    Thanks,
    Renuka



  • Today I got some errors while using API.

    1. error user/user_target not logged in Orders I placed after 9.15 am are regected with this error. all orders are posted using API. Why this error is coming. Orders placed after 10.30 am are accepted with same access token.

    2. The underlying connection was closed: An unexpected error occurred on a receive. This may be because of my internet connection.

    3. Column 'unrealized_profit' does not belong to table data. This error is frequently coming when I call get position and convert json data to table object.

    4. The remote server returned an error: (504) Gateway Timeout.
      5.Unexpected character encountered while parsing value: <. Path '', line 0, position 0. This error is also coming when I call get position function and convert json to table


  • Global Moderator

    Hi @160694 ,

    1 . This error comes when you are not logged in to the system. Make sure you login every morning as we reboot our server at night.

    1. We are not sending 'unrealized_profit' if you don't have any but now we will make changes so that you get an empty value if there is no 'unrealized_profit'.
    2. We are working on this issue.
    3. This seems related to 3rd point. We will be working on it


  • When I am trying to run get orders I am getting the error as below. Please rectify the issue as soon as possible.
    <html><body><h1>504 Gateway Time-out</h1>
    The server didn't respond in time.
    </body></html>



  • Still the error is coming. get position is working properly. Please check.


  • Global Moderator

    @160694
    Can you please check today if you are still facing an issue?



  • @RenukaMisal Get Orders function is working today.
    Below error I reported earlier is still showing many times.
    Column 'unrealized_profit' does not belong to table data.



  • From today morning 9.20 am onwards I am getting the gateway timeout error which I reported earlier.
    <html><body><h1>504 Gateway Time-out</h1>
    The server didn't respond in time.
    </body></html>

    Are you people able to provide a permanent solution for this issue. My app need list of orders to prepare orders to be pushed. I have no use with this API which is throwing error continuously.


Log in to reply
 

Looks like your connection to Upstox Forum was lost, please wait while we try to reconnect.