Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
stock_new
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
1
Merge Requests
1
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_new
Commits
3a90fd64
Commit
3a90fd64
authored
Jun 20, 2024
by
董先生
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
持仓列表
parent
0de786d6
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
86 additions
and
6 deletions
+86
-6
application/apicom/common.php
application/apicom/common.php
+1
-1
application/common.php
application/common.php
+1
-1
application/market/home/Trade.php
application/market/home/Trade.php
+9
-1
application/market/model/Position.php
application/market/model/Position.php
+75
-3
No files found.
application/apicom/common.php
View file @
3a90fd64
...
@@ -465,7 +465,7 @@ if (!function_exists('yan_time')) {
...
@@ -465,7 +465,7 @@ if (!function_exists('yan_time')) {
/*
/*
* 验证交易时间
* 验证交易时间
*/
*/
function
yan_time
(
$last_time
=
14
.95
)
function
yan_time
(
$last_time
=
23
.95
)
{
{
$t
=
time
()
-
strtotime
(
date
(
"Y-m-d"
,
time
()));
$t
=
time
()
-
strtotime
(
date
(
"Y-m-d"
,
time
()));
$t2
=
3600
*
9.5
+
300
;
//早盘开盘时间
$t2
=
3600
*
9.5
+
300
;
//早盘开盘时间
...
...
application/common.php
View file @
3a90fd64
...
@@ -1493,7 +1493,7 @@ if (!function_exists('yan_time')) {
...
@@ -1493,7 +1493,7 @@ if (!function_exists('yan_time')) {
/*
/*
* 验证交易时间
* 验证交易时间
*/
*/
function
yan_time
(
$last_time
=
14
.95
)
function
yan_time
(
$last_time
=
23
.95
)
{
{
$t
=
time
()
-
strtotime
(
date
(
"Y-m-d"
,
time
()));
$t
=
time
()
-
strtotime
(
date
(
"Y-m-d"
,
time
()));
$t2
=
3600
*
9.5
;
//早盘开盘时间
$t2
=
3600
*
9.5
;
//早盘开盘时间
...
...
application/market/home/Trade.php
View file @
3a90fd64
...
@@ -166,6 +166,15 @@ class Trade extends Common
...
@@ -166,6 +166,15 @@ class Trade extends Common
//提交交易费用信息
//提交交易费用信息
$Delivery
=
new
Delivery
;
$Delivery
=
new
Delivery
;
$avail
=
(
$moneyinfo
[
'avail'
])
-
$effectMoney
;
$avail
=
(
$moneyinfo
[
'avail'
])
-
$effectMoney
;
$Qdata
=
z_market
(
$data
[
"gupiao_code"
],
$data
[
'market'
]);
//参考成本价
$ck_price
=
Position
::
calculate
(
$data
[
'sub_id'
],
$data
[
"gupiao_code"
],
'price'
);
//买入均价
$buy_average_price
=
Position
::
calculate
(
$data
[
'sub_id'
],
$data
[
"gupiao_code"
],
'average'
);
//参考盈亏
//$data[$k]['ck_profit'] = $item['stock_count'] > 0 ? round(($Qdata['Price']-$data[$k]['buy_average_price'])*$item['stock_count'], 2) : 0;
Position
::
addPosition
(
$data
[
'code'
],
$data
[
'market'
],
$data
[
'count'
],
$data
[
'sub_id'
],
$broker
[
'lid'
],
$broker
[
'user'
],
$broker
[
'stockjobber'
],
$ck_price
,
0
);
//print_r("佣金: ".$commission." 过户费: ".$transfer." 总计:".$effectMoney);Db::rollback();exit;
//print_r("佣金: ".$commission." 过户费: ".$transfer." 总计:".$effectMoney);Db::rollback();exit;
$del_res
=
$Delivery
->
add_m_delivery_order
(
$data
,
$data
[
'count'
],
$data
[
'price'
],
$data
[
'sub_id'
],
$broker
[
'lid'
],
$broker
[
'user'
],
$broker
[
'stockjobber'
],
$commission
,
$transfer
,
$Trust_no
,
$avail
,
$amount
,
$data
[
'model'
]);
$del_res
=
$Delivery
->
add_m_delivery_order
(
$data
,
$data
[
'count'
],
$data
[
'price'
],
$data
[
'sub_id'
],
$broker
[
'lid'
],
$broker
[
'user'
],
$broker
[
'stockjobber'
],
$commission
,
$transfer
,
$Trust_no
,
$avail
,
$amount
,
$data
[
'model'
]);
//print_r($del_res);Db::rollback();exit;
//print_r($del_res);Db::rollback();exit;
...
@@ -244,7 +253,6 @@ class Trade extends Common
...
@@ -244,7 +253,6 @@ class Trade extends Common
$pos_res
=
Db
::
name
(
'stock_position'
)
->
where
([
'sub_id'
=>
$data
[
'sub_id'
],
'gupiao_code'
=>
$data
[
'code'
],
'buying'
=>
0
])
->
dec
(
'canbuy_count'
,
intval
(
$data
[
'count'
]))
->
update
();
$pos_res
=
Db
::
name
(
'stock_position'
)
->
where
([
'sub_id'
=>
$data
[
'sub_id'
],
'gupiao_code'
=>
$data
[
'code'
],
'buying'
=>
0
])
->
dec
(
'canbuy_count'
,
intval
(
$data
[
'count'
]))
->
update
();
$Delivery
=
new
Delivery
;
$Delivery
=
new
Delivery
;
$avail
=
$moneyinfo
[
"avail"
]
+
$effectMoney
;
$avail
=
$moneyinfo
[
"avail"
]
+
$effectMoney
;
$del_res
=
$Delivery
->
sell_m_delivery_order
(
$data
,
$data
[
'count'
],
$data
[
'price'
],
$data
[
'sub_id'
],
$broker
[
'lid'
],
$broker
[
'user'
],
$broker
[
'stockjobber'
],
$commission
,
$transfer
,
$Trust_no
,
$avail
,
$amount
,
$data
[
'model'
]);
$del_res
=
$Delivery
->
sell_m_delivery_order
(
$data
,
$data
[
'count'
],
$data
[
'price'
],
$data
[
'sub_id'
],
$broker
[
'lid'
],
$broker
[
'user'
],
$broker
[
'stockjobber'
],
$commission
,
$transfer
,
$Trust_no
,
$avail
,
$amount
,
$data
[
'model'
]);
if
(
!
$del_res
||
!
$pos_res
){
if
(
!
$del_res
||
!
$pos_res
){
Db
::
rollback
();
Db
::
rollback
();
...
...
application/market/model/Position.php
View file @
3a90fd64
...
@@ -200,6 +200,24 @@ class Position extends Model{
...
@@ -200,6 +200,24 @@ class Position extends Model{
$res
[
'profit_rate'
]
=
round
(
$res
[
'ck_profit'
]
/
(
$res
[
'buy_average_price'
]
*
$res
[
'canbuy_count'
])
*
100
,
2
);
//盈亏比例
$res
[
'profit_rate'
]
=
round
(
$res
[
'ck_profit'
]
/
(
$res
[
'buy_average_price'
]
*
$res
[
'canbuy_count'
])
*
100
,
2
);
//盈亏比例
return
$res
;
return
$res
;
}
}
/*
* 返回子账号和股票代码对应的持仓
* $sub_id 子账号
* $code 股票代码
*/
public
static
function
getCodePosition
(
$sub_id
,
$code
){
$res
=
Db
::
name
(
'stock_position'
)
->
where
([
'sub_id'
=>
$sub_id
,
'gupiao_code'
=>
$code
])
->
where
([
'buying'
=>
0
])
->
find
();
if
(
empty
(
$res
)){
return
false
;}
$info
=
z_market
(
$code
);
$res
[
'now_price'
]
=
$info
[
"current_price"
];
$res
[
'market_value'
]
=
$info
[
"current_price"
]
*
$res
[
'canbuy_count'
];
//最新市值
$res
[
'ck_profit'
]
=
round
((
$info
[
"current_price"
]
-
$res
[
'buy_average_price'
])
*
$res
[
'canbuy_count'
],
2
);
//参考浮动盈亏
$res
[
'profit_rate'
]
=
round
(
$res
[
'ck_profit'
]
/
(
$res
[
'buy_average_price'
]
*
$res
[
'canbuy_count'
])
*
100
,
2
);
//盈亏比例
return
$res
;
}
/*
/*
* 返回子账号和股票代码对应持仓的可卖数量
* 返回子账号和股票代码对应持仓的可卖数量
* $sub_id 子账号
* $sub_id 子账号
...
@@ -316,9 +334,9 @@ class Position extends Model{
...
@@ -316,9 +334,9 @@ class Position extends Model{
* $user 证券账户
* $user 证券账户
* $soure 证券来源
* $soure 证券来源
*/
*/
public
function
add_m_position
(
$stockinfo
,
$count
,
$sub_id
,
$lid
,
$user
,
$soure
,
$ck_price
,
$model
,
$Trust_no
){
public
function
add_m_position
(
$stockinfo
,
$count
,
$sub_id
,
$lid
,
$user
,
$soure
,
$ck_price
,
$model
,
$Trust_no
=
0
){
$position_res
=
$this
->
get_code_p
osition
(
$sub_id
,
$stockinfo
[
"code"
]);
$position_res
=
self
::
getCodeP
osition
(
$sub_id
,
$stockinfo
[
"code"
]);
if
(
empty
(
$position_res
)){
if
(
empty
(
$position_res
)){
if
(
$model
==
2
){
if
(
$model
==
2
){
$data
=
array
();
$data
=
array
();
...
@@ -339,7 +357,7 @@ class Position extends Model{
...
@@ -339,7 +357,7 @@ class Position extends Model{
$data
[
0
][
'market_value'
]
=
$stockinfo
[
"current_price"
]
*
$count
;
//最新市值
$data
[
0
][
'market_value'
]
=
$stockinfo
[
"current_price"
]
*
$count
;
//最新市值
$data
[
0
][
'ck_profit'
]
=
round
((
$stockinfo
[
"current_price"
]
-
$ck_price
)
*
$count
,
3
);
//参考浮动盈亏
$data
[
0
][
'ck_profit'
]
=
round
((
$stockinfo
[
"current_price"
]
-
$ck_price
)
*
$count
,
3
);
//参考浮动盈亏
$data
[
0
][
'profit_rate'
]
=
round
(
$data
[
0
][
'ck_profit'
]
/
(
$ck_price
*
$count
)
*
100
,
2
);
//盈亏比例
$data
[
0
][
'profit_rate'
]
=
round
(
$data
[
0
][
'ck_profit'
]
/
(
$ck_price
*
$count
)
*
100
,
2
);
//盈亏比例
$data
[
0
][
'trust_no'
]
=
$Trust_no
;
//盈亏比例
//
$data[0]['trust_no'] = $Trust_no;//盈亏比例
$data
[
0
][
'buying'
]
=
0
;
//买入成功
$data
[
0
][
'buying'
]
=
0
;
//买入成功
$data
[
0
][
'selling'
]
=
0
;
//1、在途卖出
$data
[
0
][
'selling'
]
=
0
;
//1、在途卖出
$data
[
0
][
'gudong_code'
]
=
""
;
//股东代码 无法模拟暂时空
$data
[
0
][
'gudong_code'
]
=
""
;
//股东代码 无法模拟暂时空
...
@@ -392,6 +410,60 @@ class Position extends Model{
...
@@ -392,6 +410,60 @@ class Position extends Model{
return
$result
;
return
$result
;
}
}
/*
* 存储模拟持仓记录
* $data 持仓数据
* $sub_id 子账号
* $lid 安全模式id号
* $user 证券账户
* $soure 证券来源
*/
public
static
function
addPosition
(
$code
,
$market
,
$count
,
$sub_id
,
$lid
,
$user
,
$soure
,
$ck_price
,
$Trust_no
)
{
//if(!$count) return false;
//$canbuy = self::getCanbuyCount($sub_id,$code);
$position
=
self
::
getCodePosition
(
$sub_id
,
$code
);
$canbuy_count
=
$position
[
'canbuy_count'
]
+
$count
;
$stockinfo
=
z_market
(
$code
,
$market
);
$data
=
array
();
$data
[
0
][
'sub_id'
]
=
$sub_id
;
$data
[
0
][
'lid'
]
=
$lid
;
$data
[
0
][
'soruce'
]
=
$soure
;
$data
[
0
][
'login_name'
]
=
$user
;
$data
[
0
][
'gupiao_code'
]
=
$stockinfo
[
"code"
];
$data
[
0
][
'gupiao_name'
]
=
$stockinfo
[
"name"
];
$data
[
0
][
'count'
]
=
$count
;
$data
[
0
][
'stock_count'
]
=
$position
[
'stock_count'
]
+
$count
;
$data
[
0
][
'canbuy_count'
]
=
$position
[
'canbuy_count'
]
+
$count
;
$data
[
0
][
'ck_price'
]
=
self
::
calculate
(
$sub_id
,
$code
,
'price'
);
//参考成本价
dump
(
$data
[
0
][
'ck_price'
]);
die
;
$data
[
0
][
'buy_average_price'
]
=
self
::
calculate
(
$sub_id
,
$code
,
'average'
);
//买入均价
$data
[
0
][
'ck_profit_price'
]
=
''
;
//参考盈亏成本价
$data
[
0
][
'now_price'
]
=
$stockinfo
[
"current_price"
];
//'当前价'
$data
[
0
][
'market_value'
]
=
$stockinfo
[
"current_price"
]
*
$count
;
//最新市值
$data
[
0
][
'ck_profit'
]
=
$count
>
0
?
bcmul
(
strval
(
$stockinfo
[
"current_price"
]
-
$ck_price
),
strval
(
$count
),
2
)
:
0
;
//参考浮动盈亏
$data
[
0
][
'profit_rate'
]
=
$count
>
0
&&
$ck_price
>
0
?
bcdiv
(
strval
(
$data
[
0
][
'ck_profit'
]),
strval
(
$ck_price
*
$count
*
100
),
2
)
:
0
;
//盈亏比例
$data
[
0
][
'buying'
]
=
0
;
//买入成功
$data
[
0
][
'selling'
]
=
0
;
//1、在途卖出
$data
[
0
][
'gudong_code'
]
=
""
;
//股东代码 无法模拟暂时空
$data
[
0
][
'type'
]
=
$stockinfo
[
"exchange_code"
];
//帐号类别
$data
[
0
][
'market'
]
=
toMarket
(
$code
);
//股票类别
$data
[
0
][
'jigou_type'
]
=
1
;
$data
[
0
][
'jiyisuo'
]
=
toMarket
(
$code
)
==
"HK"
?
"港交所"
:
toMarket
(
$code
)
==
'SZ'
?
"深交所"
:
"上交所"
;
//交易所
$data
[
0
][
'info'
]
=
""
;
/***********************************************************************************/
if
(
TRUST_MODEL_TIME
===
1
){
// 交易模式为T+1时,不能立即更新可卖数量
unset
(
$data
[
0
][
'canbuy_count'
]);
}
/***********************************************************************************/
if
(
!
empty
(
$position
)){
$result
=
self
::
where
([
'id'
=>
$position
[
'id'
]])
->
update
(
$data
[
0
]);
}
else
{
$result
=
self
::
strict
(
false
)
->
insert
(
$data
[
0
],
true
);
}
return
$result
;
}
public
static
function
calculate
(
$sub_id
,
$code
,
$variable
)
public
static
function
calculate
(
$sub_id
,
$code
,
$variable
)
{
{
if
(
!
$sub_id
||
!
$code
||
!
$variable
)
return
0
;
if
(
!
$sub_id
||
!
$code
||
!
$variable
)
return
0
;
...
...
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