|
7 | 7 | #include <regex> |
8 | 8 | #include <string> |
9 | 9 |
|
| 10 | +namespace TIGER_API { |
| 11 | + Contract ContractUtil::stock_contract(const utility::string_t symbol, const utility::string_t currency, |
| 12 | + const utility::string_t local_symbol, const utility::string_t exchange, |
| 13 | + long contract_id) { |
| 14 | + return Contract(U("STK"), symbol, currency, local_symbol, exchange, contract_id); |
| 15 | + } |
10 | 16 |
|
11 | | -Contract stock_contract(const utility::string_t symbol, const utility::string_t currency, const utility::string_t local_symbol, const utility::string_t exchange, |
12 | | - long contract_id) { |
13 | | - return Contract(U("STK"), symbol, currency, local_symbol, exchange, contract_id); |
14 | | -} |
15 | | - |
16 | | -Contract option_contract(const utility::string_t symbol, const utility::string_t expiry, const utility::string_t strike, const utility::string_t right, |
17 | | - const utility::string_t currency, long multiplier, const utility::string_t local_symbol, long contract_id) { |
18 | | - return Contract( U("OPT"), symbol,expiry, strike, right, currency, multiplier, local_symbol, contract_id); |
19 | | -} |
| 17 | + Contract |
| 18 | + ContractUtil::option_contract(const utility::string_t symbol, const utility::string_t expiry, const utility::string_t strike, |
| 19 | + const utility::string_t right, |
| 20 | + const utility::string_t currency, long multiplier, const utility::string_t local_symbol, |
| 21 | + long contract_id) { |
| 22 | + return Contract(U("OPT"), symbol, expiry, strike, right, currency, multiplier, local_symbol, contract_id); |
| 23 | + } |
20 | 24 |
|
21 | | -Contract option_contract(const utility::string_t identifier, long multiplier, const utility::string_t currency) { |
22 | | - utility::string_t symbol, expiry, right, strike; |
23 | | - std::tie(symbol, expiry, right, strike) = extract_option_info(identifier); |
24 | | - if (!expiry.empty() && expiry.find('-') != utility::string_t ::npos) { |
25 | | - expiry.erase(std::remove(expiry.begin(), expiry.end(), '-'), expiry.end()); |
| 25 | + Contract ContractUtil::option_contract(const utility::string_t identifier, long multiplier, const utility::string_t currency) { |
| 26 | + utility::string_t symbol, expiry, right, strike; |
| 27 | + std::tie(symbol, expiry, right, strike) = ContractUtil::extract_option_info(identifier); |
| 28 | + if (!expiry.empty() && expiry.find('-') != utility::string_t::npos) { |
| 29 | + expiry.erase(std::remove(expiry.begin(), expiry.end(), '-'), expiry.end()); |
| 30 | + } |
| 31 | + return Contract(U("OPT"), symbol, expiry, strike, right, currency, multiplier, U(""), 0); |
26 | 32 | } |
27 | | - return Contract(U("OPT"), symbol, expiry, strike, right, currency, multiplier, U(""), 0); |
28 | | -} |
29 | 33 |
|
30 | | -Contract future_contract(const utility::string_t symbol, const utility::string_t currency, const utility::string_t expiry, |
31 | | - const utility::string_t exchange, const utility::string_t contract_month, long multiplier, |
32 | | - const utility::string_t local_symbol) { |
33 | | - return Contract(U("FUT"), symbol, expiry, multiplier, contract_month, currency, exchange, local_symbol); |
34 | | -} |
| 34 | + Contract |
| 35 | + ContractUtil::future_contract(const utility::string_t symbol, const utility::string_t currency, const utility::string_t expiry, |
| 36 | + const utility::string_t exchange, const utility::string_t contract_month, long multiplier, |
| 37 | + const utility::string_t local_symbol) { |
| 38 | + return Contract(U("FUT"), symbol, expiry, multiplier, contract_month, currency, exchange, local_symbol); |
| 39 | + } |
35 | 40 |
|
36 | 41 |
|
37 | | -std::tuple<utility::string_t , utility::string_t , utility::string_t , utility::string_t> extract_option_info(const utility::string_t identifier) { |
38 | | - auto trans_identifier = str16to8(identifier); |
| 42 | + std::tuple<utility::string_t, utility::string_t, utility::string_t, utility::string_t> |
| 43 | + ContractUtil::extract_option_info(const utility::string_t identifier) { |
| 44 | + auto trans_identifier = str16to8(identifier); |
39 | 45 |
|
40 | | - if (!trans_identifier.empty()) { |
41 | | - std::regex pattern(R"((\w+(?:\.\w+)?)\s*(\d{6})([CP])(\d+))"); |
42 | | - std::smatch matches; |
43 | | - if (std::regex_search(trans_identifier, matches, pattern) && matches.size() == 5) { |
44 | | - std::string underlying_symbol = matches[1].str(); |
45 | | - std::string expiry = "20" + matches[2].str(); |
46 | | - std::string right = matches[3]; |
47 | | - utility::string_t strike = double_to_string(std::stod(matches[4]) / 1000); |
48 | | - if (expiry.size() == 8) { |
49 | | - expiry = expiry.substr(0, 4) + "-" + expiry.substr(4, 2) + "-" + expiry.substr(6); |
| 46 | + if (!trans_identifier.empty()) { |
| 47 | + std::regex pattern(R"((\w+(?:\.\w+)?)\s*(\d{6})([CP])(\d+))"); |
| 48 | + std::smatch matches; |
| 49 | + if (std::regex_search(trans_identifier, matches, pattern) && matches.size() == 5) { |
| 50 | + std::string underlying_symbol = matches[1].str(); |
| 51 | + std::string expiry = "20" + matches[2].str(); |
| 52 | + std::string right = matches[3]; |
| 53 | + utility::string_t strike = double_to_string(std::stod(matches[4]) / 1000); |
| 54 | + if (expiry.size() == 8) { |
| 55 | + expiry = expiry.substr(0, 4) + "-" + expiry.substr(4, 2) + "-" + expiry.substr(6); |
| 56 | + } |
| 57 | + right = (right == "C") ? "CALL" : "PUT"; |
| 58 | + return std::make_tuple(str8to16(underlying_symbol), str8to16(expiry), str8to16(right), |
| 59 | + strike); |
50 | 60 | } |
51 | | - right = (right == "C") ? "CALL" : "PUT"; |
52 | | - return std::make_tuple(str8to16(underlying_symbol), str8to16(expiry), str8to16(right), |
53 | | - strike); |
54 | 61 | } |
| 62 | + return std::make_tuple(U(""), U(""), U(""), U("")); |
55 | 63 | } |
56 | | - return std::make_tuple(U(""), U(""), U(""), U("")); |
57 | 64 | } |
58 | 65 |
|
59 | 66 |
|
|
0 commit comments