Parcourir la source

指数数据接口

wanggangtao il y a 5 ans
Parent
commit
384b5b60a4

+ 18 - 0
data/get_boniu_index_csi300.php

@@ -0,0 +1,18 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: 王刚涛
+ * Date: 2020/11/24
+ * Time: 19:16
+ * 获取某天的某个股票的数据
+ */
+require('../init.php');
+
+
+/***
+ * 1。获取所有的股票代码
+ * 2.遍历股票代码,住区数据,插入到数据库中
+ */
+
+
+sina::get_boniu_index_csi300();//默认是今天

+ 12 - 0
data/get_boniu_index_gem.php

@@ -0,0 +1,12 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: 王刚涛
+ * Date: 2020/11/25
+ * Time: 23:20
+ * 深成指
+ */
+require('../init.php');
+
+
+sina::get_boniu_index_gem();//默认是今天

+ 18 - 0
data/get_boniu_index_kc50.php

@@ -0,0 +1,18 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: 王刚涛
+ * Date: 2020/11/24
+ * Time: 19:16
+ * 获取某天的某个股票的数据
+ */
+require('../init.php');
+
+
+/***
+ * 1。获取所有的股票代码
+ * 2.遍历股票代码,住区数据,插入到数据库中
+ */
+
+
+sina::get_boniu_index_kc50();//默认是今天

+ 15 - 0
data/get_boniu_index_scz.php

@@ -0,0 +1,15 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: 王刚涛
+ * Date: 2020/11/25
+ * Time: 23:20
+ * 深成指
+ */
+require('../init.php');
+
+
+
+
+
+sina::get_boniu_index_scz();//默认是今天

+ 18 - 0
data/get_boniu_index_sh50.php

@@ -0,0 +1,18 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: 王刚涛
+ * Date: 2020/11/24
+ * Time: 19:16
+ * 获取某天的某个股票的数据
+ */
+require('../init.php');
+
+
+/***
+ * 1。获取所有的股票代码
+ * 2.遍历股票代码,住区数据,插入到数据库中
+ */
+
+
+sina::get_boniu_index_sh50();//默认是今天

data/test.php → data/get_day_k_base.php


+ 5 - 2
lib/index_csi300.class.php

