40 lines
1.0 KiB
C++
40 lines
1.0 KiB
C++
#ifndef _WIN32
|
|
#include "Product.h"
|
|
|
|
#include <boost/tokenizer.hpp>
|
|
#include <vector>
|
|
|
|
namespace bts {
|
|
namespace api {
|
|
std::string product_to_string(const api::Product &p) {
|
|
std::string buffer = p.symbol();
|
|
buffer += ":";
|
|
buffer += SecurityType_Name(p.type());
|
|
buffer += ":";
|
|
buffer += Venue_Name(p.exchange());
|
|
return buffer;
|
|
}
|
|
std::optional<api::Product> string_to_product(const std::string &s) {
|
|
boost::tokenizer<boost::char_separator<char>> tok{s};
|
|
std::vector<std::string> parts;
|
|
for (const auto &t : tok) {
|
|
parts.push_back(t);
|
|
}
|
|
if (parts.size() != 3)
|
|
return std::nullopt;
|
|
SecurityType type = SecurityType::SECURITYTYPE_UNSET;
|
|
if (!SecurityType_Parse(parts[1], &type))
|
|
return std::nullopt;
|
|
Venue v = Venue::VENUE_UNSET;
|
|
if (!Venue_Parse(parts[2], &v))
|
|
return std::nullopt;
|
|
Product p;
|
|
p.set_symbol(parts[0]);
|
|
p.set_type(type);
|
|
p.set_exchange(v);
|
|
return {p};
|
|
}
|
|
|
|
} // namespace api
|
|
} // namespace bts
|
|
#endif |