86 lines
2.4 KiB
C++
86 lines
2.4 KiB
C++
#pragma once
|
|
|
|
#include "common.h"
|
|
#include "lib/core/FMT_IMPL.h"
|
|
|
|
#include <string>
|
|
|
|
namespace bts {
|
|
namespace md {
|
|
|
|
// Combines a symbol, exchange and type has utilities like comparisons, streams
|
|
// etc around it
|
|
|
|
struct UserSymbol {
|
|
UserSymbol() = default;
|
|
|
|
UserSymbol(const std::string &s, api::Venue e, SecurityType t)
|
|
: _symbol(s), _exchange(e), _type(t) {}
|
|
|
|
UserSymbol(const UserSymbol &other) = default;
|
|
UserSymbol &operator=(const UserSymbol &other) = default;
|
|
UserSymbol &operator=(UserSymbol &&other) = default;
|
|
|
|
const std::string &symbol() const { return _symbol; }
|
|
api::Venue exchange() const { return _exchange; }
|
|
SecurityType type() const { return _type; }
|
|
bool operator==(const UserSymbol &other) const {
|
|
return _type == other.type() && _exchange == other.exchange() &&
|
|
_symbol == other.symbol();
|
|
}
|
|
bool operator<(const UserSymbol &other) const {
|
|
if (_type < other.type()) {
|
|
return true;
|
|
} else {
|
|
if (_type == other.type()) {
|
|
if (_exchange < other.exchange()) {
|
|
return true;
|
|
} else {
|
|
if (_exchange == other.exchange()) {
|
|
return _symbol < other.symbol();
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
std::string to_string() const {
|
|
return symbol() + "-" + SecurityType_Name(type());
|
|
}
|
|
|
|
bts::api::Product to_product() const {
|
|
bts::api::Product p;
|
|
p.set_exchange(_exchange);
|
|
p.set_type(_type);
|
|
p.set_symbol(_symbol);
|
|
return p;
|
|
}
|
|
|
|
// No move constructor -
|
|
// because in this case the std::string will be a spot symbol which should
|
|
// be small enough to be inlined in both msvsc and gcc/clang
|
|
|
|
private:
|
|
std::string _symbol;
|
|
api::Venue _exchange = api::Venue::VENUE_UNSET;
|
|
SecurityType _type = SecurityType::SECURITYTYPE_UNSET;
|
|
};
|
|
|
|
std::ostream &operator<<(std::ostream &os, const UserSymbol &sym);
|
|
|
|
//////////////////////////////////////////////////
|
|
// Definition
|
|
//////////////////////////////////////////////////
|
|
|
|
inline std::ostream &operator<<(std::ostream &out, const UserSymbol &s) {
|
|
out << s.symbol() << " " << bts::api::SecurityType_Name(s.type()) << " at "
|
|
<< bts::api::Venue_Name(s.exchange());
|
|
return out;
|
|
}
|
|
|
|
} // namespace md
|
|
} // namespace bts
|
|
|
|
FMT_IMPL_OSTREAM(bts::md::UserSymbol);
|