Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
token
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wallet
token
Commits
6f8d6cb6
Commit
6f8d6cb6
authored
Oct 18, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into feature/issue_coin
parents
32ff472b
12b7c8a8
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
35 additions
and
23 deletions
+35
-23
TickerController.php
api/controllers/TickerController.php
+24
-14
CoinOptional.php
common/models/psources/CoinOptional.php
+7
-5
BinanceBuilder.php
common/service/exchange/factory/BinanceBuilder.php
+1
-1
FactoryService.php
common/service/exchange/factory/FactoryService.php
+1
-1
HuobiBuilder.php
common/service/exchange/factory/HuobiBuilder.php
+1
-1
ZhaobiBuilder.php
common/service/exchange/factory/ZhaobiBuilder.php
+1
-1
No files found.
api/controllers/TickerController.php
View file @
6f8d6cb6
...
...
@@ -20,11 +20,13 @@ class TickerController extends BaseController
{
$page
=
Yii
::
$app
->
request
->
get
(
'page'
,
1
);
$device_code
=
Yii
::
$app
->
request
->
get
(
'device_code'
,
''
);
$platform_id
=
Yii
::
$app
->
request
->
get
(
'device_code'
,
0
);
$exchange
=
Yii
::
$app
->
request
->
get
(
'exchange'
,
'zhaobi'
);
$data_value
=
Yii
::
$app
->
request
->
get
(
'data-value'
,
''
);
$sort
=
Yii
::
$app
->
request
->
get
(
'sort'
,
''
);
$data_value
=
Yii
::
$app
->
request
->
get
(
'data-value'
,
''
);
$sort
=
Yii
::
$app
->
request
->
get
(
'sort'
,
''
);
$exchange_arr
=
[
'huobi'
,
'binance'
,
'okex'
,
'zhaobi'
];
if
(
!
in_array
(
$exchange
,
$exchange_arr
))
{
$msg
=
'不存在的交易平台'
;
$code
=
-
1
;
...
...
@@ -37,7 +39,12 @@ class TickerController extends BaseController
$data
=
$result
[
'data'
];
if
(
false
!=
$device_code
)
{
$coin_optional
=
CoinOptional
::
find
()
->
select
(
'symbol'
)
->
where
([
'platform'
=>
$exchange
,
'device_code'
=>
$device_code
])
->
asArray
()
->
all
();
if
(
false
!=
$platform_id
)
{
$coin_optional
=
CoinOptional
::
find
()
->
select
(
'symbol'
)
->
where
([
'platform'
=>
$exchange
,
'device_code'
=>
$device_code
])
->
asArray
()
->
all
();
}
else
{
$coin_optional
=
CoinOptional
::
find
()
->
select
(
'symbol'
)
->
where
([
'platform'
=>
$exchange
,
'device_code'
=>
$device_code
,
'platform_id'
=>
$platform_id
])
->
asArray
()
->
all
();
}
$coin_optional
=
ArrayHelper
::
getColumn
(
$coin_optional
,
'symbol'
);
foreach
(
$data
[
'ticker'
]
as
&
$val
)
{
if
(
in_array
(
$val
[
'symbol'
],
$coin_optional
))
{
...
...
@@ -66,7 +73,7 @@ class TickerController extends BaseController
$params
=
json_encode
(
$data
);
$curl
->
setHeader
(
'Content-Type'
,
'application/json'
);
$curl
->
setRawPostData
(
$params
);
$res
=
$curl
->
post
(
'https://b.biqianbao.net
/interface/coin/coin-index'
,
true
);
$res
=
$curl
->
post
(
Yii
::
$app
->
params
[
'biqianbao'
]
.
'
/interface/coin/coin-index'
,
true
);
$res
=
json_decode
(
$res
,
true
);
foreach
(
$res
[
'data'
]
as
$val
)
{
$this
->
basic_price
[
$val
[
'name'
]][
'rmb'
]
=
$val
[
'rmb'
];
...
...
@@ -82,12 +89,13 @@ class TickerController extends BaseController
$symbol
=
$request
->
post
(
'symbol'
,
''
);
$platform
=
$request
->
post
(
'platform'
,
''
);
$device_code
=
$request
->
post
(
'device_code'
,
''
);
$platform_id
=
$request
->
post
(
'platform_id'
,
0
);
if
(
empty
(
$symbol
)
||
empty
(
$platform
)
||
empty
(
$device_code
))
{
if
(
empty
(
$symbol
)
||
empty
(
$platform
)
||
empty
(
$device_code
)
||
empty
(
$platform_id
)
)
{
$msg
=
'参数错误'
;
goto
doEnd
;
}
$model
=
CoinOptional
::
find
()
->
where
([
'device_code'
=>
$device_code
,
'symbol'
=>
$symbol
])
->
one
();
$model
=
CoinOptional
::
find
()
->
where
([
'device_code'
=>
$device_code
,
'symbol'
=>
$symbol
,
'platform_id'
=>
(
int
)
$platform_id
])
->
one
();
if
(
$model
)
{
$msg
=
'数据已存在!'
;
goto
doEnd
;
...
...
@@ -106,14 +114,15 @@ class TickerController extends BaseController
if
(
$request
->
isGet
)
{
$device_code
=
$request
->
get
(
'device_code'
,
''
);
$platform_id
=
$request
->
get
(
'platform_id'
,
0
);
$page
=
Yii
::
$app
->
request
->
get
(
'page'
,
1
);
if
(
empty
(
$device_code
)
)
{
if
(
false
==
$device_code
||
false
==
$platform_id
)
{
$msg
=
'参数错误'
;
goto
doEnd
;
}
$temp
=
[];
$query
=
CoinOptional
::
find
()
->
select
(
'symbol, platform'
)
->
where
([
'device_code'
=>
$device_code
])
->
where
([
'device_code'
=>
$device_code
,
'platform_id'
=>
(
int
)
$platform_id
])
->
orderBy
(
'update_time desc'
);
$data
=
$query
->
offset
((
$page
-
1
)
*
50
)
->
limit
(
50
)
->
asArray
()
->
all
();
if
(
false
==
$data
)
{
...
...
@@ -122,7 +131,7 @@ class TickerController extends BaseController
$data
=
[
'ticker'
=>
[],
'page'
=>
[
'pageSize'
=>
50
,
'pageSize'
=>
50
,
'currentPage'
=>
(
int
)
$page
,
]
];
...
...
@@ -145,14 +154,14 @@ class TickerController extends BaseController
$exchange
=
ExchangeFactory
::
createExchange
(
$exchange
);
$quotation
=
$exchange
->
getTicker
(
strtolower
(
$tag_first
),
strtolower
(
$tag_second
));
if
(
empty
(
$quotation
))
continue
;
if
(
empty
(
$quotation
))
continue
;
$temp
[
'symbol'
]
=
$val
[
'symbol'
];
$temp
[
'currency'
]
=
strtoupper
(
$tag_first
);
$temp
[
'base_currency'
]
=
strtoupper
(
$tag_second
);
$temp
[
'close'
]
=
number_format
(
$quotation
[
'last'
],
6
,
'.'
,
''
);
$temp
[
'close_usd'
]
=
(
float
)
sprintf
(
"%0.6f"
,
$quotation
[
'last'
]
*
$this
->
basic_price
[
$tag_second
][
'usd'
]);
$temp
[
'close_rmb'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$quotation
[
'last'
]
*
$this
->
basic_price
[
$tag_second
][
'rmb'
]);
$temp
[
'change'
]
=
(
0
==
$quotation
[
'open'
])
?
0
:
(
float
)
sprintf
(
"%0.
4
f"
,
(
$quotation
[
'last'
]
-
$quotation
[
'open'
])
/
$quotation
[
'open'
]
*
100
);
$temp
[
'change'
]
=
(
0
==
$quotation
[
'open'
])
?
0
:
(
float
)
sprintf
(
"%0.
2
f"
,
(
$quotation
[
'last'
]
-
$quotation
[
'open'
])
/
$quotation
[
'open'
]
*
100
);
$temp
[
'high_usd'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$quotation
[
'high'
]
*
$this
->
basic_price
[
$tag_second
][
'usd'
]);
$temp
[
'low_usd'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$quotation
[
'low'
]
*
$this
->
basic_price
[
$tag_second
][
'usd'
]);
$temp
[
'high_rmb'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$quotation
[
'high'
]
*
$this
->
basic_price
[
$tag_second
][
'rmb'
]);
...
...
@@ -179,7 +188,7 @@ class TickerController extends BaseController
$data
=
[
'ticker'
=>
$ticker
,
'page'
=>
[
'pageSize'
=>
50
,
'pageSize'
=>
50
,
'currentPage'
=>
(
int
)
$page
,
]
];
...
...
@@ -205,11 +214,12 @@ class TickerController extends BaseController
$symbol
=
$request
->
post
(
'symbol'
,
''
);
$platform
=
$request
->
post
(
'platform'
,
''
);
$device_code
=
$request
->
post
(
'device_code'
,
''
);
if
(
empty
(
$symbol
)
||
empty
(
$device_code
)
||
empty
(
$platform
))
{
$platform_id
=
$request
->
post
(
'platform_id'
,
0
);
if
(
empty
(
$symbol
)
||
empty
(
$device_code
)
||
empty
(
$platform
)
||
empty
(
$platform_id
))
{
$msg
=
'请求参数错误!'
;
goto
doEnd
;
}
$model
=
CoinOptional
::
find
()
->
where
([
'symbol'
=>
$symbol
,
'platform'
=>
$platform
,
'device_code'
=>
$device_code
])
->
one
();
$model
=
CoinOptional
::
find
()
->
where
([
'symbol'
=>
$symbol
,
'platform'
=>
$platform
,
'device_code'
=>
$device_code
,
'platform_id'
=>
(
int
)
$platform_id
])
->
one
();
if
(
empty
(
$model
))
{
$msg
=
'数据不存在!'
;
goto
doEnd
;
...
...
common/models/psources/CoinOptional.php
View file @
6f8d6cb6
...
...
@@ -21,16 +21,18 @@ class CoinOptional extends BaseActiveRecord
const
SCENARIOS_CREATE
=
'create'
;
public
function
rules
()
{
public
function
rules
()
{
return
[
[[
'symbol'
,
'platform'
,
'device_code
'
],
'required'
],
[[
'symbol'
,
'platform'
,
'device_code'
,
'platform_id
'
],
'required'
],
];
}
public
function
scenarios
()
{
public
function
scenarios
()
{
$scenarios
=
[
self
::
SCENARIOS_CREATE
=>
[
'symbol'
,
'platform'
,
'device_code
'
],
self
::
SCENARIOS_CREATE
=>
[
'symbol'
,
'platform'
,
'device_code'
,
'platform_id
'
],
];
return
array_merge
(
parent
::
scenarios
(),
$scenarios
);
return
array_merge
(
parent
::
scenarios
(),
$scenarios
);
}
}
common/service/exchange/factory/BinanceBuilder.php
View file @
6f8d6cb6
...
...
@@ -90,7 +90,7 @@ class BinanceBuilder extends FactoryService
$temp
[
'close'
]
=
number_format
(
$close
,
6
,
'.'
,
''
);
$temp
[
'close_usd'
]
=
(
float
)
sprintf
(
"%0.6f"
,
$close
*
$this
->
basic_price
[
$coin
][
'usd'
]);
$temp
[
'close_rmb'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$close
*
$this
->
basic_price
[
$coin
][
'rmb'
]);
$temp
[
'change'
]
=
(
0
==
$open
)
?
0
:
(
float
)
sprintf
(
"%0.
4
f"
,
(
$close
-
$open
)
/
$open
*
100
);
$temp
[
'change'
]
=
(
0
==
$open
)
?
0
:
(
float
)
sprintf
(
"%0.
2
f"
,
(
$close
-
$open
)
/
$open
*
100
);
$temp
[
'high_usd'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$high
*
$this
->
basic_price
[
$coin
][
'usd'
]);
$temp
[
'low_usd'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$low
*
$this
->
basic_price
[
$coin
][
'usd'
]);
$temp
[
'high_rmb'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$high
*
$this
->
basic_price
[
$coin
][
'rmb'
]);
...
...
common/service/exchange/factory/FactoryService.php
View file @
6f8d6cb6
...
...
@@ -35,7 +35,7 @@ abstract class FactoryService
$params
=
json_encode
(
$data
);
$curl
->
setHeader
(
'Content-Type'
,
'application/json'
);
$curl
->
setRawPostData
(
$params
);
$res
=
$curl
->
post
(
'http://127.0.0.1:8082
/interface/coin/coin-index'
,
true
);
$res
=
$curl
->
post
(
\Yii
::
$app
->
params
[
'biqianbao'
]
.
'
/interface/coin/coin-index'
,
true
);
$res
=
json_decode
(
$res
,
true
);
foreach
(
$res
[
'data'
]
as
$val
)
{
...
...
common/service/exchange/factory/HuobiBuilder.php
View file @
6f8d6cb6
...
...
@@ -90,7 +90,7 @@ class HuobiBuilder extends FactoryService
$temp
[
'close'
]
=
number_format
(
$close
,
6
,
'.'
,
''
);
$temp
[
'close_usd'
]
=
(
float
)
sprintf
(
"%0.6f"
,
$close
*
$this
->
basic_price
[
$coin
][
'usd'
]);
$temp
[
'close_rmb'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$close
*
$this
->
basic_price
[
$coin
][
'rmb'
]);
$temp
[
'change'
]
=
(
false
==
$open
)
?
0
:
(
float
)
sprintf
(
"%0.
4
f"
,
(
$close
-
$open
)
/
$open
*
100
);
$temp
[
'change'
]
=
(
false
==
$open
)
?
0
:
(
float
)
sprintf
(
"%0.
2
f"
,
(
$close
-
$open
)
/
$open
*
100
);
$temp
[
'high_usd'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$high
*
$this
->
basic_price
[
$coin
][
'usd'
]);
$temp
[
'low_usd'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$low
*
$this
->
basic_price
[
$coin
][
'usd'
]);
$temp
[
'high_rmb'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$high
*
$this
->
basic_price
[
$coin
][
'rmb'
]);
...
...
common/service/exchange/factory/ZhaobiBuilder.php
View file @
6f8d6cb6
...
...
@@ -41,7 +41,7 @@ class ZhaobiBuilder extends FactoryService
$temp
[
'close'
]
=
number_format
(
$val
[
'last'
],
6
,
'.'
,
''
);
$temp
[
'close_usd'
]
=
(
float
)
sprintf
(
"%0.6f"
,
$val
[
'last'
]
*
$this
->
basic_price
[
$coin
][
'usd'
]);
$temp
[
'close_rmb'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'last'
]
*
$this
->
basic_price
[
$coin
][
'rmb'
]);
$temp
[
'change'
]
=
(
0
==
$val
[
'open'
])
?
0
:
(
float
)
sprintf
(
"%0.
4
f"
,
(
$val
[
'last'
]
-
$val
[
'open'
])
/
$val
[
'open'
]
*
100
);
$temp
[
'change'
]
=
(
0
==
$val
[
'open'
])
?
0
:
(
float
)
sprintf
(
"%0.
2
f"
,
(
$val
[
'last'
]
-
$val
[
'open'
])
/
$val
[
'open'
]
*
100
);
$temp
[
'high_usd'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'high'
]
*
$this
->
basic_price
[
$coin
][
'usd'
]);
$temp
[
'low_usd'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'low'
]
*
$this
->
basic_price
[
$coin
][
'usd'
]);
$temp
[
'high_rmb'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'high'
]
*
$this
->
basic_price
[
$coin
][
'rmb'
]);
...
...
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