解决JSON.stringify 丢undefined 的问题
JSON.stringify(obj, (key, value) => {
if (value === undefined) {
return null
}
return value
})
hotconi 采用 wss和rpc方式通信,经过采样发现,使用protobufjs可以解开
wss通信后,使用proto对象镜像接收数据。
proto对象已经被编译混淆,无法还原,但是可以通过返回值猜测结构和排序。
以market.v2.trade.area.tickers 为例
{
"code": 200,
"msg": "SUCCESS",
"status": "ok",
"ts": 1732365915001,
"ch": "market.v2.trade.area.tickers",
"klinelist": null,
"tradedepthvo": null,
"tradedetaillist": null,
"tradeareapair": {
"listList": [
{
"tradeid": 1900573,
"cny": "0.000499",
"buy": "0.00006590000000000000",
"lever": "0",
"sell": "0.00006899000000000000",
"last": "0.00006899000000000000",
"volume": "4612936154.8542",
"change": "0.96",
"high": "0.00007299000000000000",
"low": "0.00006451000000000000",
"isopen": "1",
"open": "0",
"amount": "307750.69",
"isfiatconvert": true
}
]
},
"mainpair": null,
"recommendpair": null,
"uppair": null,
"amtpair": null,
"starpair": null,
"tradetickervo": null,
"entrustvo": null,
"userassetbalance": null,
"markettickerlist": null,
"marketmonit": null,
"margincrossassetvo": null,
"marginisolatedassetvo": null,
"newlistingpair": null,
"chgdistributions": null,
"marketzones": null,
"klineorders": null,
"notificationpush": null,
"tradehotlisting": null,
"ctcgoingordernum": null,
"multichange": null,
"heatmap": null,
"downpair": null,
"heatvol": null,
"currencyrate": null
}
syntax = "proto3";
package market.v2.trade; // 替换为你的包名
// 定义最外层的消息类型
message Response {
int32 code = 1; //数字代表 字段的编号顺序。
string msg = 2;
string status = 3;
int64 ts = 4;
string ch = 5;
TradeAreaPair tradeareapair = 25;
}
// 定义tradeareapair中的消息类型
message TradeAreaPair {
repeated TradeArea listList = 1; // 由于JSON中的listList实际上是一个列表,我们使用repeated关键字
}
// 定义tradeid_list中的消息类型
message TradeArea {
int32 tradeid = 1;
string cny = 2;
string buy = 3;
int32 lever = 4;
string sell = 5;
string last = 6;
string volume = 7;
string change = 8;
string high = 9;
string low = 10;
string isopen = 11;
int32 open = 12;
string amount = 13;
bool isfiatconvert = 14;
}
【重点】 如果网页抓包的某项有值,但是接收到的没有值,需要调整每一个字段的编号。 上面是一个包的方式,其他所有接口都类似抓取,然后 规范的添加到 market.v2.trade.proto