专栏名称: 申龙斌的程序人生
分享可繁殖的知识与技能:GTD时间管理、读书心得、个人成长、财富自由之路
目录
相关文章推荐
程序员的那些事  ·  刚刚!DeepSeek 杀入全球榜单第 2 ... ·  3 天前  
OSC开源社区  ·  go-zero突破三万星——star数量最高 ... ·  5 天前  
OSC开源社区  ·  听说技术大V们都被"manus"喂饱了,求邀 ... ·  4 天前  
51好读  ›  专栏  ›  申龙斌的程序人生

访问Bigone API获取数字资产的余额

申龙斌的程序人生  · 公众号  · 程序员  · 2018-06-27 22:18

正文

昨天写了一篇文章《 Bigone API 升级到v2,害死程序员 》,有人反映API文档无法打开,请 自备梯子 访问https://open.big.one。


文档中明确规定了API的访问限制:

  • 针对每个独立IP访问限额为: 每5秒钟/500次请求。

  • 针对每个用户账号访问限额为:每小时/2000次请求。

  • 如果要玩量化交易,还可以联系客服进行配额的调整。


昨天的例子中的Ping是公开访问的API,即不需要API token即可访问,而更多的涉及到账户查询、订单查询等操作是私有API,需要用到上一篇文章中提到的Header来访问API网址。


对于C#获取https URL的返回内容,可以参考以下代码:

public static string GetUrl(string url, string[] headers = null)

{

ServicePointManager.Expect100Continue = true;

// 如果考虑兼容性,用SecurityProtocolType.Ssl3

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;


HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;

request.UserAgent = DEFAULT_USER_AGENT;

request.Method = "GET";

request.KeepAlive = false;


if (headers != null) {

foreach (string h in headers) {

request.Headers.Add(h);

}

}


using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) {

using (System.IO.StreamReader reader = new System.IO.StreamReader(response.GetResponseStream(), Encoding.UTF8)) {

string srcString = reader.ReadToEnd();

return srcString;

}

}

}


访问一个bigone账户的余额的API为:

https://b1.run/api/v2/viewer/accounts


如果一切正常,则返回类似的内容:

"locked_balance":"0.111",

"balance":"0.765",

"asset_uuid":"c98f5d90-c619-4de2-b643-3d429f622239",

"asset_id":"ETH"


取出所有数字资产的代码就非常容易了,写一个Asset类,再加一段代码:

public static Dictionary ParseBigoneAssetJson(string json)

{

Dictionary dict = new Dictionary ();

var root = JObject.Parse(json);

JArray data = root["data"] as JArray;

foreach (JToken token in data)

{

Asset a = new Asset();

a.ID = token["asset_id"].ToString();

a.LockedBalance = double.Parse(token["locked_balance"].ToString());

a.Balance = double.Parse(token["balance"].ToString());

if (a.Balance > 0.001)

dict.Add(a.ID, a);

}

return dict;

}


币价跌得太难看,我就不贴出我的bigone余额啦。


点击文末的广告,我会收到5毛钱,

用于支付北京呼家楼6800元的房租,谢谢!


--- END ---


近期文章:







请到「今天看啥」查看全文