-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathIndodaxDataParser.cpp
More file actions
44 lines (37 loc) · 1.27 KB
/
IndodaxDataParser.cpp
File metadata and controls
44 lines (37 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "IndodaxDataParser.h"
IndodaxDataParser::IndodaxDataParser()
:doc(512)
{
}
bool IndodaxDataParser::parseData(std::string body, float& out)
{
int startIndex = body.find_first_of('{');
int endIndex = body.find_last_of('}');
std::string data = body.substr(startIndex,endIndex+1);
//Serial.print("indodax parsing data: ");
//Serial.println(data);
this->doc.clear();
DeserializationError parseResult = deserializeJson(this->doc,data);
if( parseResult != DeserializationError::Ok){
Serial.println("! parse json doc failed");
Serial.println(parseResult.c_str());
return false;
}
else{
JsonObject root = this->doc.as<JsonObject>();
JsonVariant ticker = root["ticker"];
if(!ticker.isNull()){
JsonObject tickerObj = ticker.as<JsonObject>();
out = tickerObj["last"].as<float>()/1000000.0f;
// out.closePrice = tickerObj["last"].as<float>()/1000000.0f;
// out.highPrice = tickerObj["high"].as<float>()/1000000.0f;
// out.lowPrice = tickerObj["low"].as<float>()/1000000.0f;
// out.timestamp = tickerObj["server_time"].as<uint32_t>();
return true;
}
else{
Serial.println("! parse json root failed");
return false;
}
}
}