#pragma once

#include <map>
#include <string>

#include "spdQuoteAPI.h"

struct ContractInfo
{
	std::string Exchange;
	std::string Symbol;
	std::string DisplayName;
	std::string MaturityDate;
	std::string Category;
	double BullPx;
	double BearPx;
	double RefPx;
	double ContractMultiplier;
	double StrikePx;
	std::string Market;
	int TradeUnit;
	std::string DayTrade;
	int WarningStock;
	bool TradeFlag;
	bool IsWarrant;
	std::string CallPut;
};

class testSpdQuoteAPI : public spdQuoteAPI
{
private:
	bool exit{ false };

	std::map<std::string, ContractInfo> Stocks;
	std::map<std::string, ContractInfo> Futures;
	std::map<std::string, ContractInfo> Options;

private:
	void OnStarwaveConnected() override;
	void OnStarwaveDisconnected() override;
	void OnOrderBook(const char* Exchange, const char* Symbol, const char* MsgTime, spdMsgOrderBook* OrderBook) override;
	void OnTrade(const char* Exchange, const char* Symbol, const char* MatchTime, double MatchPrice, int MatchQty, bool isTestMatch) override;
	void OnStarwaveLogonResponse(bool isLoginOK, const char* ReplyMsg) override;
	void OnContract(const char* Exchange, const char* Symbol, const char* Name, const char* MaturityDate, const char* Category, spdContract* Contract) override;
	void OnContractDownloadComplete(int TotalContracts) override;

public:
	void MainLoop();
	void Stop() { exit = true; }
	void AddStock(const char* symbol, ContractInfo* contract) { Stocks.insert(std::pair<std::string, ContractInfo>(symbol, *contract)); }
	void AddFuture(const char* symbol, ContractInfo* contract) { Futures.insert(std::pair<std::string, ContractInfo>(symbol, *contract)); }
	void AddOption(const char* symbol, ContractInfo* contract) { Options.insert(std::pair<std::string, ContractInfo>(symbol, *contract)); }
	void OnDownloadComplete(int TotalContracts);
};

