| | |
| | | SettleMessage* settle(rapidjson::Value& d); |
| | | AddedMessage* added(rapidjson::Value& d); |
| | | DeletedMessage* deleted(rapidjson::Value& d); |
| | | RejectMessage* reject(rapidjson::Value& d); |
| | | TradeMessage* trade(rapidjson::Value& d); |
| | | BrokerRequest* brokerReq(rapidjson::Value& d); |
| | | BrokerAck* brokerAck(rapidjson::Value& d); |
| | | BrokerConfirm* brokerCon(rapidjson::Value& d); |
| | | ErrorMessage* error(rapidjson::Value& d); |
| | | |
| | | std::queue<Message*> parse(std::string& str) |
| | | { |
| | |
| | | if (mapTypes.empty()) { |
| | | initialise(); |
| | | } |
| | | if (d.HasMember("error")) return error(d); |
| | | Message* out; |
| | | switch (mapTypes[d["type"].GetString()]) { |
| | | case FUTURE_TYPE: |
| | |
| | | break; |
| | | case DELETED: |
| | | out = deleted(d); |
| | | break; |
| | | case REJECT: |
| | | out = reject(d); |
| | | break; |
| | | case TRADE: |
| | | out = trade(d); |
| | |
| | | d["sequence"].GetInt(), d["timestamp"].GetDouble()); |
| | | } |
| | | |
| | | RejectMessage* reject(rapidjson::Value& d) |
| | | { |
| | | return new RejectMessage(mapTypes[d["type"].GetString()], "", |
| | | d["error"].GetString(), uint64_t(0), double(0)); |
| | | } |
| | | |
| | | TradeMessage* trade(rapidjson::Value& d) |
| | | { |
| | | return new TradeMessage( |
| | |
| | | d["id"].GetString()); |
| | | } |
| | | |
| | | ErrorMessage* error(rapidjson::Value& d) |
| | | { |
| | | return new ErrorMessage(d["error"].GetString()); |
| | | } |
| | | |
| | | Message::Message() : type(NONE), product("error") {} |
| | | |
| | | Message::Message(MessageTypes types, std::string product) |
| | | : type(types), product(product) |
| | | { |
| | | } |
| | | |
| | | ErrorMessage::ErrorMessage(std::string message) |
| | | : Message(ERROR, ""), message(message) |
| | | { |
| | | } |
| | | std::string ErrorMessage::as_string() |
| | | { |
| | | return "{\"error\": \"" + this->message + "\"}"; |
| | | } |
| | | |
| | | FromExchange::FromExchange(MessageTypes type, std::string product, |
| | |
| | | { |
| | | } |
| | | |
| | | std::string AddedMessage::as_string() |
| | | { |
| | | return "{\"type\": \"ADDED\", \"product\": \"" + this->product + |
| | | "\", \"product\": \"" + this->id + "\" \"side\": \"" + |
| | | mapOrderSide[this->side] + |
| | | "\", \"price\": " + std::to_string(this->price) + |
| | | "\"filled\": " + std::to_string(this->filled) + |
| | | ", \"resting\": " + std::to_string(this->resting) + |
| | | ", \"sequence\": " + std::to_string(this->sequence) + |
| | | ", \"timestamp\":" + std::to_string(this->timestamp) + "}"; |
| | | } |
| | | |
| | | DeleteMessage::DeleteMessage(MessageTypes type, std::string product, |
| | | std::string id) |
| | | : ToExchange(type, product), id(id) |
| | |
| | | { |
| | | } |
| | | |
| | | std::string DeletedMessage::as_string() |
| | | { |
| | | return "{\"type\": \"DELETED\", \"product\": \"" + this->product + |
| | | "\", \"product\": \"" + this->id + "\" \"side\": \"" + |
| | | mapOrderSide[this->side] + |
| | | ", \"sequence\": " + std::to_string(this->sequence) + |
| | | ", \"timestamp\":" + std::to_string(this->timestamp) + "}"; |
| | | } |
| | | |
| | | RejectMessage::RejectMessage(MessageTypes type, std::string product, |
| | | std::string error, uint64_t sequence, |
| | | double timestamp) |
| | |
| | | { |
| | | } |
| | | |
| | | std::string RejectMessage::as_string() |
| | | { |
| | | return "{\"type\": \"REJECT\", \"product\": \"" + this->product = |
| | | "\", \"error\": \"" + this->error + |
| | | "\", \"sequence\": " + std::to_string(this->sequence) + |
| | | ", \"timestamp\": " + std::to_string(this->timestamp) + "}"; |
| | | } |
| | | |
| | | TradeMessage::TradeMessage(MessageTypes type, std::string product, double price, |
| | | uint64_t volume, std::string buyer, |
| | | std::string seller, TradeTypeEnum tradeType, |