2022-02-18 09:24:24 +00:00
|
|
|
#ifndef _COMMON_H_
|
|
|
|
#define _COMMON_H_
|
|
|
|
|
2022-02-18 11:07:03 +00:00
|
|
|
/*
|
|
|
|
ALL INCLUDES (COMMON) SHOULD BE HERE
|
|
|
|
*/
|
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
#include <stdlib.h>
|
2022-05-07 14:49:43 +00:00
|
|
|
#include <pthread.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <tuple>
|
2022-02-18 11:07:03 +00:00
|
|
|
|
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
|
2022-12-10 14:35:16 +00:00
|
|
|
// TODO: REFACTOR ALL THIS TRASH HOLY SHIT
|
2022-02-18 11:07:03 +00:00
|
|
|
|
2022-05-07 14:49:43 +00:00
|
|
|
/***********************************************************************************
|
|
|
|
WEBSOCKET MESSAGE STRUCTURES
|
|
|
|
***********************************************************************************/
|
|
|
|
/**
|
|
|
|
Types of messages going through the websocket.
|
|
|
|
X-macros: https://stackoverflow.com/questions/201593/is-there-a-simple-way-to-convert-c-enum-to-string
|
|
|
|
*/
|
|
|
|
enum WS_MSG {
|
|
|
|
#define X(a) a,
|
|
|
|
#include "ws_msg.def"
|
|
|
|
#undef X
|
2022-02-18 11:07:03 +00:00
|
|
|
};
|
2022-02-18 09:24:24 +00:00
|
|
|
|
2022-05-07 14:49:43 +00:00
|
|
|
///**
|
|
|
|
// Mapping from WS_MSG enum to its name.
|
|
|
|
//*/
|
|
|
|
//std::map<WS_MSG, std::string> WS_MSG_map {
|
|
|
|
// #define X(a) {a, "#a"},
|
|
|
|
// #include "ws_msg.def"
|
|
|
|
// #undef X
|
|
|
|
//};
|
2022-02-18 11:07:03 +00:00
|
|
|
|
2022-05-07 14:49:43 +00:00
|
|
|
/**
|
|
|
|
Structure holding websocket raw data and their type.
|
|
|
|
Used to fill the queue uniformly
|
|
|
|
*/
|
2022-02-18 11:07:03 +00:00
|
|
|
typedef struct raw_msg_t {
|
2022-05-07 14:49:43 +00:00
|
|
|
enum WS_MSG type;
|
2022-02-18 09:24:24 +00:00
|
|
|
std::string data;
|
|
|
|
} raw_message_t ;
|
|
|
|
|
2022-02-18 11:07:03 +00:00
|
|
|
/**
|
2022-05-07 14:49:43 +00:00
|
|
|
Placeholder for parsed outputs of the websocket.
|
|
|
|
These structures are c++ formated and should contain the entirety of the represented data.
|
|
|
|
Specialized below.
|
2022-02-18 11:07:03 +00:00
|
|
|
*/
|
2022-05-07 14:49:43 +00:00
|
|
|
template <WS_MSG E>
|
|
|
|
struct ws_msg_parsed;
|
2022-02-18 11:07:03 +00:00
|
|
|
|
2022-02-18 09:24:24 +00:00
|
|
|
/**
|
|
|
|
coinPriceUpdate structure
|
|
|
|
*/
|
2022-02-18 11:07:03 +00:00
|
|
|
template <>
|
2022-12-10 14:35:16 +00:00
|
|
|
struct ws_msg_parsed<WS_EVENT_COIN_PRICE> {
|
2022-02-18 09:24:24 +00:00
|
|
|
std::string coin;
|
|
|
|
float price;
|
|
|
|
float saleValue;
|
|
|
|
uint inCirculation;
|
2022-02-18 11:07:03 +00:00
|
|
|
};
|
2022-02-18 09:24:24 +00:00
|
|
|
|
2022-05-07 14:49:43 +00:00
|
|
|
/**
|
2022-12-10 14:35:16 +00:00
|
|
|
Auxiliary type for WS_EVENT_HISTORY.
|
2022-05-07 14:49:43 +00:00
|
|
|
This holds individual transactions as handed by the websocket in a list.
|
|
|
|
*/
|
|
|
|
template <>
|
|
|
|
struct ws_msg_parsed<WS_EVENT_TRANSACTION> {
|
|
|
|
std::string coin;
|
|
|
|
uint type;
|
|
|
|
std::string userid;
|
|
|
|
int quantity;
|
|
|
|
long timestamp;
|
|
|
|
bool completed;
|
|
|
|
float price;
|
2022-12-10 14:35:16 +00:00
|
|
|
bool fund;
|
2022-05-07 14:49:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
historyUpdate structure holding transactions.
|
|
|
|
*/
|
|
|
|
template<>
|
2022-12-10 14:35:16 +00:00
|
|
|
struct ws_msg_parsed<WS_EVENT_HISTORY> {
|
2022-05-07 14:49:43 +00:00
|
|
|
std::vector<ws_msg_parsed<WS_EVENT_TRANSACTION>> transaction_list;
|
|
|
|
};
|
|
|
|
|
2022-12-10 14:35:16 +00:00
|
|
|
/***********************************************************************************
|
|
|
|
MUTUAL FUNDS
|
|
|
|
***********************************************************************************/
|
|
|
|
/**
|
|
|
|
Portfolio type TODO: Make this global, could be used with users' wallets
|
|
|
|
nasfaq::types::portfolio::coin
|
|
|
|
*/
|
|
|
|
typedef struct portfolio_coin_t {
|
|
|
|
std::string coin; //TODO: make this an enum
|
|
|
|
uint amount;
|
|
|
|
long ts;
|
|
|
|
float mpp;
|
|
|
|
} portfolio_coin_t ;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Portfolio update
|
|
|
|
*/
|
|
|
|
template <>
|
|
|
|
struct ws_msg_parsed<WS_EVENT_MF_PORTFOLIO> {
|
|
|
|
std::string fund;
|
|
|
|
std::string event; // TODO: type for this
|
|
|
|
std::vector<ws_msg_parsed<WS_EVENT_TRANSACTION>> transactions;
|
|
|
|
std::vector<portfolio_coin_t> portfolio;
|
|
|
|
};
|
|
|
|
|
2022-05-07 14:49:43 +00:00
|
|
|
/***********************************************************************************
|
|
|
|
WEBSOCKET MESSAGE STRUCTURES FUNCTIONS
|
|
|
|
***********************************************************************************/
|
|
|
|
std::ostream& operator<< (std::ostream&, const WS_MSG&);
|
|
|
|
|
|
|
|
/***********************************************************************************
|
|
|
|
IN-GAME MESSAGE STRUCTURES
|
|
|
|
***********************************************************************************/
|
|
|
|
/**
|
|
|
|
Types of in-game messages.
|
|
|
|
*/
|
|
|
|
enum IG_MSG
|
|
|
|
{ TRANSACTION
|
|
|
|
, IG_UNKNOWN_TYPE
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************************
|
|
|
|
INGAME MESSAGE STRUCTURES FUNCTIONS
|
|
|
|
***********************************************************************************/
|
|
|
|
template<WS_MSG E>
|
|
|
|
std::ostream& operator<< (std::ostream&, ws_msg_parsed<E> const &);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Cycle representation.
|
|
|
|
*/
|
|
|
|
typedef std::map<std::string, int> cycle_t;
|
|
|
|
std::ostream& operator<< (std::ostream&, const cycle_t&);
|
|
|
|
|
|
|
|
/**
|
|
|
|
User representation
|
|
|
|
*/
|
|
|
|
typedef struct user_t{
|
|
|
|
std::string userid;
|
|
|
|
std::string username;
|
|
|
|
std::string icon;
|
|
|
|
float networth;
|
|
|
|
} user_t;
|
|
|
|
|
2022-02-18 09:24:24 +00:00
|
|
|
#endif
|
|
|
|
|