Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mdlink_tencent added #1

Merged
merged 8 commits into from
Dec 7, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
mdlink_tencent added
  • Loading branch information
linboqiao committed Dec 1, 2017
commit 27587cae1ee9f9a38ad474b794c34e2782b89669
18 changes: 17 additions & 1 deletion mdlink/etc/jzs.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"sources": [
{ "addr": "tcp://127.0.0.1:10001", "id": "future1" },
{ "addr": "tcp://127.0.0.1:10002", "id": "stock1" },
{ "addr": "tcp://127.0.0.1:10003", "id": "stock2" }
{ "addr": "tcp://127.0.0.1:10003", "id": "stock2" },
{ "addr": "tcp://127.0.0.1:10004", "id": "stock3" }
]
},

Expand Down Expand Up @@ -75,6 +76,21 @@
"insttypes": "1;2;3;4;5;100;"
}
]
},

"stock3": {
"pub_addr": "tcp://0.0.0.0:10004",
"route": "TENCENT",
"source_id": 4,
"sources": [
{
"id": "stock3",
"route": "TENCENT",
"addr": "http://qt.gtimg.cn/q=",
"markets": "SZ;SH;",
"insttypes": "1;2;3;4;5;100;"
}
]
}
}
}
1 change: 1 addition & 0 deletions mdlink/scripts/start.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ start cmd /k "cd .. && bin\qms2.exe qms2"
start cmd /k "cd .. && bin\mdlink2.exe mdlink2"
::start cmd /k "cd .. && bin\mdlink_tdf.exe stock1"
start cmd /k "cd .. && bin\mdlink_sina.exe stock2"
start cmd /k "cd .. && bin\mdlink_tencent.exe stock3"
start cmd /k "cd .. && bin\mdlink_ctp.exe future1"
10 changes: 9 additions & 1 deletion mdlink/src/config/SysConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,15 @@ namespace jzs
LOG(INFO) << "\taddr: " << source["addr"].asString() << endl;
LOG(INFO) << "\tinsttypes: " << source["insttypes"].asString() << endl;
LOG(INFO) << "\tmarkets: " << source["markets"].asString() << endl;
}
}
else if (cfg.route == "TENCENT") {
svrcfg.addr = source["addr"].asString();
svrcfg.markets = source["markets"].asString();
svrcfg.insttypes = source["insttypes"].asString();
LOG(INFO) << "\taddr: " << source["addr"].asString() << endl;
LOG(INFO) << "\tinsttypes: " << source["insttypes"].asString() << endl;
LOG(INFO) << "\tmarkets: " << source["markets"].asString() << endl;
}
cfg.mdvec.push_back(svrcfg);
}
md = cfg;
Expand Down
8 changes: 5 additions & 3 deletions mdlink/src/mdlink/mdlink_tencent/MdLinkMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,20 @@ using namespace jzs::msgbus;
using namespace tencent_api;
void test_tencent()
{
string url_test = "http://qt.gtimg.cn/q=";
tencent_api::TencentApi api;
api.set_url(url_test);

vector<shared_ptr<tencent_api::MarketQuote>> quotes;


vector<string> codes;
codes.push_back("sz000001");
codes.push_back("sh000001");
codes.push_back("sh502028");
codes.push_back("sz399001");
api.get_quotes(codes, &quotes);

cout << "test tencent\n";
for (auto q : quotes) {
cout << q->code << "," << q->date << "," << q->time << "," << q->last << "," << q->volume << endl;
}
Expand All @@ -53,7 +55,7 @@ void test_tencent()

int main(int argc, char* argv[])
{
string mdid;
string mdid;
if (argc == 2) {
mdid = string(argv[1]);
init(argv[1]);
Expand All @@ -77,7 +79,7 @@ int main(int argc, char* argv[])
auto next_time = chrono::system_clock::now() + chrono::seconds(5);
while (chrono::system_clock::now() < next_time)
this_thread::sleep_until(next_time);
svr->ShowStatus();
svr->ShowStatus();
}
return 0;
}
Expand Down
92 changes: 44 additions & 48 deletions mdlink/src/mdlink/mdlink_tencent/TencentApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,14 @@ string TencentApi::download(const vector<string>& codes)

static inline int parse_date(const string& date)
{
vector<string> ss;
split(date, "-", ss);
if (ss.size() != 3) return 0;

int v;
v = atoi(ss[0].c_str()) * 10000 + atoi(ss[1].c_str()) * 100 + atoi(ss[2].c_str());
return v;
if (date.length() != 8) return 0;
return atoi(date.c_str());
}

static inline int parse_time(const string& time)
{
vector<string> ss;
split(time, ":", ss);
if (ss.size() != 3) return 0;

int v;
v = atoi(ss[0].c_str()) * 10000 + atoi(ss[1].c_str()) * 100 + atoi(ss[2].c_str());
return v * 1000;
if (time.length() != 6) return 0;
return atoi(time.c_str()) *1000;
}

static inline shared_ptr<MarketQuote> parse_quote(const string& raw_line)
Expand Down Expand Up @@ -119,44 +109,50 @@ static inline shared_ptr<MarketQuote> parse_quote(const string& raw_line)
string values_str = tmp[1];
vector<string> values;

split(values_str, ",", values);
split(values_str, "~", values);
if (values.size() == 0) {
return nullptr;
}
int i = 1;
quote->open = atof(values[i++].c_str());
quote->pre_close = atof(values[i++].c_str());
quote->last = atof(values[i++].c_str());
int i = 3;
quote->last = atof(values[i++].c_str());
quote->pre_close = atof(values[i++].c_str());
quote->open = atof(values[i++].c_str());
quote->volume = atoll(values[i++].c_str()) * 100;
i += 2; // ignore the outer, inner

quote->bid1 = atof(values[i++].c_str());
quote->bid_vol1 = atoi(values[i++].c_str()) * 100;
quote->bid2 = atof(values[i++].c_str());
quote->bid_vol2 = atoi(values[i++].c_str()) * 100;
quote->bid3 = atof(values[i++].c_str());
quote->bid_vol3 = atoi(values[i++].c_str()) * 100;
quote->bid4 = atof(values[i++].c_str());
quote->bid_vol4 = atoi(values[i++].c_str()) * 100;
quote->bid5 = atof(values[i++].c_str());
quote->bid_vol5 = atoi(values[i++].c_str()) * 100;

quote->ask1 = atof(values[i++].c_str());
quote->ask_vol1 = atoi(values[i++].c_str()) * 100;
quote->ask2 = atof(values[i++].c_str());
quote->ask_vol2 = atoi(values[i++].c_str()) * 100;
quote->ask3 = atof(values[i++].c_str());
quote->ask_vol3 = atoi(values[i++].c_str()) * 100;
quote->ask4 = atof(values[i++].c_str());
quote->ask_vol4 = atoi(values[i++].c_str()) * 100;
quote->ask5 = atof(values[i++].c_str());
quote->ask_vol5 = atoi(values[i++].c_str()) * 100;
i += 1; // ignore last transactions

quote->date = atoi(values[i].substr(0, 8).c_str());
quote->time = atoi(values[i++].substr(8, 6).c_str())*1000;
i += 2; // ignore ups and downs

quote->high = atof(values[i++].c_str());
quote->low = atof(values[i++].c_str());
i += 2; // ignore bid1,ask1
quote->volume = atoll(values[i++].c_str());
quote->turnover = atoll(values[i++].c_str());

quote->bid_vol1 = atoi(values[i++].c_str());
quote->bid1 = atof(values[i++].c_str());
quote->bid_vol2 = atoi(values[i++].c_str());
quote->bid2 = atof(values[i++].c_str());
quote->bid_vol3 = atoi(values[i++].c_str());
quote->bid3 = atof(values[i++].c_str());
quote->bid_vol4 = atoi(values[i++].c_str());
quote->bid4 = atof(values[i++].c_str());
quote->bid_vol5 = atoi(values[i++].c_str());
quote->bid5 = atof(values[i++].c_str());

quote->ask_vol1 = atoi(values[i++].c_str());
quote->ask1 = atof(values[i++].c_str());
quote->ask_vol2 = atoi(values[i++].c_str());
quote->ask2 = atof(values[i++].c_str());
quote->ask_vol3 = atoi(values[i++].c_str());
quote->ask3 = atof(values[i++].c_str());
quote->ask_vol4 = atoi(values[i++].c_str());
quote->ask4 = atof(values[i++].c_str());
quote->ask_vol5 = atoi(values[i++].c_str());
quote->ask5 = atof(values[i++].c_str());

quote->date = parse_date(values[i++]);
quote->time = parse_time(values[i++]);
i += 2; // ignore transaction, vol

quote->turnover = atoll(values[i++].c_str())*10000;

}
return quote;
}
Expand All @@ -169,7 +165,7 @@ bool TencentApi::get_quotes(const vector<string>& codes, vector<shared_ptr<Marke
vector<string> lines;
split(content, ";", lines);
for (string line : lines) {
if (strncmp(line.c_str(), "var", 3) != 0) continue;
if (strncmp(line.c_str(), "v", 1) != 0) continue;
auto q = parse_quote(trim(line));
if (q)
quotes->push_back(q);
Expand Down
6 changes: 2 additions & 4 deletions mdlink/src/mdlink/mdlink_tencent/TencentApi.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _SINA_API_H
#define _SINA_API_H
#ifndef _TENCENT_API_H
#define _TENCENT_API_H


#include <memory>
Expand Down Expand Up @@ -50,9 +50,7 @@ namespace tencent_api {

class TencentApi {
public:

TencentApi();

~TencentApi();
void set_url(string url) { m_url = url; }
bool get_quotes(const vector<string>& codes, vector<shared_ptr<MarketQuote>>* quotes);
Expand Down
4 changes: 2 additions & 2 deletions mdlink/src/mdlink/mdlink_tencent/TencentMdServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ const int sleep_time = 200; //ms

bool TencentMdServer::init_by_type(MdlinkCfg& mdcfg)
{
if (mdcfg.route != "SINA") {
LOG(FATAL) << "Error md type " << mdcfg.route << " (SINA expected)";
if (mdcfg.route != "TENCENT") {
LOG(FATAL) << "Error md type " << mdcfg.route << " (TENCENT expected)";
return false;
}
vector<MdCfg> &mdvec = mdcfg.mdvec;
Expand Down
4 changes: 2 additions & 2 deletions mdlink/src/mdlink/mdlink_tencent/TencentMdServer.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef JZS_SINAMDSERVER_H
#define JZS_SINAMDSERVER_H
#ifndef JZS_TENCENTMDSERVER_H
#define JZS_TENCENTMDSERVER_H
#include <vector>
#include <string>

Expand Down