| 1 | /* |
| 2 | * Legal Notice |
| 3 | * |
| 4 | * This document and associated source code (the "Work") is a part of a |
| 5 | * benchmark specification maintained by the TPC. |
| 6 | * |
| 7 | * The TPC reserves all right, title, and interest to the Work as provided |
| 8 | * under U.S. and international laws, including without limitation all patent |
| 9 | * and trademark rights therein. |
| 10 | * |
| 11 | * No Warranty |
| 12 | * |
| 13 | * 1.1 TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THE INFORMATION |
| 14 | * CONTAINED HEREIN IS PROVIDED "AS IS" AND WITH ALL FAULTS, AND THE |
| 15 | * AUTHORS AND DEVELOPERS OF THE WORK HEREBY DISCLAIM ALL OTHER |
| 16 | * WARRANTIES AND CONDITIONS, EITHER EXPRESS, IMPLIED OR STATUTORY, |
| 17 | * INCLUDING, BUT NOT LIMITED TO, ANY (IF ANY) IMPLIED WARRANTIES, |
| 18 | * DUTIES OR CONDITIONS OF MERCHANTABILITY, OF FITNESS FOR A PARTICULAR |
| 19 | * PURPOSE, OF ACCURACY OR COMPLETENESS OF RESPONSES, OF RESULTS, OF |
| 20 | * WORKMANLIKE EFFORT, OF LACK OF VIRUSES, AND OF LACK OF NEGLIGENCE. |
| 21 | * ALSO, THERE IS NO WARRANTY OR CONDITION OF TITLE, QUIET ENJOYMENT, |
| 22 | * QUIET POSSESSION, CORRESPONDENCE TO DESCRIPTION OR NON-INFRINGEMENT |
| 23 | * WITH REGARD TO THE WORK. |
| 24 | * 1.2 IN NO EVENT WILL ANY AUTHOR OR DEVELOPER OF THE WORK BE LIABLE TO |
| 25 | * ANY OTHER PARTY FOR ANY DAMAGES, INCLUDING BUT NOT LIMITED TO THE |
| 26 | * COST OF PROCURING SUBSTITUTE GOODS OR SERVICES, LOST PROFITS, LOSS |
| 27 | * OF USE, LOSS OF DATA, OR ANY INCIDENTAL, CONSEQUENTIAL, DIRECT, |
| 28 | * INDIRECT, OR SPECIAL DAMAGES WHETHER UNDER CONTRACT, TORT, WARRANTY, |
| 29 | * OR OTHERWISE, ARISING IN ANY WAY OUT OF THIS OR ANY OTHER AGREEMENT |
| 30 | * RELATING TO THE WORK, WHETHER OR NOT SUCH AUTHOR OR DEVELOPER HAD |
| 31 | * ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. |
| 32 | * |
| 33 | * Contributors |
| 34 | * - Doug Johnson |
| 35 | */ |
| 36 | |
| 37 | /****************************************************************************** |
| 38 | * Description: This class provides Market Exchange Emulator |
| 39 | * functionality. It accepts trade requests for |
| 40 | *processing; generates a negative exponential delay for each trade to simulate |
| 41 | *the market processing time; manages the timers for all trades being processed; |
| 42 | *generates Trade-Result and Market-Feed input data to be used by a sponsor |
| 43 | *provided callback interface to the SUT (see MEESUTInterface.h). |
| 44 | * |
| 45 | * The constructor for this class requires two parameters. |
| 46 | * - TradingTimeSoFar: the number of seconds for which |
| 47 | * trades have been run against the database. This allows |
| 48 | * the MEE to pick up on the price curves from where it |
| 49 | * last left off. If doing this isn't important than 0 can |
| 50 | * passed in. |
| 51 | * - pSUT: a pointer to an instance of a sponsor provided |
| 52 | * subclassing of the CMEESUTInterface class. |
| 53 | * |
| 54 | * - pLogger: a pointer to an instance of CEGenLogger or a |
| 55 | * sponsor provided subclassing of the CBaseLogger class. |
| 56 | * |
| 57 | * The MEE provides the following entry points. |
| 58 | * |
| 59 | * - SetBaseTime: used to cordinate the price curves |
| 60 | * across multiple instances of this class. This method |
| 61 | * should be called "at the same time" for all instances. |
| 62 | * This call should be made just prior to starting |
| 63 | * transactions. There is no return value. |
| 64 | * |
| 65 | * - SubmitTradeRequest: used for submitting a trade |
| 66 | * request into the market. The return value is the number |
| 67 | * of milliseconds before the next timer is set to expire. |
| 68 | * |
| 69 | * - GenerateTradeResult: called whenever the current |
| 70 | *timer has expired (i.e. whenever the number of milliseconds returned by either |
| 71 | *SubmitTradeRequest or GenerateTradeResult has elapsed). The return value is |
| 72 | * the number of milliseconds before the next timer is set |
| 73 | * to expire. |
| 74 | * |
| 75 | * - DisableTickerTape / EnableTickerTape: by default, the |
| 76 | * ticker tape functionality of the MEE is enabled. It can |
| 77 | * be disabled, or re-enabled by calls to these methods. |
| 78 | * Disabling the ticker tape is useful at the end of a |
| 79 | * test run to allow processing of submitted orders to |
| 80 | * continue (Trade-Results) while not generating any |
| 81 | * ticker tape activity (Market-Feeds). |
| 82 | ******************************************************************************/ |
| 83 | |
| 84 | #ifndef MEE_H |
| 85 | #define MEE_H |
| 86 | |
| 87 | #include "utilities/EGenUtilities_stdafx.h" |
| 88 | #include "MEETradeRequestActions.h" |
| 89 | #include "TxnHarnessStructs.h" |
| 90 | #include "MEEPriceBoard.h" |
| 91 | #include "MEETickerTape.h" |
| 92 | #include "MEETradingFloor.h" |
| 93 | #include "MEESUTInterface.h" |
| 94 | #include "BaseLogger.h" |
| 95 | #include "DriverParamSettings.h" |
| 96 | |
| 97 | #include "input/DataFileManager.h" |
| 98 | |
| 99 | namespace TPCE { |
| 100 | |
| 101 | class CMEE { |
| 102 | private: |
| 103 | CDriverMEESettings m_DriverMEESettings; |
| 104 | |
| 105 | CMEESUTInterface *m_pSUT; |
| 106 | CBaseLogger *m_pLogger; |
| 107 | CMEEPriceBoard m_PriceBoard; |
| 108 | CMEETickerTape m_TickerTape; |
| 109 | CMEETradingFloor m_TradingFloor; |
| 110 | CDateTime m_BaseTime; |
| 111 | CDateTime m_CurrentTime; |
| 112 | |
| 113 | CMutex m_MEELock; |
| 114 | |
| 115 | // Automatically generate unique RNG seeds |
| 116 | void AutoSetRNGSeeds(UINT32 UniqueId); |
| 117 | |
| 118 | public: |
| 119 | static const INT32 NO_OUTSTANDING_TRADES = CMEETradingFloor::NO_OUTSTANDING_TRADES; |
| 120 | |
| 121 | // Constructor - automatic RNG seed generation |
| 122 | CMEE(INT32 TradingTimeSoFar, CMEESUTInterface *pSUT, CBaseLogger *pLogger, const DataFileManager &inputFiles, |
| 123 | UINT32 UniqueId); |
| 124 | |
| 125 | // Constructor - RNG seed provided |
| 126 | CMEE(INT32 TradingTimeSoFar, CMEESUTInterface *pSUT, CBaseLogger *pLogger, const DataFileManager &inputFiles, |
| 127 | UINT32 UniqueId, RNGSEED TickerTapeRNGSeed, RNGSEED TradingFloorRNGSeed); |
| 128 | |
| 129 | ~CMEE(void); |
| 130 | |
| 131 | RNGSEED GetTickerTapeRNGSeed(void); |
| 132 | RNGSEED GetTradingFloorRNGSeed(void); |
| 133 | |
| 134 | void SetBaseTime(void); |
| 135 | |
| 136 | INT32 SubmitTradeRequest(PTradeRequest pTradeRequest); |
| 137 | INT32 GenerateTradeResult(void); |
| 138 | |
| 139 | bool EnableTickerTape(void); |
| 140 | bool DisableTickerTape(void); |
| 141 | }; |
| 142 | |
| 143 | } // namespace TPCE |
| 144 | |
| 145 | #endif // MEE_H |
| 146 | |