KdataController.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. <?php
  2. namespace backend\controllers;
  3. use Yii;
  4. use yii\web\Controller;
  5. use yii\filters\VerbFilter;
  6. use yii\filters\AccessControl;
  7. use common\models\LoginForm;
  8. /**
  9. * Site controller
  10. */
  11. class KdataController extends Controller
  12. {
  13. // /**
  14. // * @inheritdoc
  15. // */
  16. // public function behaviors()
  17. // {
  18. // return [
  19. // 'access' => [
  20. // 'class' => AccessControl::className(),
  21. // 'rules' => [
  22. // [
  23. // 'actions' => ['login', 'error', 'index','testcreatequeue'],
  24. // 'allow' => true,
  25. // ],
  26. // [
  27. // 'actions' => ['logout'],
  28. // 'allow' => true,
  29. // 'roles' => ['@'],
  30. // ],
  31. // ],
  32. // ],
  33. // 'verbs' => [
  34. // 'class' => VerbFilter::className(),
  35. // 'actions' => [
  36. // 'logout' => ['post'],
  37. // ],
  38. // ],
  39. // ];
  40. // }
  41. /**
  42. * @inheritdoc
  43. */
  44. public function actions()
  45. {
  46. return [
  47. 'error' => [
  48. 'class' => 'yii\web\ErrorAction',
  49. ],
  50. ];
  51. }
  52. /**
  53. * Displays homepage.
  54. *
  55. * @return string
  56. */
  57. public function actionIndex()
  58. {
  59. \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
  60. header("Access-Control-Allow-Origin: *");
  61. header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE");
  62. header('Access-Control-Allow-Headers:x-requested-with,content-type');
  63. $data= "{\"id\":[0,1,2,3,4,5],\"time\":[1524787200,1524441600,1524182400,1524182400,1523491200,1522195200],\"color\":[\"red\",\"blue\",\"green\",\"red\",\"blue\",\"green\"],\"text\":[\"Today\",\"4 days back\",\"7 days back + Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\",\"7 days back once again\",\"15 days back\",\"30 days back\"],\"label\":[\"A\",\"B\",\"CORE\",\"D\",\"EURO\",\"F\"],\"labelFontColor\":[\"white\",\"white\",\"red\",\"#FFFFFF\",\"white\",\"#000\"],\"minSize\":[14,28,7,40,7,14]}";
  64. echo ($data);
  65. }
  66. /**
  67. * Displays homepage.
  68. *
  69. * @return string
  70. */
  71. public function actionConfig()
  72. {
  73. \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
  74. header("Access-Control-Allow-Origin: *");
  75. header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE");
  76. header('Access-Control-Allow-Headers:x-requested-with,content-type');
  77. $data= "{\"supports_search\":false,\"supports_group_request\":true,
  78. \"supports_marks\":false,\"supports_timescale_marks\":false,\"supports_time\":false,
  79. \"exchanges\":[{\"value\":\"\",\"name\":\"All Exchanges\",\"desc\":\"\"},{\"value\":\"NasdaqNM\",\"name\":\"NasdaqNM\",\"desc\":\"NasdaqNM\"},{\"value\":\"NYSE\",\"name\":\"NYSE\",\"desc\":\"NYSE\"},{\"value\":\"NCM\",\"name\":\"NCM\",\"desc\":\"NCM\"},{\"value\":\"NGM\",\"name\":\"NGM\",\"desc\":\"NGM\"}],\"symbols_types\":[{\"name\":\"All types\",\"value\":\"\"},{\"name\":\"Stock\",\"value\":\"stock\"},{\"name\":\"Index\",\"value\":\"index\"}],\"supported_resolutions\":[\"D\",\"2D\",\"3D\",\"W\",\"3W\",\"M\",\"6M\"]}";
  80. // $data="
  81. //{
  82. // \"supports_search\": false,
  83. // \"supports_group_request\": true,
  84. // \"supports_marks\": false,
  85. // \"supports_timescale_marks\": false,
  86. // \"supports_time\": false,
  87. // \"exchanges\": [
  88. // {
  89. // \"value\": \"中国第一股票\",
  90. // \"name\": \"All Exchanges\",
  91. // \"desc\": \"中国第一股票\"
  92. // }
  93. // ],
  94. // \"symbols_types\": [
  95. // {
  96. // \"name\": \"All types\",
  97. // \"value\": \"\"
  98. // }
  99. // ],
  100. // \"supported_resolutions\": [
  101. // \"D\",
  102. // \"2D\",
  103. // \"6M\"
  104. // ]
  105. //}";
  106. $data="
  107. {
  108. \"supports_search\": false,
  109. \"supports_group_request\": true,
  110. \"supports_marks\": false,
  111. \"supports_timescale_marks\": false,
  112. \"supports_time\": true,
  113. \"exchanges\": [
  114. {
  115. \"value\": \"\",
  116. \"name\": \"All Exchanges\",
  117. \"desc\": \"\"
  118. },
  119. {
  120. \"value\": \"NasdaqNM\",
  121. \"name\": \"NasdaqNM\",
  122. \"desc\": \"NasdaqNM\"
  123. },
  124. {
  125. \"value\": \"NYSE\",
  126. \"name\": \"NYSE\",
  127. \"desc\": \"NYSE\"
  128. },
  129. {
  130. \"value\": \"NCM\",
  131. \"name\": \"NCM\",
  132. \"desc\": \"NCM\"
  133. },
  134. {
  135. \"value\": \"NGM\",
  136. \"name\": \"NGM\",
  137. \"desc\": \"NGM\"
  138. }
  139. ],
  140. \"symbols_types\": [
  141. {
  142. \"name\": \"All types\",
  143. \"value\": \"\"
  144. },
  145. {
  146. \"name\": \"Stock\",
  147. \"value\": \"stock\"
  148. },
  149. {
  150. \"name\": \"Index\",
  151. \"value\": \"index\"
  152. }
  153. ],
  154. \"supported_resolutions\":[
  155. \"1\",
  156. \"3\",
  157. \"5\",
  158. \"15\",
  159. \"30\",
  160. \"60\",
  161. \"120\",
  162. \"240\",
  163. \"360\",
  164. \"720\",
  165. \"D\",
  166. \"3D\",
  167. \"5D\",
  168. \"7D\",
  169. \"15D\",
  170. \"M\"
  171. ]
  172. }";
  173. echo ($data);
  174. }
  175. /**
  176. * Displays homepage.
  177. *
  178. * @return string
  179. */
  180. public function actionMarks()
  181. {
  182. \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
  183. header("Access-Control-Allow-Origin: *");
  184. header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE");
  185. header('Access-Control-Allow-Headers:x-requested-with,content-type');
  186. $data= "{\"id\":[0,1,2,3,4,5],\"time\":[1524787200,1524441600,1524182400,1524182400,1523491200,1522195200],\"color\":[\"red\",\"blue\",\"green\",\"red\",\"blue\",\"green\"],\"text\":[\"Today\",\"4 days back\",\"7 days back + Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\",\"7 days back once again\",\"15 days back\",\"30 days back\"],\"label\":[\"A\",\"B\",\"CORE\",\"D\",\"EURO\",\"F\"],\"labelFontColor\":[\"white\",\"white\",\"red\",\"#FFFFFF\",\"white\",\"#000\"],\"minSize\":[14,28,7,40,7,14]}";
  187. echo ($data);
  188. }
  189. /**
  190. * Displays homepage.
  191. *
  192. * @return string
  193. */
  194. public function actionSymbol_info()
  195. {
  196. \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
  197. header("Access-Control-Allow-Origin: *");
  198. header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE");
  199. header('Access-Control-Allow-Headers:x-requested-with,content-type');
  200. $data= "{
  201. \"symbol\": [
  202. \"BTCUSDT\"
  203. ],
  204. \"description\": [
  205. \"BTCUSDT\"
  206. ],
  207. \"exchange-listed\": \"中国第一股\",
  208. \"exchange-traded\": \"快速交易\",
  209. \"minmov\": 1,
  210. \"minmov2\": 0,
  211. \"pricescale\": [
  212. 1
  213. ],
  214. \"has-intraday\": true,
  215. \"has_no_volume\": [
  216. true
  217. ],
  218. \"has_weekly_and_monthly\": true,
  219. \"has_seconds\": true,
  220. \"has_daily\": true,
  221. \"intraday_multipliers\": [
  222. 1
  223. ],
  224. \"supported_resolutions\": [
  225. \"1\",
  226. \"3\",
  227. \"5\",
  228. \"15\",
  229. \"30\",
  230. \"60\",
  231. \"120\",
  232. \"240\",
  233. \"360\",
  234. \"720\",
  235. \"D\",
  236. \"3D\",
  237. \"5D\",
  238. \"7D\",
  239. \"15D\",
  240. \"M\"
  241. ],
  242. \"type\": [
  243. \"stock\"
  244. ],
  245. \"ticker\": [
  246. \"BTCUSDT\"
  247. ],
  248. \"timezone\": \"UTC\",
  249. \"session-regular\": \"0900-1600\"
  250. }";
  251. echo ($data);
  252. }
  253. /**
  254. * Displays homepage.
  255. *
  256. * @return string
  257. */
  258. public function actionSymbols()
  259. {
  260. \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
  261. header("Access-Control-Allow-Origin: *");
  262. header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE");
  263. header('Access-Control-Allow-Headers:x-requested-with,content-type');
  264. $data= "{\"name\":\"AAPL\",\"exchange-traded\":\"NasdaqNM\",\"exchange-listed\":\"NasdaqNM\",\"timezone\":\"America/New_York\",\"minmov\":1,\"minmov2\":0,\"pointvalue\":1,\"session\":\"0930-1630\",\"has_intraday\":false,\"has_no_volume\":false,\"description\":\"Apple Inc.\",\"type\":\"stock\",\"supported_resolutions\":[\"D\",\"2D\",\"3D\",\"W\",\"3W\",\"M\",\"6M\"],\"pricescale\":100,\"ticker\":\"AAPL\"}";
  265. // $data= "{
  266. // \"symbol\": [
  267. // \"BTCUSDT\"
  268. // ],
  269. // \"description\": [
  270. // \"BTCUSDT\"
  271. // ],
  272. // \"exchange-listed\": \"中国第一股\",
  273. // \"exchange-traded\": \"快速交易\",
  274. // \"minmov\": 1,
  275. // \"minmov2\": 0,
  276. // \"pricescale\": [
  277. // 1
  278. // ],
  279. // \"has-intraday\": true,
  280. // \"has_no_volume\": [
  281. // true
  282. // ],
  283. // \"has_weekly_and_monthly\": true,
  284. //
  285. // \"has_seconds\": true,
  286. // \"has_daily\": true,
  287. //
  288. //
  289. // \"intraday_multipliers\": [
  290. // 1
  291. // ],
  292. // \"supported_resolutions\": [
  293. // \"60\",
  294. // \"2D\",
  295. // \"3D\",
  296. // \"W\",
  297. // \"3W\",
  298. // \"M\",
  299. // \"6M\"
  300. // ],
  301. //
  302. //
  303. //
  304. //
  305. //
  306. //
  307. //
  308. // \"type\": [
  309. // \"stock\"
  310. // ],
  311. // \"ticker\": [
  312. // \"BTCUSDT\"
  313. // ],
  314. // \"timezone\": \"UTC\",
  315. // \"session-regular\": \"0900-1600\"
  316. //}";
  317. $data="{
  318. \"name\": \"BTCUSDT\",
  319. \"exchange-traded\": \"BTCUSDT\",
  320. \"exchange-listed\": \"BTCUSDT\",
  321. \"timezone\": \"America/New_York\",
  322. \"minmov\": 1,
  323. \"minmov2\": 0,
  324. \"pointvalue\": 1,
  325. \"session\": \"0930-1630\",
  326. \"has_intraday\": true,
  327. \"has_no_volume\": false,
  328. \"has_seconds\": true,
  329. \"description\": \"BTCUSDT\",
  330. \"type\": \"stock\",
  331. \"supported_resolutions\": [
  332. \"1\",
  333. \"3\",
  334. \"5\",
  335. \"15\",
  336. \"30\",
  337. \"60\",
  338. \"120\",
  339. \"240\",
  340. \"360\",
  341. \"720\",
  342. \"D\",
  343. \"3D\",
  344. \"5D\",
  345. \"7D\",
  346. \"15D\",
  347. \"M\"
  348. ],
  349. \"pricescale\": 100,
  350. \"ticker\": \"BTCUSDT\"
  351. }";
  352. echo ($data);
  353. }
  354. /**
  355. * Displays homepage.
  356. *
  357. * @return string
  358. */
  359. public function actionTime()
  360. {
  361. \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
  362. header("Access-Control-Allow-Origin: *");
  363. header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE");
  364. header('Access-Control-Allow-Headers:x-requested-with,content-type');
  365. $data= "1524713662";
  366. echo ($data);
  367. }
  368. /**
  369. * Displays homepage.
  370. *
  371. * @return string
  372. */
  373. public function actionTimescale_marks()
  374. {
  375. \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
  376. header("Access-Control-Allow-Origin: *");
  377. header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE");
  378. header('Access-Control-Allow-Headers:x-requested-with,content-type');
  379. $data= "{\"name\":\"AAPL\",\"exchange-traded\":\"NasdaqNM\",\"exchange-listed\":\"NasdaqNM\",\"timezone\":\"America/New_York\",\"minmov\":1,\"minmov2\":0,\"pointvalue\":1,\"session\":\"0930-1630\",\"has_intraday\":false,\"has_no_volume\":false,\"description\":\"Apple Inc.\",\"type\":\"stock\",\"supported_resolutions\":[\"D\",\"2D\",\"3D\",\"W\",\"3W\",\"M\",\"6M\"],\"pricescale\":100,\"ticker\":\"AAPL\"}";
  380. $data= "{
  381. \"symbol\": [
  382. \"BTCUSDT\"
  383. ],
  384. \"description\": [
  385. \"BTCUSDT\"
  386. ],
  387. \"exchange-listed\": \"中国第一股\",
  388. \"exchange-traded\": \"快速交易\",
  389. \"minmov\": 1,
  390. \"minmov2\": 0,
  391. \"pricescale\": [
  392. 1
  393. ],
  394. \"has_intraday\": true,
  395. \"has_weekly_and_monthly\": true,
  396. \"type\": [
  397. \"stock\"
  398. ],
  399. \"ticker\": [
  400. \"BTCUSDT\"
  401. ],
  402. \"timezone\": \"UTC\",
  403. \"session-regular\": \"0900-1600\"
  404. }";
  405. echo ($data);
  406. }
  407. /**
  408. * Displays homepage.
  409. *
  410. * @return string
  411. */
  412. public function actionHistory()
  413. {
  414. header("Access-Control-Allow-Origin: *");
  415. header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE");
  416. header('Access-Control-Allow-Headers:x-requested-with,content-type');
  417. \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
  418. // $params = Yii::$app->getRequest()->params;
  419. $params=Yii::$app->request->get();//获取参数
  420. $rmap = array(
  421. '1'=>'m1',
  422. '3'=>'m3',
  423. '5'=>'m5',
  424. '15'=>'m15',
  425. '30'=>'m30',
  426. '60'=>'h1',
  427. '120'=>'h2',
  428. '240'=>'h4',
  429. '360'=>'h6',
  430. '720'=>'h12',
  431. 'D'=>'d1',
  432. '3D'=>'d3',
  433. '5D'=>'d5',
  434. '7D'=>'d7',
  435. '15D'=>'d15',
  436. 'M'=>'mo'
  437. );
  438. $level = $rmap[$params['resolution']];
  439. $url='http://59.110.169.112:89/kdata/';
  440. $data = file_get_contents($url."history?symbol=BTCUSDT&period={$level}&from={$params['from']}&to={$params['to']}");
  441. // $data = file_get_contents($url."history?symbol=BTCUSDT&period=m1&from=1493796539&to=1493796540");
  442. // $a=rand(1,9);
  443. // if($a > 6){
  444. ////
  445. //// header("Access-Control-Allow-Origin: *");
  446. //// header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE");
  447. //// header('Access-Control-Allow-Headers:x-requested-with,content-type');
  448. //// $data= "{\"t\":[1492041600,1492387200,1492473600,1492560000,1492646400,1492732800,1492992000,1493078400],\"o\":[141.91,141.48,141.41,141.88,141.22,142.44,143.5,143.91],\"h\":[142.38,141.88,142.04,142,142.92,142.68,143.95,144.9],\"l\":[141.05,140.87,141.11,140.45,141.16,141.85,143.18,143.87],\"c\":[141.05,141.83,141.2,140.68,142.44,142.27,143.64,144.54],\"v\":[17822880,16582094,14697544,17328375,23319562,17320928,17116599,18216472],\"s\":\"ok\"}";
  449. ////
  450. // $url='http://59.110.169.112:89/kdata/';
  451. // $data = file_put_contents($url."history?symbol={$params['symbol']}&period={$params['resolution']}&from={$params['from']}&to={$params['to']}");
  452. //
  453. //
  454. //
  455. //
  456. //
  457. //
  458. //// }else{
  459. //
  460. //// $data="{\"s\":\"no_data\",\"nextTime\":1522108800}";
  461. //
  462. //// }
  463. echo ($data);
  464. }
  465. }