1
0

KdataController.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  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\": true,
  109. \"supports_group_request\": true,
  110. \"supports_marks\": false,
  111. \"supports_timescale_marks\": false,
  112. \"supports_time\": true,
  113. \"exchanges\": [
  114. {
  115. \"value\": \"BTCUSDT\",
  116. \"name\": \"BTCUSDT\",
  117. \"desc\": \"BTCUSDT\"
  118. } ,
  119. {
  120. \"value\": \"BTCUSDT1\",
  121. \"name\": \"BTCUSDT1\",
  122. \"desc\": \"BTCUSDT1\"
  123. }
  124. ],
  125. \"symbols_types\": [
  126. {
  127. \"name\": \"stock\",
  128. \"value\": \"BTCUSDT\"
  129. } ,
  130. {
  131. \"name\": \"All types\",
  132. \"value\": \"\"
  133. }
  134. ],
  135. \"has_no_volume\": true,
  136. \"supported_resolutions\":[
  137. \"1\",
  138. \"3\",
  139. \"5\",
  140. \"15\",
  141. \"30\",
  142. \"60\",
  143. \"120\",
  144. \"240\",
  145. \"360\",
  146. \"720\",
  147. \"D\",
  148. \"3D\",
  149. \"5D\",
  150. \"7D\",
  151. \"15D\",
  152. \"M\"
  153. ]
  154. }";
  155. echo ($data);
  156. }
  157. /**
  158. * Displays homepage.
  159. *
  160. * @return string
  161. */
  162. public function actionMarks()
  163. {
  164. \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
  165. header("Access-Control-Allow-Origin: *");
  166. header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE");
  167. header('Access-Control-Allow-Headers:x-requested-with,content-type');
  168. $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]}";
  169. echo ($data);
  170. }
  171. /**
  172. * Displays homepage.
  173. *
  174. * @return string
  175. */
  176. public function actionSearch()
  177. {
  178. \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
  179. header("Access-Control-Allow-Origin: *");
  180. header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE");
  181. header('Access-Control-Allow-Headers:x-requested-with,content-type');
  182. $data= "[
  183. {
  184. \"symbol\": \"BTCUSDT\",
  185. \"full_name\": \"BTCUSDT\",
  186. \"description\": \"BTCUSDT Inc.\",
  187. \"exchange\": \"BTCUSDT\",
  188. \"type\": \"stock\"
  189. },
  190. {
  191. \"symbol\": \"BTCUSDT1\",
  192. \"full_name\": \"BTCUSDT1\",
  193. \"description\": \"BTCUSDT1 Inc.\",
  194. \"exchange\": \"BTCUSDT1\",
  195. \"type\": \"stock\"
  196. }
  197. ]";
  198. echo ($data);
  199. }
  200. /**
  201. * Displays homepage.
  202. *
  203. * @return string
  204. */
  205. public function actionSymbol_info()
  206. {
  207. \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
  208. header("Access-Control-Allow-Origin: *");
  209. header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE");
  210. header('Access-Control-Allow-Headers:x-requested-with,content-type');
  211. $data= "{
  212. \"symbol\": [
  213. \"BTCUSDT\",
  214. \"BTCUSDT1\"
  215. ],
  216. \"description\": [
  217. \"BTCUSDT\" ,
  218. \"BTCUSDT1\"
  219. ],
  220. \"exchange-listed\": \"中国第一股\",
  221. \"exchange-traded\": \"快速交易\",
  222. \"minmov\": 1,
  223. \"minmov2\": 0,
  224. \"pricescale\": [
  225. 1
  226. ],
  227. \"has-intraday\": true,
  228. \"has_no_volume\": true,
  229. \"has_weekly_and_monthly\": true,
  230. \"has_seconds\": true,
  231. \"has_daily\": true,
  232. \"intraday_multipliers\": [
  233. 1
  234. ],
  235. \"volume_precision\": [
  236. 3
  237. ],
  238. \"supported_resolutions\": [
  239. \"1\",
  240. \"3\",
  241. \"5\",
  242. \"15\",
  243. \"30\",
  244. \"60\",
  245. \"120\",
  246. \"240\",
  247. \"360\",
  248. \"720\",
  249. \"D\",
  250. \"3D\",
  251. \"5D\",
  252. \"7D\",
  253. \"15D\",
  254. \"M\"
  255. ],
  256. \"type\": [
  257. \"stock\"
  258. ],
  259. \"ticker\": [
  260. \"BTCUSDT\",
  261. \"BTCUSDT1\"
  262. ],
  263. \"timezone\": \"America/New_York\",
  264. \"session-regular\": \"0900-1600\"
  265. }";
  266. echo ($data);
  267. }
  268. /**
  269. * Displays homepage.
  270. *
  271. * @return string
  272. */
  273. public function actionSymbols()
  274. {
  275. \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
  276. header("Access-Control-Allow-Origin: *");
  277. header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE");
  278. header('Access-Control-Allow-Headers:x-requested-with,content-type');
  279. $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\"}";
  280. // $data= "{
  281. // \"symbol\": [
  282. // \"BTCUSDT\"
  283. // ],
  284. // \"description\": [
  285. // \"BTCUSDT\"
  286. // ],
  287. // \"exchange-listed\": \"中国第一股\",
  288. // \"exchange-traded\": \"快速交易\",
  289. // \"minmov\": 1,
  290. // \"minmov2\": 0,
  291. // \"pricescale\": [
  292. // 1
  293. // ],
  294. // \"has-intraday\": true,
  295. // \"has_no_volume\": [
  296. // true
  297. // ],
  298. // \"has_weekly_and_monthly\": true,
  299. //
  300. // \"has_seconds\": true,
  301. // \"has_daily\": true,
  302. //
  303. //
  304. // \"intraday_multipliers\": [
  305. // 1
  306. // ],
  307. // \"supported_resolutions\": [
  308. // \"60\",
  309. // \"2D\",
  310. // \"3D\",
  311. // \"W\",
  312. // \"3W\",
  313. // \"M\",
  314. // \"6M\"
  315. // ],
  316. //
  317. //
  318. //
  319. //
  320. //
  321. //
  322. //
  323. // \"type\": [
  324. // \"stock\"
  325. // ],
  326. // \"ticker\": [
  327. // \"BTCUSDT\"
  328. // ],
  329. // \"timezone\": \"UTC\",
  330. // \"session-regular\": \"0900-1600\"
  331. //}";
  332. $data="{
  333. \"name\": \"BTCUSDT\",
  334. \"exchange-traded\": \"BTCUSDT\",
  335. \"exchange-listed\": \"BTCUSDT\",
  336. \"timezone\": \"America/New_York\",
  337. \"minmov\": 1,
  338. \"minmov2\": 0,
  339. \"pointvalue\": 1,
  340. \"session\": \"0930-1630\",
  341. \"has_intraday\": true,
  342. \"has_no_volume\": true,
  343. \"has_seconds\": true,
  344. \"description\": \"BTCUSDT\",
  345. \"type\": \"stock\",
  346. \"supported_resolutions\": [
  347. \"1\",
  348. \"3\",
  349. \"5\",
  350. \"15\",
  351. \"30\",
  352. \"60\",
  353. \"120\",
  354. \"240\",
  355. \"360\",
  356. \"720\",
  357. \"D\",
  358. \"3D\",
  359. \"5D\",
  360. \"7D\",
  361. \"15D\",
  362. \"M\"
  363. ],
  364. \"pricescale\": 100,
  365. \"ticker\": \"BTCUSDT\"
  366. }";
  367. echo ($data);
  368. }
  369. /**
  370. * Displays homepage.
  371. *
  372. * @return string
  373. */
  374. public function actionTime()
  375. {
  376. \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
  377. header("Access-Control-Allow-Origin: *");
  378. header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE");
  379. header('Access-Control-Allow-Headers:x-requested-with,content-type');
  380. $data= "1524713662";
  381. echo ($data);
  382. }
  383. /**
  384. * Displays homepage.
  385. *
  386. * @return string
  387. */
  388. public function actionTimescale_marks()
  389. {
  390. \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
  391. header("Access-Control-Allow-Origin: *");
  392. header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE");
  393. header('Access-Control-Allow-Headers:x-requested-with,content-type');
  394. $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\"}";
  395. $data= "{
  396. \"symbol\": [
  397. \"BTCUSDT\"
  398. ],
  399. \"description\": [
  400. \"BTCUSDT\"
  401. ],
  402. \"exchange-listed\": \"中国第一股\",
  403. \"exchange-traded\": \"快速交易\",
  404. \"minmov\": 1,
  405. \"minmov2\": 0,
  406. \"pricescale\": [
  407. 1
  408. ],
  409. \"has_intraday\": true,
  410. \"has_weekly_and_monthly\": true,
  411. \"type\": [
  412. \"stock\"
  413. ],
  414. \"ticker\": [
  415. \"BTCUSDT\"
  416. ],
  417. \"timezone\": \"UTC\",
  418. \"session-regular\": \"0900-1600\"
  419. }";
  420. echo ($data);
  421. }
  422. /**
  423. * Displays homepage.
  424. *
  425. * @return string
  426. */
  427. public function actionHistory()
  428. {
  429. header("Access-Control-Allow-Origin: *");
  430. header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE");
  431. header('Access-Control-Allow-Headers:x-requested-with,content-type');
  432. \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
  433. // $params = Yii::$app->getRequest()->params;
  434. $params=Yii::$app->request->get();//获取参数
  435. $rmap = array(
  436. '1'=>'m1',
  437. '3'=>'m3',
  438. '5'=>'m5',
  439. '15'=>'m15',
  440. '30'=>'m30',
  441. '60'=>'h1',
  442. '120'=>'h2',
  443. '240'=>'h4',
  444. '360'=>'h6',
  445. '720'=>'h12',
  446. 'D'=>'d1',
  447. '3D'=>'d3',
  448. '5D'=>'d5',
  449. '7D'=>'d7',
  450. '15D'=>'d15',
  451. 'M'=>'mo'
  452. );
  453. $level = $rmap[$params['resolution']];
  454. $url='http://59.110.169.112:89/kdata/';
  455. $data = file_get_contents($url."history?symbol={$params['symbol']}&period={$level}&from={$params['from']}&to={$params['to']}");
  456. // $data = file_get_contents($url."history?symbol=BTCUSDT&period=m1&from=1493796539&to=1493796540");
  457. // $a=rand(1,9);
  458. // if($a > 6){
  459. ////
  460. //// header("Access-Control-Allow-Origin: *");
  461. //// header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE");
  462. //// header('Access-Control-Allow-Headers:x-requested-with,content-type');
  463. //// $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\"}";
  464. ////
  465. // $url='http://59.110.169.112:89/kdata/';
  466. // $data = file_put_contents($url."history?symbol={$params['symbol']}&period={$params['resolution']}&from={$params['from']}&to={$params['to']}");
  467. //
  468. //
  469. //
  470. //
  471. //
  472. //
  473. //// }else{
  474. //
  475. //// $data="{\"s\":\"no_data\",\"nextTime\":1522108800}";
  476. //
  477. //// }
  478. echo ($data);
  479. }
  480. }