C# Bitz exchange tradeAdd方法中缺少参数

C# Bitz exchange tradeAdd方法中缺少参数,c#,api,bitcoin,cryptocurrency,C#,Api,Bitcoin,Cryptocurrency,我一直在从事一个加密项目,我一直在致力于将bitz集成到该项目中。我的公用电话工作正常,但当涉及到私人电话时,我得到了以下回应: {"code":100,"msg":"The required parameter cannot be empty","data":null} 我不确定我缺少了什么参数,因为通过查看api文档,我拥有调用所需的所有参数(api文档:) 这是我的主要代码: using bit_z; using System; using System.Collections.Gene

我一直在从事一个加密项目,我一直在致力于将bitz集成到该项目中。我的公用电话工作正常,但当涉及到私人电话时,我得到了以下回应:

{"code":100,"msg":"The required parameter cannot be empty","data":null}
我不确定我缺少了什么参数,因为通过查看api文档,我拥有调用所需的所有参数(api文档:)

这是我的主要代码:

using bit_z;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace test
{
class Program
{
    public static void Main(string[] args)
    {

        bit_z_core core = new bit_z_core("api_key", "api_secret");
        WebFuncs weber = new WebFuncs();
        tickerBase b = core.getTicker("eth_btc");

        string sell = b._dat.sell;


        //core.AddTrade("out", sell, "1", "eth_btc", "sdf");

        Dictionary<string, string> data = new Dictionary<string, string>();

        //tradeAdd
        string payload_tradeAdd = bit_z.WebFuncs.Sign("api_key", "api_secret", new Dictionary<string, string>{
            { "price", sell},
            { "number", "0.876"},
            { "coin", "eth_btc"},
            { "tradepwd", "super-secret"},
            { "type" , "in" }
        });

        string info = bit_z.WebFuncs.callPrivateAPI(payload_tradeAdd).Result;
        Console.WriteLine(info); //here it responses with: {"code":100,"msg":"The required parameter cannot be empty","data":null}
        Console.ReadLine();


    }

    private static void TestSign(string expected, Dictionary<string, string> data)
    {
        string payload = bit_z.WebFuncs.Sign("KEY", "SECRET", data, "1532127208", "100000");
        if (expected == payload)
        {
            Console.WriteLine("OK");
        }
        else
        {
            Console.WriteLine("Invalid payload. Expected {0}. Got {1}.", expected, payload);
        }
    }
}
}
使用bit_z;
使用制度;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
名称空间测试
{
班级计划
{
公共静态void Main(字符串[]args)
{
bit_z_core=新的bit_z_core(“api_密钥”、“api_秘密”);
WebFuncs weber=新的WebFuncs();
tickerBase b=core.getTicker(“eth_btc”);
字符串sell=b._dat.sell;
//core.AddTrade(“出售”、“出售”、“1”、“eth_btc”、“sdf”);
字典数据=新字典();
//贸易附加
string payload\u tradeAdd=bit\u z.WebFuncs.Sign(“api\u密钥”、“api\u秘密”),新字典{
{“价格”,出售},
{“数字”,“0.876”},
{“coin”,“eth_btc”},
{“贸易”、“超级秘密”},
{“type”,“in”}
});
string info=bit_z.WebFuncs.callPrivateAPI(payload_tradeAdd).Result;
Console.WriteLine(info);//在这里,它的响应是:{“code”:100,“msg”:“所需参数不能为空”,“data”:null}
Console.ReadLine();
}
私有静态void TestSign(需要字符串,字典数据)
{
字符串有效载荷=bit_z.WebFuncs.Sign(“KEY”,“SECRET”,data,“1532127208”,“100000”);
如果(预期==有效负载)
{
控制台。写入线(“OK”);
}
其他的
{
WriteLine(“无效的有效负载。应为{0}。应为{1}.”,应为有效负载);
}
}
}
}
以及执行bitz调用的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace bit_z
{
public class WebFuncs
{


    private static RNGCryptoServiceProvider rngCsp = new RNGCryptoServiceProvider();

    private string url = "https://api.bit-z.com/api_v1";
    public string getHTML(string url_endpoint)
    {
        try
        {
            WebClient client = new WebClient();
            string inf = client.DownloadString(url + url_endpoint);
            return inf;
        }
        catch (Exception i)
        {
            return null;
        }
    }

    public static async Task<string> callPrivateAPI(string payload)
    {
        string requestUri = "https://api.bit-z.com/api_v1";

        try
        {

            var request = new HttpRequestMessage();
            request.Method = HttpMethod.Post;
            string final = requestUri + "/tradeAdd?" + payload;
            request.RequestUri = new Uri(final);
            //string info = client.DownloadString(final);
            //Console.WriteLine(info);
            //request.Headers.Add("sign", encoded);
            //request.Content = new ObjectContent(typeof(object), postData, new JsonMediaTypeFormatter());

           using (var client = new HttpClient())
            {

                var response = client.SendAsync(request).Result;
                if (response.IsSuccessStatusCode)
                {
                    string r = await response.Content.ReadAsStringAsync();
                    //{"Success":true,"Error":null,"Data":[{"CurrencyId":2,"Symbol":"DOT","Total":9646.07411016,"Available":9646.07411016,"Unconfirmed":0.0,"HeldForTrades":0.0,"PendingWithdraw":0.0,"Address":"1HEfio1kreDBgj5uCw4VHbEDSgc6YJXfTN","Status":"OK","StatusMessage":null}]}
                    return r;
                }
            }
        }
        catch (Exception ii)
        {
            return null;
        }
        return null;



    }

    // Sign creates a signed payload with the given API key and secret
    public static string Sign(string key, string secret, Dictionary<string, string> data = null, string timestamp = null, string nonce = null)
    {
        if (timestamp == null)
        {
            timestamp = GetTimestamp();
        }
        if (nonce == null)
        {
            nonce = GetNonce();
        }

        if (data == null)
        {
            data = new Dictionary<string, string>();
        }

        // Convert the data to a SortedDictionary
        SortedDictionary<string, string> sortedData = new SortedDictionary<string, string>(data);

        // Add the common key-value pairs
        sortedData["api_key"] = key;
        sortedData["nonce"] = nonce;
        sortedData["timestamp"] = timestamp;

        // Construct the body as key-value pairs, sorting by key
        var pairs = new List<string>();
        foreach (var kv in sortedData)
        {
            pairs.Add(kv.Key + "=" + kv.Value);
        }
        var body = String.Join("&", pairs);

        // Append the signature
        var signature = GetMD5(body + secret);
        body += "&sign=" + signature;

        return body;
    }


    // Timestamp returns the time in unix seconds as a string
    private static string GetTimestamp()
    {
        return DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString();
    }

    // Nonce returns a 6-character nonce to use for API requests
    private static string GetNonce()
    {
        return RandomInt32(100000, 999999).ToString();
    }

    private static Int32 RandomInt32(Int32 minValue, Int32 maxValue)
    {
        if (minValue > maxValue)
        {
            throw new ArgumentOutOfRangeException(nameof(minValue));
        }
        if (minValue == maxValue) return minValue;

        Int64 diff = maxValue - minValue;
        byte[] buffer = new byte[8];

        while (true)
        {
            rngCsp.GetBytes(buffer);
            UInt32 rand = BitConverter.ToUInt32(buffer, 0);

            Int64 max = (1 + (Int64)UInt32.MaxValue);
            Int64 remainder = max % diff;
            if (rand < max - remainder)
            {
                return (Int32)(minValue + (rand % diff));
            }
        }
    }

    private static string GetMD5(string input)
    {
        // Use input string to calculate MD5 hash
        using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create())
        {
            byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
            byte[] hashBytes = md5.ComputeHash(inputBytes);

            // Convert the byte array to hexadecimal string
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < hashBytes.Length; i++)
            {
                sb.Append(hashBytes[i].ToString("X2"));
            }
            return sb.ToString().ToLower();
        }
    }

}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
Net系统;
使用System.Net.Http;
使用System.Net.Http.Header;
使用System.Security.Cryptography;
使用系统文本;
使用System.Threading.Tasks;
名称空间位
{
公共类WebFuncs
{
私有静态RNGCryptoServiceProvider rngCsp=新的RNGCryptoServiceProvider();
专用字符串url=”https://api.bit-z.com/api_v1";
公共字符串getHTML(字符串url\U端点)
{
尝试
{
WebClient客户端=新的WebClient();
string inf=client.DownloadString(url+url\U端点);
返回inf;
}
捕获(例外情况一)
{
返回null;
}
}
公共静态异步任务callPrivateAPI(字符串负载)
{
字符串requestUri=”https://api.bit-z.com/api_v1";
尝试
{
var request=new-HttpRequestMessage();
request.Method=HttpMethod.Post;
字符串final=requestUri+“/tradeAdd?”+有效负载;
request.RequestUri=新Uri(最终);
//string info=client.DownloadString(最终版);
//控制台写入线(信息);
//添加(“签名”,编码);
//request.Content=newobjectcontent(typeof(object)、postData、newjsonmediatypeformatter());
使用(var client=new HttpClient())
{
var response=client.sendaync(request.Result);
if(响应。IsSuccessStatusCode)
{
字符串r=wait response.Content.ReadAsStringAsync();
//{“成功”:true,“错误”:null,“数据”:[{“CurrencyId”:2,“符号”:“点”,“总计”:9646.07411016,“可用”:9646.07411016,“未确认”:0.0,“HeldForTrades”:0.0,“挂起撤回”:0.0,“地址”:“1Hefio1kredbgJ5UCW4VHbedGC6YJxftn”,“状态”:“确定”,“状态消息”:null}]
返回r;
}
}
}
捕获(例外二)
{
返回null;
}
返回null;
}
//Sign使用给定的API密钥和密码创建已签名的有效负载
公共静态字符串符号(字符串密钥、字符串机密、字典数据=null、字符串时间戳=null、字符串nonce=null)
{
if(时间戳==null)
{
timestamp=GetTimestamp();
}
if(nonce==null)
{
nonce=GetNonce();
}
如果(数据==null)
{
数据=新字典();
}
//将数据转换为SortedDictionary
SortedDictionary sortedData=新的SortedDictionary(数据);
//添加公共键值对
sortedData[“api_键”]=键;
sortedData[“nonce”]=nonce;
sortedData[“时间戳”]=时间戳;
//将主体构造为键值对,按键排序
var pairs=新列表();
foreach(额定电压千伏,以达塔为单位)
{
对。添加(千伏键+“=”+千伏值);
}
var body=String.Join(“&”,成对);
//附加签名
var签名=GetMD5(body+secret);
body+=”&sign=“+签名;
返回体;
}
//Timestamp以字符串形式返回时间(以unix秒为单位)
私有静态字符串GetTimestamp()
{
return DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString();
}
//Nonce返回用于API请求的6个字符的Nonce
私有静态字符串GetNonce()
{
返回RandomInt32(100000,999999).ToString();
}
私有静态Int32 RandomInt32(Int32最小值,Int32最大值)
{
如果(最小值>最大值)
{
抛出新ArgumentOutOfRangeException(nameof(minValue));
}
如果(minValue==maxValue)返回minValue;
Int64 diff=最大值-最小值;
字节[]缓冲区=新字节[8];
while(true)
{
rngCsp.GetBytes(缓冲区);
UInt32 rand=BitConverter.ToUInt32(缓冲区,0);
Int64 max=(1+(Int64)UInt32.MaxValue);