How to sign a POST request with CoinEX API












0














I can sign every single private call to the API but the buy/sell order. It is the only call with a JSON request. All other calls are form URL encoded. It always return "signature error" or "cannot serialize to JSON".



Balances information end point "/balance/info"



Place order end point"/order/limit"



ref: CoinEx API doc



API Key: 09D8485F15B145F5B48D79B8E0FF4C8D



API Secret: 2F27E476B09140AA8E0B0F80CA4832A5F014A895E28BF8A1



There is no cryptocurrencies on the account so please use my key. I will erase it after but the key/secret is valid



 Private CoinEXAPIurl As String = "https://api.coinex.com/v1"

Private Function PrivateApiAsync(ByVal requestEndPoint As String, ByVal RequestType As HttpMethod, ByVal Params As Dictionary(Of String, String), Optional ByVal IncludeST As Boolean = True) As CallResult
Dim ErrMSG As String = "Unknown Error"
Try
Dim xhttp As New HttpClient()
Dim request As New HttpRequestMessage
Dim sign As String = ""
Dim Parameters As String = ""
Dim tonce = Int(DateTime.Now.ToUniversalTime.Subtract(New DateTime(1970, 1, 1)).TotalMilliseconds)
Dim newparam As New Dictionary(Of String, String)
newparam.Add("access_id", _Credentials.APIKey)
For Each entry In Params
newparam.Add(entry.Key, entry.Value)
Next
newparam.Add("tonce", tonce)

Dim FormURLEncodedSTR = New FormUrlEncodedContent(newparam).ReadAsStringAsync.Result
sign = GetHash(FormURLEncodedSTR & "&" & "secret_key=" & _Credentials.APISecret)

With request
.Headers.Add("authorization", sign)
.Headers.UserAgent.ParseAdd("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36")
.Method = RequestType
If RequestType = HttpMethod.Post Then
.RequestUri = New Uri(CoinEXAPIurl & requestEndPoint)
.Content = New StringContent(Json_.Serialize(newparam), Encoding.UTF8, "application/json")
Else
.RequestUri = New Uri(CoinEXAPIurl & requestEndPoint & "?" & FormURLEncodedSTR)
End If
End With

Dim result = xhttp.SendAsync(request).Result
Dim xcontent = result.Content.ReadAsStringAsync.Result
Dim jData = Json_.DeserializeObject(xcontent)
Dim Success As Boolean = False
If jData("code") <> 0 Then
ErrMSG = jData("message")
Else
Success = True
Return New CallResult With {.Data = Json_.Serialize(jData("data")), .ErrorMSG = "", .Success = Success}
End If
Catch ex As Exception
Return New CallResult With {.Data = "", .ErrorMSG = ex.Message.ToString, .Success = False}
End Try
Return New CallResult With {.Data = "", .ErrorMSG = ErrMSG, .Success = False}
End Function









