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
8676c3a4
Commit
8676c3a4
authored
May 28, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/hl_ticker' into 'master'
new ticker api See merge request
!20
parents
8535b81f
bafe4d34
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
84 additions
and
1 deletion
+84
-1
ExchangeBusiness.php
common/business/ExchangeBusiness.php
+9
-1
Zg.php
common/service/exchange/Zg.php
+75
-0
No files found.
common/business/ExchangeBusiness.php
View file @
8676c3a4
...
...
@@ -33,7 +33,8 @@ class ExchangeBusiness
4
=>
'Bittrex'
,
5
=>
'Zb'
,
6
=>
'Token7'
,
7
=>
'S'
7
=>
'S'
,
8
=>
'Zg'
];
/**
...
...
@@ -96,6 +97,13 @@ class ExchangeBusiness
return
$quotation
;
}
if
(
in_array
(
strtoupper
(
$tag
),[
'GHP'
])){
$exchange
=
ExchangeFactory
::
createExchange
(
"Zg"
);
$quotation
=
$exchange
->
getTicker
(
$tag
,
'CNZ'
);
$quotation
[
'rmb'
]
=
(
float
)
sprintf
(
"%0.2f"
,
$quotation
[
'last'
]);
return
$quotation
;
}
foreach
(
self
::
$exchanges
as
$exchange
)
{
/**
* @var $exchange \common\service\exchange\Exchange
...
...
common/service/exchange/Zg.php
0 → 100644
View file @
8676c3a4
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-8-7
* Time: 上午11:30
*/
namespace
common\service\exchange
;
use
linslin\yii2\curl\Curl
;
class
Zg
extends
Exchange
implements
ExchangeInterface
{
protected
$supported_symbol
=
'supported_symbol_zg'
;
protected
$quotation_prefix
=
'quotation_zg_'
;
protected
$base_url
=
'https://www.zg.com/api/v1/tickers'
;
public
function
symbolExists
(
$tag
=
'HL'
,
$aim
=
"USDT"
)
{
$supported
=
$this
->
redis
->
smembers
(
$this
->
supported_symbol
);
if
(
is_array
(
$supported
)
&&
in_array
(
$this
->
formatSymbol
(
$tag
,
$aim
),
$supported
))
{
return
true
;
}
return
false
;
}
/**
* 转化交易对为请求变量
*
* @param string $tag
* @param string $aim
* @return mixed
*/
public
function
formatSymbol
(
$tag
=
'HL'
,
$aim
=
'USDT'
)
{
return
strtoupper
(
$tag
.
'_'
.
$aim
);
}
/**
* 保存支持的交易对到redis数据库,使用crontab定时更新
*
* @return mixed|void
*/
public
function
setSupportedSymbol
()
{
$this
->
redis
->
sadd
(
$this
->
supported_symbol
,
'HL_USDT'
);
}
/**
* 更新交易对行情保存到redis,使用crontab定时更新
*
* @return mixed|void
*/
public
function
setQuotation
()
{
$curl
=
new
Curl
();
$curl
->
setHeaders
([
'User-Agent'
=>
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36'
,
]);
$content
=
$curl
->
get
(
$this
->
base_url
,
false
);
if
(
is_array
(
$content
)
&&
isset
(
$content
[
'ticker'
]))
{
$data
=
$content
[
'ticker'
];
foreach
(
$data
as
$item
)
{
if
(
in_array
(
$item
[
'symbol'
],
[
'HL_USDT'
,
'GHP_CNZ'
]))
{
$data
=
$item
;
$key
=
$this
->
quotation_prefix
.
$item
[
'symbol'
];
$this
->
redis
->
hmset
(
$key
,
'low'
,
$data
[
'low'
],
'high'
,
$data
[
'high'
],
'last'
,
$data
[
'last'
]);
$this
->
redis
->
sadd
(
$this
->
supported_symbol
,
$item
[
'symbol'
]);
}
}
}
}
}
\ No newline at end of file
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