Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
stock
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sugar
stock
Commits
fc234190
Commit
fc234190
authored
Jun 21, 2024
by
董先生
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
2.0
parent
baa37e0c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
8 deletions
+59
-8
app/apicom/controller/Trade.php
app/apicom/controller/Trade.php
+3
-3
app/apicom/model/StockPosition.php
app/apicom/model/StockPosition.php
+1
-1
app/common.php
app/common.php
+55
-4
No files found.
app/apicom/controller/Trade.php
View file @
fc234190
...
...
@@ -40,14 +40,14 @@ class Trade extends BaseController
//提取当前价格
$data
[
$k
][
'now_price'
]
=
$Qdata
[
'Price'
];
//市值 = 当前价格*数量
$data
[
$k
][
'market_value'
]
=
round
(
$Qdata
[
'Price'
]
*
$item
[
'stock_count'
],
2
);
$data
[
$k
][
'market_value'
]
=
round
(
(
int
)
$Qdata
[
'Price'
]
*
(
int
)
$item
[
'stock_count'
],
2
);
//参考成本价
$data
[
$k
][
'ck_price'
]
=
StockPosition
::
calculate
(
$subid
,
$item
[
"gupiao_code"
],
'price'
);
//买入均价
$data
[
$k
][
'buy_average_price'
]
=
StockPosition
::
calculate
(
$subid
,
$item
[
"gupiao_code"
],
'average'
);
//参考盈亏
//$data[$k]['ck_profit'] = $item['stock_count'] > 0 ? round(($Qdata['Price']-$data[$k]['buy_average_price'])*$item['stock_count'], 2) : 0;
$data
[
$k
][
'ck_profit'
]
=
$item
[
'stock_count'
]
>
0
?
bcmul
(
strval
(
$Qdata
[
"Price"
]
-
$data
[
$k
][
'buy_average_price'
]),
strval
(
$item
[
'stock_count'
]),
2
)
:
0
;
//参考浮动盈亏
$data
[
$k
][
'ck_profit'
]
=
$item
[
'stock_count'
]
>
0
?
bcmul
(
strval
(
(
int
)
$Qdata
[
"Price"
]
-
(
int
)
$data
[
$k
][
'buy_average_price'
]),
strval
(
$item
[
'stock_count'
]),
2
)
:
0
;
//参考浮动盈亏
//盈亏比例
//$data[$k]['profit_rate'] = $item['stock_count'] > 0 ? round(($data[$k]['ck_profit'] / ($data[$k]['buy_average_price'] * $item['stock_count'])) * 100, 2) : 0;
//$data[$k]['profit_rate'] = $item['stock_count'] > 0 ? bcdiv(strval($data[$k]['ck_profit']),strval($data[$k]['buy_average_price']*$item['stock_count']*100),2) : 0;//盈亏比例
...
...
@@ -113,7 +113,7 @@ class Trade extends BaseController
//print_r("佣金: ".$commission." 过户费: ".$transfer." 总计:".$effectMoney);Db::rollback();exit;
$del_res
=
$Delivery
->
add_m_delivery_order
(
$data
[
'code'
],
$data
[
'count'
],
$price
,
$data
[
'subid'
],
$commission
,
$transfer
,
$Trust_no
,
$avail
,
$amount
,
$data
[
'model'
]);
//print_r($del_res);Db::rollback();exit;
if
(
!
$del_res
){
if
(
!
$del_res
){
Db
::
rollback
();
return
ajaxmsg
(
'委托失败'
,
0
);
}
else
{
...
...
app/apicom/model/StockPosition.php
View file @
fc234190
...
...
@@ -225,7 +225,7 @@ class StockPosition extends Base
$data
[
0
][
'canbuy_count'
]
=
$count
;
$data
[
0
][
'ck_price'
]
=
self
::
calculate
(
$sub_id
,
$code
,
'price'
);
//参考成本价
$data
[
0
][
'buy_average_price'
]
=
self
::
calculate
(
$sub_id
,
$code
,
'average'
);
//买入均价
$data
[
0
][
'ck_profit_price'
]
=
''
;
//参考盈亏成本价
$data
[
0
][
'ck_profit_price
ck_profit_price
'
]
=
''
;
//参考盈亏成本价
$data
[
0
][
'now_price'
]
=
$stockinfo
[
"Price"
];
//'当前价'
$data
[
0
][
'market_value'
]
=
$stockinfo
[
"Price"
]
*
$count
;
//最新市值
$data
[
0
][
'ck_profit'
]
=
$count
>
0
?
bcmul
(
strval
(
$stockinfo
[
"Price"
]
-
$ck_price
),
strval
(
$count
),
2
)
:
0
;
//参考浮动盈亏
...
...
app/common.php
View file @
fc234190
...
...
@@ -729,9 +729,33 @@ if(!function_exists('curl')){
function
curl
(
$url
){
$ch
=
curl_init
();
curl_setopt
(
$ch
,
CURLOPT_URL
,
$url
);
curl_setopt
(
$ch
,
CURLOPT_HEADER
,
false
);
// curl_setopt($ch, CURLOPT_HEADER, false);
// $headers = [
// ':authority:push2.eastmoney.com',
// ':method:GET',
// ':path:/api/qt/clist/get?np=1&fltt=2&invt=2&fields=f1,f2,f3,f4,f12,f13,f14&pn=1&fid=f3&po=1&fs=b:DLMK0144&pz=200',
// ':scheme:https',
// 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
// 'Accept-Encoding:gzip, deflate, br, zstd',
// 'Accept-Language:zh-CN,zh;q=0.9',
// 'Cache-Control:max-age=0',
// 'Cookie:qgqp_b_id=e226b82e4ddba871d760e93933bc9c95; st_si=89300947093095; st_asi=delete; websitepoptg_api_time=1718683552178; st_pvi=03338601060702; st_sp=2024-06-18%2011%3A19%3A01; st_inirUrl=https%3A%2F%2Fwap.eastmoney.com%2F; st_sn=17; st_psi=20240618134400959-111000300841-7097354950',
// 'Sec-Ch-Ua:"Not/A)Brand";v="8", "Chromium";v="126", "Google Chrome";v="126"',
// 'Sec-Ch-Ua-Mobile:?0',
// 'Sec-Ch-Ua-Platform:"Windows"',
// 'Sec-Fetch-Dest:document',
// 'Sec-Fetch-Mode:navigate',
// 'Sec-Fetch-Site:none',
// 'Sec-Fetch-User:?1',
// 'Upgrade-Insecure-Requests:1',
// 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
// // 可以继续添加更多的头部信息
// ];
// curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt
(
$ch
,
CURLOPT_RETURNTRANSFER
,
1
);
curl_setopt
(
$ch
,
CURLOPT_TIMEOUT
,
10
);
// curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//绕过ssl验证
// curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$result
=
curl_exec
(
$ch
);
curl_close
(
$ch
);
return
$result
;
...
...
@@ -819,9 +843,13 @@ if (!function_exists('fenxi_east')) {
/*东方财务网获取全部沪深京A股股票列表*/
if
(
!
function_exists
(
'Eastmoney_CN_List'
))
{
function
Eastmoney_HSJ_List
()
{
$host
=
"http://43.push2.eastmoney.com"
;
$url
=
$host
.
"/api/qt/clist/get?pn=1&pz=6000&po=1&np=1&fltt=2&invt=2&fid=f3&fs=m:0+t:6,m:0+t:80,m:1+t:2,m:1+t:23,m:0+t:81+s:2048&fields=f12,f13,f14"
;
$output
=
curl
(
$url
);
$url
=
"https://push2.eastmoney.com/api/qt/clist/get?np=1&fltt=2&invt=2&fields=f1,f2,f3,f4,f12,f13,f14&pn=1&fid=f3&po=1&fs=b:DLMK0144&pz=200"
;
// $host = "http://43.push2.eastmoney.com";
// $url = $host."/api/qt/clist/get?pn=1&pz=6000&po=1&np=1&fltt=2&invt=2&fid=f3&fs=m:0+t:6,m:0+t:80,m:1+t:2,m:1+t:23,m:0+t:81+s:2048&fields=f12,f13,f14";
// $url = 'http://stock.openapi.codemen.cn/getMarket?codes=100.HSI,100.HSCEI,100.HSAHP';
$output
=
curl
(
$url
);
// $response = file_get_contents($url);
var_dump
(
$output
);
die
;
$response
=
json_decode
(
$output
,
true
);
if
(
!
$response
[
'data'
][
'diff'
])
return
false
;
//dump($response['data']);exit;
...
...
@@ -838,9 +866,32 @@ if(!function_exists('Eastmoney_CN_List')) {
return
$json
;
}
}
if
(
!
function_exists
(
'get_curl'
))
{
/**
* @param $url
* @param string $data
* @return mixed
*/
function
get_curl
(
$url
,
$data
){
$ch
=
curl_init
();
curl_setopt
(
$ch
,
CURLOPT_URL
,
$url
);
curl_setopt
(
$ch
,
CURLOPT_HTTPHEADER
,
array
(
'Content-type:application/json;charset=UTF-8
'
));
curl_setopt
(
$ch
,
CURLOPT_RETURNTRANSFER
,
1
);
curl_setopt
(
$ch
,
CURLOPT_CUSTOMREQUEST
,
"get"
);
$output
=
curl_exec
(
$ch
);
curl_close
(
$ch
);
// $output = json_decode($output);
return
$output
;
}
}
/*东方财务网获取全部港股股票列表*/
if
(
!
function_exists
(
'Eastmoney_HK_List'
))
{
function
Eastmoney_HK_List
()
{
// https://push2.eastmoney.com/api/qt/clist/get?fltt=2&invt=2&fid=f3&fs=m:201+t:2&fields=f3,f4,f12,f13,f14,f128,f136&np=1&pn=1&po=1&pz=6
$host
=
"http://43.push2.eastmoney.com"
;
$url
=
$host
.
"/api/qt/clist/get?pn=1&pz=5000&po=1&np=1fltt=2&invt=2&fid=f3&fs=m:128+t:3,m:128+t:4,m:128+t:1,m:128+t:2&fields=f12,f13,f14"
;
$output
=
curl
(
$url
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment