You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VB.NET实现Bittrex API遭遇NONCE_NOT_PROVIDED错误求助

Fixing Bittrex API "NONCE_NOT_PROVIDED" Error in VB.NET

Let's break down why you're hitting the NONCE_NOT_PROVIDED error and fix your code step by step:

Key Issues in Your Current Code

  • Invalid Nonce Format: You're using DateTime.Now.ToString() which produces a human-readable date string (like "10/05/2024 14:30:00"), but Bittrex expects a Unix timestamp (integer representing seconds since January 1, 1970 UTC).
  • Incorrect URL Parameter Splicing: You appended the nonce directly to the API URL without using the required &nonce= query parameter syntax, so Bittrex can't detect the nonce value at all.
  • Header Format Misstep: Adding the apisign header as a full string ("apisign:" + sign) might not be parsed correctly by WebRequest; it's cleaner and more reliable to use the key-value pair syntax for headers.

Corrected VB.NET Implementation

First, add helper methods to generate a valid Unix timestamp and compute the HMAC-SHA512 signature properly:

Imports System.Security.Cryptography
Imports System.Text

Module BittrexApiHelper
    ' Generate Unix timestamp (seconds since 1970-01-01 UTC)
    Function GetUnixTimestamp() As Long
        Dim epoch As New DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)
        Return CLng((DateTime.UtcNow - epoch).TotalSeconds)
    End Function

    ' Compute HMAC-SHA512 signature matching Bittrex's requirements
    Function ComputeHmacSha512(input As String, secret As String) As String
        Using hmac As New HMACSHA512(Encoding.UTF8.GetBytes(secret))
            Dim hashBytes As Byte() = hmac.ComputeHash(Encoding.UTF8.GetBytes(input))
            Return BitConverter.ToString(hashBytes).Replace("-", "").ToLowerInvariant()
        End Using
    End Function
End Module

Then update your main API request code with the fixes:

Dim apiKey As String = "YOUR_ACTUAL_API_KEY"
Dim apiSecret As String = "YOUR_ACTUAL_API_SECRET"
Dim nonce As Long = GetUnixTimestamp()

' Build the full API URL with both apikey and nonce as proper query parameters
Dim apiUrl As String = $"https://bittrex.com/api/v1.1/account/getbalances?apikey={apiKey}&nonce={nonce}"

' Compute the signature using the full URL (exactly as Bittrex's PHP example specifies)
Dim sign As String = ComputeHmacSha512(apiUrl, apiSecret)

' Create and configure the web request
Dim request As WebRequest = WebRequest.Create(apiUrl)
request.Method = "GET"
' Add the apisign header using key-value syntax for proper parsing
request.Headers.Add("apisign", sign)

' Handle the response safely
Try
    Using response As WebResponse = request.GetResponse()
        Using reader As New System.IO.StreamReader(response.GetResponseStream())
            Dim responseJson As String = reader.ReadToEnd()
            ' Parse and use the JSON response as needed
            Console.WriteLine(responseJson)
        End Using
    End Using
Catch ex As Exception
    Console.WriteLine($"Request failed: {ex.Message}")
End Try

Additional Notes

  • Nonce Enforcement: Even though Bittrex mentions nonce is "not mandatory yet", their API clearly enforces it for authenticated endpoints now—always include a valid, incrementing Unix timestamp.
  • Signature Accuracy: The signature must be computed using the full API URL (including all query parameters) as the input string, just like the official PHP example demonstrates.
  • Deprecation Reminder: The old endpoint format (https://bittrex.com/api/v1.1/account/getbalances?apikey=apikey) is deprecated, so stick to the format with both apikey and nonce parameters.

内容的提问来源于stack exchange,提问作者Amit kumar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:36:01