@@ -54,13 +54,16 @@ bool BinanceJSONParser::GetTokensFromJSON(
54
54
// "free": "0.00000000",
55
55
// "locked": "0.00000000",
56
56
// "freeze": "1.00000000",
57
- // "withdrawing": "0.00000000"
57
+ // "withdrawing": "0.00000000",
58
+ // "btcValuation": "0.00000000",
59
+ // "fiatValuation": "0.00000000"
58
60
// }
59
61
// ]
60
62
// }
61
63
//
62
64
bool BinanceJSONParser::GetAccountBalancesFromJSON (
63
- const std::string& json, std::map<std::string, std::string>* balances) {
65
+ const std::string& json,
66
+ std::map<std::string, std::vector<std::string>>* balances) {
64
67
if (!balances) {
65
68
return false ;
66
69
}
@@ -76,18 +79,31 @@ bool BinanceJSONParser::GetAccountBalancesFromJSON(
76
79
}
77
80
78
81
const base::Value* pv_arr = records_v->FindKey (" data" );
79
- if (pv_arr && pv_arr->is_list ()) {
80
- for (const base::Value &val : pv_arr->GetList ()) {
81
- const base::Value* asset = val.FindKey (" asset" );
82
- const base::Value* free_amount = val.FindKey (" free" );
83
- const base::Value* locked_amount = val.FindKey (" locked" );
84
- if (asset && asset->is_string () &&
85
- free_amount && free_amount->is_string () &&
86
- locked_amount && locked_amount->is_string ()) {
87
- const std::string asset_symbol = asset->GetString ();
88
- balances->insert ({asset_symbol, free_amount->GetString ()});
89
- }
82
+ if (!pv_arr || !pv_arr->is_list ()) {
83
+ return false ;
84
+ }
85
+
86
+ for (const base::Value &val : pv_arr->GetList ()) {
87
+ const base::Value* asset = val.FindKey (" asset" );
88
+ const base::Value* free_amount = val.FindKey (" free" );
89
+ const base::Value* btc_val = val.FindKey (" btcValuation" );
90
+ const base::Value* fiat_val = val.FindKey (" fiatValuation" );
91
+
92
+ bool has_asset = asset && asset->is_string ();
93
+ bool has_free = free_amount && free_amount->is_string ();
94
+ bool has_btc_val = btc_val && btc_val->is_string ();
95
+ bool has_fiat_val = fiat_val && fiat_val->is_string ();
96
+
97
+ if (!has_asset || !has_free || !has_btc_val || !has_fiat_val) {
98
+ continue ;
90
99
}
100
+
101
+ std::vector<std::string> balance_data;
102
+ balance_data.push_back (free_amount->GetString ());
103
+ balance_data.push_back (btc_val->GetString ());
104
+ balance_data.push_back (fiat_val->GetString ());
105
+
106
+ balances->insert ({asset->GetString (), balance_data});
91
107
}
92
108
93
109
return true ;
@@ -146,62 +162,6 @@ bool BinanceJSONParser::GetQuoteInfoFromJSON(
146
162
return true ;
147
163
}
148
164
149
- // static
150
- // Response format:
151
- // {
152
- // "symbol": "BTCUSDT",
153
- // "price":"7265.82000000"
154
- // }
155
- //
156
- bool BinanceJSONParser::GetTickerPriceFromJSON (
157
- const std::string& json, std::string* symbol_pair_price) {
158
- DCHECK (symbol_pair_price);
159
- base::JSONReader::ValueWithError value_with_error =
160
- base::JSONReader::ReadAndReturnValueWithError (
161
- json, base::JSONParserOptions::JSON_PARSE_RFC);
162
- base::Optional<base::Value>& parsed_response = value_with_error.value ;
163
- if (!parsed_response) {
164
- LOG (ERROR) << " Invalid response, could not parse JSON, JSON is: " << json;
165
- return false ;
166
- }
167
-
168
- const base::Value* price = parsed_response->FindKey (" price" );
169
- if (!price || !price->is_string ()) {
170
- return false ;
171
- }
172
-
173
- *symbol_pair_price = price->GetString ();
174
- return true ;
175
- }
176
-
177
- // static
178
- // Response Format:
179
- // {
180
- // "symbol":"BTCUSDT",
181
- // "volume":"1337"
182
- // }
183
- bool BinanceJSONParser::GetTickerVolumeFromJSON (
184
- const std::string& json, std::string* symbol_pair_volume) {
185
- DCHECK (symbol_pair_volume);
186
-
187
- base::JSONReader::ValueWithError value_with_error =
188
- base::JSONReader::ReadAndReturnValueWithError (
189
- json, base::JSONParserOptions::JSON_PARSE_RFC);
190
- base::Optional<base::Value>& parsed_response = value_with_error.value ;
191
- if (!parsed_response) {
192
- LOG (ERROR) << " Invalid response, could not parse JSON, JSON is: " << json;
193
- return false ;
194
- }
195
-
196
- const base::Value* volume = parsed_response->FindKey (" volume" );
197
- if (!volume || !volume->is_string ()) {
198
- return false ;
199
- }
200
-
201
- *symbol_pair_volume = volume->GetString ();
202
- return true ;
203
- }
204
-
205
165
// static
206
166
// Response Format:
207
167
// {
0 commit comments