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
95db9035
Commit
95db9035
authored
Sep 17, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
行情
parent
1da8cd6d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
1 deletion
+37
-1
TickerController.php
api/controllers/TickerController.php
+1
-1
HuobiBuilder.php
common/service/exchange/factory/HuobiBuilder.php
+36
-0
No files found.
api/controllers/TickerController.php
View file @
95db9035
...
...
@@ -49,7 +49,7 @@ class TickerController extends BaseController
goto
doEnd
;
}
$builder
=
ExchangeBuilderFactory
::
create
(
$exchange
);
$result
=
$builder
->
getTicker
();
$result
=
$builder
->
getTicker
FromCache
();
$code
=
$result
[
'code'
];
$data
=
$result
[
'ticker'
];
...
...
common/service/exchange/factory/HuobiBuilder.php
View file @
95db9035
...
...
@@ -13,6 +13,8 @@ use linslin\yii2\curl\Curl;
class
HuobiBuilder
extends
FactoryService
{
protected
$base_url
=
'https://api.huobi.pro'
;
protected
$supported_symbol
=
'supported_symbol_huobi'
;
protected
$quotation_prefix
=
'quotation_huobi_'
;
public
function
getTicker
()
{
...
...
@@ -51,6 +53,40 @@ class HuobiBuilder extends FactoryService
return
[
'code'
=>
$this
->
code
,
'ticker'
=>
$ticker
];
}
public
function
getTickerFromCache
()
{
$redis
=
\Yii
::
$app
->
redis
;
$keys
=
$redis
->
smembers
(
$this
->
supported_symbol
);
$ticker
=
[];
foreach
(
$keys
as
$val
)
{
foreach
(
$this
->
basic_coin
as
$k
=>
$coin
)
{
$explode_arr
=
explode
(
strtolower
(
$coin
),
$val
);
if
(
2
==
count
(
$explode_arr
)
&&
empty
(
$explode_arr
[
1
]))
{
list
(
$low
,
$high
,
$close
,
$open
,
$vol
)
=
$redis
->
hmget
(
$this
->
quotation_prefix
.
strtolower
(
$val
),
'low'
,
'high'
,
'last'
,
'open'
,
'vol'
);
$temp
=
[];
$temp
[
'symbol'
]
=
strtoupper
(
$explode_arr
[
0
])
.
'/'
.
$coin
;
$temp
[
'currency'
]
=
strtoupper
(
$explode_arr
[
0
]);
$temp
[
'base_currency'
]
=
strtoupper
(
$coin
);
$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.4f"
,
(
$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'
]);
$temp
[
'low_rmb'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$low
*
$this
->
basic_price
[
$coin
][
'rmb'
]);
$temp
[
'vol'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$vol
);
$temp
[
'optional'
]
=
false
;
$temp
[
'platform_zh'
]
=
'火币'
;
$temp
[
'platform_us'
]
=
'huoBi'
;
array_push
(
$ticker
,
$temp
);
}
}
}
echo
json_encode
(
$ticker
);
exit
;
}
public
function
getHotTicker
()
{
$curl
=
new
Curl
();
...
...
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