@@ -14,8 +14,11 @@ class Index_csi300 {
 	 * @param $log       日志内容
 	 * 
 	 */
-	static public function add($log){
-
+	static public function add($attrs){
+        if (empty($attrs)) throw new Exception('参数不能为空', 102);
+        $Table_index_csi300 = new Table_index_csi300();
+        $id = $Table_index_csi300->add($attrs);
+        return $id;
 	}
     
 	/** 

+ 11 - 8
lib/index_gem.class.php

@@ -7,14 +7,17 @@
  */
 class Index_gem {
 
-	/**
-	 * 记录管理员日志
-	 * 
-	 * @param $log       日志内容
-	 * 
-	 */
-	static public function add($log){
-
+    /***
+     * @param $log
+     * @return mixed
+     * @throws Exception
+     *
+     */
+	static public function add($attrs){
+        if (empty($attrs)) throw new Exception('参数不能为空', 102);
+        $Table_index_gem = new Table_index_gem();
+        $id = $Table_index_gem->add($attrs);
+        return $id;
 	}
     
 	/** 

+ 5 - 2
lib/index_kc50.class.php

@@ -13,8 +13,11 @@ class Index_kc50 {
 	 * @param $log       日志内容
 	 * 
 	 */
-	static public function add($log){
-
+	static public function add($attrs){
+        if (empty($attrs)) throw new Exception('参数不能为空', 102);
+        $Table_index_kc50 = new Table_index_kc50();
+        $id = $Table_index_kc50->add($attrs);
+        return $id;
 	}
     
 	/** 

+ 11 - 8
lib/index_scz.class.php

@@ -8,14 +8,17 @@
 
 class Index_scz {
 
-	/**
-	 * 记录管理员日志
-	 * 
-	 * @param $log       日志内容
-	 * 
-	 */
-	static public function add($log){
-
+    /****
+     * @param $date
+     * @return mixed
+     * @throws Exception
+     *
+     */
+	static public function add($attrs){
+        if (empty($attrs)) throw new Exception('参数不能为空', 102);
+        $Table_index_scz = new Table_index_scz();
+        $id = $Table_index_scz->add($attrs);
+        return $id;
 	}
     
 	/** 

+ 5 - 2
lib/index_sh50.class.php

@@ -14,8 +14,11 @@ class Index_sh50 {
 	 * @param $log       日志内容
 	 * 
 	 */
-	static public function add($log){
-
+	static public function add($attrs){
+        if (empty($attrs)) throw new Exception('参数不能为空', 102);
+        $Table_index_sh50 = new Table_index_sh50();
+        $id = $Table_index_sh50->add($attrs);
+        return $id;
 	}
     
 	/** 

+ 134 - 8
lib/sina.class.php

@@ -37,7 +37,12 @@ class sina
 
 
 
-//上证指数表(boniu_index_sh)
+
+    /****
+     * @param string $code
+     * @return mixed
+    //上证指数表(boniu_index_sh)
+     */
      static public function get_boniu_index_sh($code="000001")
     {
         $url = "http://hq.sinajs.cn/list=s_sh".$code;
@@ -55,13 +60,128 @@ class sina
         $data['value'] = (int)($data2[9]);//成交金额以万为单位
         return  Index_sh::add($data);
     }
-//深成指数表(boniu_index_scz)
+
+
+    /****
+     * @param string $code
+     * @return mixed
+     * 深成指数表(boniu_index_scz)
+     */
+    static public function get_boniu_index_scz($code="399001")
+    {
+        $url = "http://hq.sinajs.cn/list=s_sz".$code;
+        $content3=sina::curl_get_data($url);
+        $data['increase_value'] = floatval($content3[3]);//涨跌率
+        $data2=self::get_info_code($code);//调用另一个函数获取其他数据如开盘价等等
+        $data['increase_price']  = floatval($data2[3]-$data2[2]);//涨跌
+        // 涨跌价-当日股票最新价与前一日收盘价格(或前一日收盘指数)
+        $data['date'] = strtotime(date('Y-m-d',time()));//当天的0点时间戳
+        $data['open_price'] = floatval($data2[1]);//开盘价
+        $data['close_price'] = floatval($data2[3]);//3点之后的当前价格就是收盘价
+        $data['hightest_price'] = floatval($data2[4]);//今日最高价
+        $data['lowest_price'] = floatval($data2[5]);//今日最低价
+        $data['amount'] =  (int)($data2[8]);//成交的股票数,以百为单位
+        $data['value'] = (int)($data2[9]);//成交金额以万为单位
+        return  Index_scz::add($data);
+    }
+
+
+
+    /***
+     * @param string $code
+     * @return mixed
+     * 上证50指数表(boniu_index_sh50)  000016
+     */
+    static public function get_boniu_index_sh50($code="000016")
+    {
+        $url = "http://hq.sinajs.cn/list=s_sh".$code;
+        $content3=sina::curl_get_data($url);
+        $data['increase_value'] = floatval($content3[3]);//涨跌率
+        $data2=self::get_info_code($code);//调用另一个函数获取其他数据如开盘价等等
+        $data['increase_price']  = floatval($data2[3]-$data2[2]);//涨跌
+        // 涨跌价-当日股票最新价与前一日收盘价格(或前一日收盘指数)
+        $data['date'] = strtotime(date('Y-m-d',time()));//当天的0点时间戳
+        $data['open_price'] = floatval($data2[1]);//开盘价
+        $data['close_price'] = floatval($data2[3]);//3点之后的当前价格就是收盘价
+        $data['hightest_price'] = floatval($data2[4]);//今日最高价
+        $data['lowest_price'] = floatval($data2[5]);//今日最低价
+        $data['amount'] =  (int)($data2[8]);//成交的股票数,以百为单位
+        $data['value'] = (int)($data2[9]);//成交金额以万为单位
+        return  Index_sh50::add($data);
+    }
+
+
+
+    /***
+     * @param string $code
+     * @return mixed
+     * //沪深300指数表(boniu_index_csi300)   399300
+     */
+    static public function get_boniu_index_csi300($code="399300")
+    {
+        $url = "http://hq.sinajs.cn/list=s_sz".$code;
+        $content3=sina::curl_get_data($url);
+        $data['increase_value'] = floatval($content3[3]);//涨跌率
+        $data2=self::get_info_code($code);//调用另一个函数获取其他数据如开盘价等等
+        $data['increase_price']  = floatval($data2[3]-$data2[2]);//涨跌
+        // 涨跌价-当日股票最新价与前一日收盘价格(或前一日收盘指数)
+        $data['date'] = strtotime(date('Y-m-d',time()));//当天的0点时间戳
+        $data['open_price'] = floatval($data2[1]);//开盘价
+        $data['close_price'] = floatval($data2[3]);//3点之后的当前价格就是收盘价
+        $data['hightest_price'] = floatval($data2[4]);//今日最高价
+        $data['lowest_price'] = floatval($data2[5]);//今日最低价
+        $data['amount'] =  (int)($data2[8]);//成交的股票数,以百为单位
+        $data['value'] = (int)($data2[9]);//成交金额以万为单位
+        return  Index_csi300::add($data);
+    }
+//
+    /***
+     * @param string $code
+     * @return mixed
+     * 创业板指数表(boniu_index_gem) 399006
+     */
+    static public function get_boniu_index_gem($code="399006")
+    {
+        $url = "http://hq.sinajs.cn/list=s_sz".$code;
+        $content3=sina::curl_get_data($url);
+        $data['increase_value'] = floatval($content3[3]);//涨跌率
+        $data2=self::get_info_code($code);//调用另一个函数获取其他数据如开盘价等等
+        $data['increase_price']  = floatval($data2[3]-$data2[2]);//涨跌
+        // 涨跌价-当日股票最新价与前一日收盘价格(或前一日收盘指数)
+        $data['date'] = strtotime(date('Y-m-d',time()));//当天的0点时间戳
+        $data['open_price'] = floatval($data2[1]);//开盘价
+        $data['close_price'] = floatval($data2[3]);//3点之后的当前价格就是收盘价
+        $data['hightest_price'] = floatval($data2[4]);//今日最高价
+        $data['lowest_price'] = floatval($data2[5]);//今日最低价
+        $data['amount'] =  (int)($data2[8]);//成交的股票数,以百为单位
+        $data['value'] = (int)($data2[9]);//成交金额以万为单位
+        return  Index_gem::add($data);
+    }
+
+
+    /****
+     * @param string $code
+     * @return mixed
+     * //科创50指数( boniu_index_kc50)   000688
+     */
+    static public function get_boniu_index_kc50($code="000688")
+    {
+        $url = "http://hq.sinajs.cn/list=s_sh".$code;
+        $content3=sina::curl_get_data($url);
+        $data['increase_value'] = floatval($content3[3]);//涨跌率
+        $data2=self::get_info_code($code);//调用另一个函数获取其他数据如开盘价等等
+        $data['increase_price']  = floatval($data2[3]-$data2[2]);//涨跌
+        // 涨跌价-当日股票最新价与前一日收盘价格(或前一日收盘指数)
+        $data['date'] = strtotime(date('Y-m-d',time()));//当天的0点时间戳
+        $data['open_price'] = floatval($data2[1]);//开盘价
+        $data['close_price'] = floatval($data2[3]);//3点之后的当前价格就是收盘价
+        $data['hightest_price'] = floatval($data2[4]);//今日最高价
+        $data['lowest_price'] = floatval($data2[5]);//今日最低价
+        $data['amount'] =  (int)($data2[8]);//成交的股票数,以百为单位
+        $data['value'] = (int)($data2[9]);//成交金额以万为单位
+        return  Index_kc50::add($data);
+    }
 //
-//上证50指数表(boniu_index_sh50)
-//沪深300指数表(boniu_index_csi300)
-//创业板指数表(boniu_index_gem)
-//科创50指数( boniu_index_kc50)
-//日k线表 day_k_******(每月存一张表,比如boniu_day_k_202011)
     /***
      * @param $code
      * @param $date
@@ -80,7 +200,13 @@ class sina
         return $content3;
     }
 
-
+    /***
+     * @param $code
+     * @param $date
+     * @return mixed
+     * 日k线表 day_k_******(每月存一张表,比如boniu_day_k_202011)
+     *
+     */
     static public function get_day_k_base($code, $date)
     {
         $stock_code = $code;

+ 9 - 3
lib/table/table_index_csi300.class.php

@@ -31,9 +31,15 @@ class Table_index_csi300 extends Table {
 
     public function add($attr){
         $param = array (
-
-             'admingroup_name'    => array('string', $attr['name'])
-
+            'index_csi300_date'    => array('number', $attr['date']),
+            'index_csi300_open_price'    => array('number', $attr['open_price']),
+            'index_csi300_close_price'    => array('number', $attr['close_price']),
+            'index_csi300_hightest_price'    => array('number', $attr['hightest_price']),
+            'index_csi300_lowest_price'    => array('number', $attr['lowest_price']),
+            'index_csi300_increase_value'    => array('number', $attr['increase_value']),
+            'index_csi300_increase_price'    => array('number', $attr['increase_price']),
+            'index_csi300_amount'    => array('number', $attr['amount']),
+            'index_csi300_value'    => array('number', $attr['value']),
         );
         return $this->pdo->sqlinsert($this->table_fullname, $param);
     }

+ 9 - 3
lib/table/table_index_gem.class.php

@@ -31,9 +31,15 @@ class Table_index_gem extends Table {
 
     public function add($attr){
         $param = array (
-
-             'admingroup_name'    => array('string', $attr['name'])
-
+            'index_gem_date'    => array('number', $attr['date']),
+            'index_gem_open_price'    => array('number', $attr['open_price']),
+            'index_gem_close_price'    => array('number', $attr['close_price']),
+            'index_gem_hightest_price'    => array('number', $attr['hightest_price']),
+            'index_gem_lowest_price'    => array('number', $attr['lowest_price']),
+            'index_gem_increase_value'    => array('number', $attr['increase_value']),
+            'index_gem_increase_price'    => array('number', $attr['increase_price']),
+            'index_gem_amount'    => array('number', $attr['amount']),
+            'index_gem_value'    => array('number', $attr['value']),
         );
         return $this->pdo->sqlinsert($this->table_fullname, $param);
     }

+ 9 - 3
lib/table/table_index_kc50.class.php

@@ -31,9 +31,15 @@ class Table_index_kc50 extends Table {
 
     public function add($attr){
         $param = array (
-
-             'admingroup_name'    => array('string', $attr['name'])
-
+            'index_kc50_date'    => array('number', $attr['date']),
+            'index_kc50_open_price'    => array('number', $attr['open_price']),
+            'index_kc50_close_price'    => array('number', $attr['close_price']),
+            'index_kc50_hightest_price'    => array('number', $attr['hightest_price']),
+            'index_kc50_lowest_price'    => array('number', $attr['lowest_price']),
+            'index_kc50_increase_value'    => array('number', $attr['increase_value']),
+            'index_kc50_increase_price'    => array('number', $attr['increase_price']),
+            'index_kc50_amount'    => array('number', $attr['amount']),
+            'index_kc50_value'    => array('number', $attr['value']),
         );
         return $this->pdo->sqlinsert($this->table_fullname, $param);
     }

+ 10 - 3
lib/table/table_index_scz.class.php

@@ -31,10 +31,17 @@ class Table_index_scz extends Table {
 
     public function add($attr){
         $param = array (
-
-             'admingroup_name'    => array('string', $attr['name'])
-
+            'index_scz_date'    => array('number', $attr['date']),
+            'index_scz_open_price'    => array('number', $attr['open_price']),
+            'index_scz_close_price'    => array('number', $attr['close_price']),
+            'index_scz_hightest_price'    => array('number', $attr['hightest_price']),
+            'index_scz_lowest_price'    => array('number', $attr['lowest_price']),
+            'index_scz_increase_value'    => array('number', $attr['increase_value']),
+            'index_scz_increase_price'    => array('number', $attr['increase_price']),
+            'index_scz_amount'    => array('number', $attr['amount']),
+            'index_scz_value'    => array('number', $attr['value']),
         );
+
         return $this->pdo->sqlinsert($this->table_fullname, $param);
     }
 

+ 9 - 3
lib/table/table_index_sh50.class.php

@@ -31,9 +31,15 @@ class Table_index_sh50 extends Table {
 
     public function add($attr){
         $param = array (
-
-             'admingroup_name'    => array('string', $attr['name'])
-
+            'index_sh50_date'    => array('number', $attr['date']),
+            'index_sh50_open_price'    => array('number', $attr['open_price']),
+            'index_sh50_close_price'    => array('number', $attr['close_price']),
+            'index_sh50_hightest_price'    => array('number', $attr['hightest_price']),
+            'index_sh50_lowest_price'    => array('number', $attr['lowest_price']),
+            'index_sh50_increase_value'    => array('number', $attr['increase_value']),
+            'index_sh50_increase_price'    => array('number', $attr['increase_price']),
+            'index_sh50_amount'    => array('number', $attr['amount']),
+            'index_sh50_value'    => array('number', $attr['value']),
         );
         return $this->pdo->sqlinsert($this->table_fullname, $param);
     }