share|improve this question





























    0














    I can sign every single private call to the API but the buy/sell order. It is the only call with a JSON request. All other calls are form URL encoded. It always return "signature error" or "cannot serialize to JSON".



    Balances information end point "/balance/info"



    Place order end point"/order/limit"



    ref: CoinEx API doc



    API Key: 09D8485F15B145F5B48D79B8E0FF4C8D



    API Secret: 2F27E476B09140AA8E0B0F80CA4832A5F014A895E28BF8A1



    There is no cryptocurrencies on the account so please use my key. I will erase it after but the key/secret is valid



     Private CoinEXAPIurl As String = "https://api.coinex.com/v1"

    Private Function PrivateApiAsync(ByVal requestEndPoint As String, ByVal RequestType As HttpMethod, ByVal Params As Dictionary(Of String, String), Optional ByVal IncludeST As Boolean = True) As CallResult
    Dim ErrMSG As String = "Unknown Error"
    Try
    Dim xhttp As New HttpClient()
    Dim request As New HttpRequestMessage
    Dim sign As String = ""
    Dim Parameters As String = ""
    Dim tonce = Int(DateTime.Now.ToUniversalTime.Subtract(New DateTime(1970, 1, 1)).TotalMilliseconds)
    Dim newparam As New Dictionary(Of String, String)
    newparam.Add("access_id", _Credentials.APIKey)
    For Each entry In Params
    newparam.Add(entry.Key, entry.Value)
    Next
    newparam.Add("tonce", tonce)

    Dim FormURLEncodedSTR = New FormUrlEncodedContent(newparam).ReadAsStringAsync.Result
    sign = GetHash(FormURLEncodedSTR & "&" & "secret_key=" & _Credentials.APISecret)

    With request
    .Headers.Add("authorization", sign)
    .Headers.UserAgent.ParseAdd("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36")
    .Method = RequestType
    If RequestType = HttpMethod.Post Then
    .RequestUri = New Uri(CoinEXAPIurl & requestEndPoint)
    .Content = New StringContent(Json_.Serialize(newparam), Encoding.UTF8, "application/json")
    Else
    .RequestUri = New Uri(CoinEXAPIurl & requestEndPoint & "?" & FormURLEncodedSTR)
    End If
    End With

    Dim result = xhttp.SendAsync(request).Result
    Dim xcontent = result.Content.ReadAsStringAsync.Result
    Dim jData = Json_.DeserializeObject(xcontent)
    Dim Success As Boolean = False
    If jData("code") <> 0 Then
    ErrMSG = jData("message")
    Else
    Success = True
    Return New CallResult With {.Data = Json_.Serialize(jData("data")), .ErrorMSG = "", .Success = Success}
    End If
    Catch ex As Exception
    Return New CallResult With {.Data = "", .ErrorMSG = ex.Message.ToString, .Success = False}
    End Try
    Return New CallResult With {.Data = "", .ErrorMSG = ErrMSG, .Success = False}
    End Function









    share|improve this question



























      0












      0








      0







      I can sign every single private call to the API but the buy/sell order. It is the only call with a JSON request. All other calls are form URL encoded. It always return "signature error" or "cannot serialize to JSON".



      Balances information end point "/balance/info"



      Place order end point"/order/limit"



      ref: CoinEx API doc



      API Key: 09D8485F15B145F5B48D79B8E0FF4C8D



      API Secret: 2F27E476B09140AA8E0B0F80CA4832A5F014A895E28BF8A1



      There is no cryptocurrencies on the account so please use my key. I will erase it after but the key/secret is valid



       Private CoinEXAPIurl As String = "https://api.coinex.com/v1"

      Private Function PrivateApiAsync(ByVal requestEndPoint As String, ByVal RequestType As HttpMethod, ByVal Params As Dictionary(Of String, String), Optional ByVal IncludeST As Boolean = True) As CallResult
      Dim ErrMSG As String = "Unknown Error"
      Try
      Dim xhttp As New HttpClient()
      Dim request As New HttpRequestMessage
      Dim sign As String = ""
      Dim Parameters As String = ""
      Dim tonce = Int(DateTime.Now.ToUniversalTime.Subtract(New DateTime(1970, 1, 1)).TotalMilliseconds)
      Dim newparam As New Dictionary(Of String, String)
      newparam.Add("access_id", _Credentials.APIKey)
      For Each entry In Params
      newparam.Add(entry.Key, entry.Value)
      Next
      newparam.Add("tonce", tonce)

      Dim FormURLEncodedSTR = New FormUrlEncodedContent(newparam).ReadAsStringAsync.Result
      sign = GetHash(FormURLEncodedSTR & "&" & "secret_key=" & _Credentials.APISecret)

      With request
      .Headers.Add("authorization", sign)
      .Headers.UserAgent.ParseAdd("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36")
      .Method = RequestType
      If RequestType = HttpMethod.Post Then
      .RequestUri = New Uri(CoinEXAPIurl & requestEndPoint)
      .Content = New StringContent(Json_.Serialize(newparam), Encoding.UTF8, "application/json")
      Else
      .RequestUri = New Uri(CoinEXAPIurl & requestEndPoint & "?" & FormURLEncodedSTR)
      End If
      End With

      Dim result = xhttp.SendAsync(request).Result
      Dim xcontent = result.Content.ReadAsStringAsync.Result
      Dim jData = Json_.DeserializeObject(xcontent)
      Dim Success As Boolean = False
      If jData("code") <> 0 Then
      ErrMSG = jData("message")
      Else
      Success = True
      Return New CallResult With {.Data = Json_.Serialize(jData("data")), .ErrorMSG = "", .Success = Success}
      End If
      Catch ex As Exception
      Return New CallResult With {.Data = "", .ErrorMSG = ex.Message.ToString, .Success = False}
      End Try
      Return New CallResult With {.Data = "", .ErrorMSG = ErrMSG, .Success = False}
      End Function









      share|improve this question















      I can sign every single private call to the API but the buy/sell order. It is the only call with a JSON request. All other calls are form URL encoded. It always return "signature error" or "cannot serialize to JSON".



      Balances information end point "/balance/info"



      Place order end point"/order/limit"



      ref: CoinEx API doc



      API Key: 09D8485F15B145F5B48D79B8E0FF4C8D



      API Secret: 2F27E476B09140AA8E0B0F80CA4832A5F014A895E28BF8A1



      There is no cryptocurrencies on the account so please use my key. I will erase it after but the key/secret is valid



       Private CoinEXAPIurl As String = "https://api.coinex.com/v1"

      Private Function PrivateApiAsync(ByVal requestEndPoint As String, ByVal RequestType As HttpMethod, ByVal Params As Dictionary(Of String, String), Optional ByVal IncludeST As Boolean = True) As CallResult
      Dim ErrMSG As String = "Unknown Error"
      Try
      Dim xhttp As New HttpClient()
      Dim request As New HttpRequestMessage
      Dim sign As String = ""
      Dim Parameters As String = ""
      Dim tonce = Int(DateTime.Now.ToUniversalTime.Subtract(New DateTime(1970, 1, 1)).TotalMilliseconds)
      Dim newparam As New Dictionary(Of String, String)
      newparam.Add("access_id", _Credentials.APIKey)
      For Each entry In Params
      newparam.Add(entry.Key, entry.Value)
      Next
      newparam.Add("tonce", tonce)

      Dim FormURLEncodedSTR = New FormUrlEncodedContent(newparam).ReadAsStringAsync.Result
      sign = GetHash(FormURLEncodedSTR & "&" & "secret_key=" & _Credentials.APISecret)

      With request
      .Headers.Add("authorization", sign)
      .Headers.UserAgent.ParseAdd("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36")
      .Method = RequestType
      If RequestType = HttpMethod.Post Then
      .RequestUri = New Uri(CoinEXAPIurl & requestEndPoint)
      .Content = New StringContent(Json_.Serialize(newparam), Encoding.UTF8, "application/json")
      Else
      .RequestUri = New Uri(CoinEXAPIurl & requestEndPoint & "?" & FormURLEncodedSTR)
      End If
      End With

      Dim result = xhttp.SendAsync(request).Result
      Dim xcontent = result.Content.ReadAsStringAsync.Result
      Dim jData = Json_.DeserializeObject(xcontent)
      Dim Success As Boolean = False
      If jData("code") <> 0 Then
      ErrMSG = jData("message")
      Else
      Success = True
      Return New CallResult With {.Data = Json_.Serialize(jData("data")), .ErrorMSG = "", .Success = Success}
      End If
      Catch ex As Exception
      Return New CallResult With {.Data = "", .ErrorMSG = ex.Message.ToString, .Success = False}
      End Try
      Return New CallResult With {.Data = "", .ErrorMSG = ErrMSG, .Success = False}
      End Function






      vb.net rest md5 dotnet-httpclient






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 28 '18 at 0:16

























      asked Dec 28 '18 at 0:10









      overflow

      13




      13
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53952250%2fhow-to-sign-a-post-request-with-coinex-api%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53952250%2fhow-to-sign-a-post-request-with-coinex-api%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Mossoró

          Error while reading .h5 file using the rhdf5 package in R

          Pushsharp Apns notification error: 'InvalidToken'