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
f870841c
Commit
f870841c
authored
Aug 23, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/ticker' into 'master'
add new tsc ticker See merge request
!94
parents
dc3d70cb
bb2ed89b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
82 additions
and
2 deletions
+82
-2
ExchangeBusiness.php
common/business/ExchangeBusiness.php
+10
-2
Tsc.php
common/service/exchange/Tsc.php
+72
-0
No files found.
common/business/ExchangeBusiness.php
View file @
f870841c
...
...
@@ -40,7 +40,8 @@ class ExchangeBusiness
11
=>
'Gdpro'
,
12
=>
'Boc'
,
13
=>
'Ex'
,
14
=>
'Zt'
14
=>
'Zt'
,
15
=>
'Tsc'
];
/**
...
...
@@ -83,7 +84,7 @@ class ExchangeBusiness
goto
doEnd
;
}
if
(
strtoupper
(
$tag
)
==
'RYH'
||
strtoupper
(
$tag
)
==
'
TSC'
||
strtoupper
(
$tag
)
==
'
WL'
||
strtoupper
(
$tag
)
==
'ETS'
||
strtoupper
(
$tag
)
==
'LIMS'
||
strtoupper
(
$tag
)
==
'AT'
||
strtoupper
(
$tag
)
==
'BTJ'
)
{
if
(
strtoupper
(
$tag
)
==
'RYH'
||
strtoupper
(
$tag
)
==
'WL'
||
strtoupper
(
$tag
)
==
'ETS'
||
strtoupper
(
$tag
)
==
'LIMS'
||
strtoupper
(
$tag
)
==
'AT'
||
strtoupper
(
$tag
)
==
'BTJ'
)
{
$quotation
=
[
'low'
=>
0
,
'high'
=>
0
,
...
...
@@ -164,6 +165,13 @@ class ExchangeBusiness
goto
doEnd
;
}
if
(
in_array
(
strtoupper
(
$tag
),
[
'TSC'
]))
{
$exchange
=
ExchangeFactory
::
createExchange
(
"Tsc"
);
$quotation
=
$exchange
->
getTicker
(
'TSC'
,
'CNDT'
);
$quotation
[
'rmb'
]
=
(
float
)
sprintf
(
"%0.2f"
,
$quotation
[
'last'
]);
goto
doEnd
;
}
if
(
in_array
(
strtoupper
(
$tag
),
[
'SJPY'
]))
{
$exchange
=
ExchangeFactory
::
createExchange
(
"Boc"
);
$quotation
=
$exchange
->
getTicker
(
'CNY'
,
'JPY'
);
...
...
common/service/exchange/Tsc.php
0 → 100644
View file @
f870841c
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-8-7
* Time: 上午11:30
*/
namespace
common\service\exchange
;
use
linslin\yii2\curl\Curl
;
class
Tsc
extends
Exchange
implements
ExchangeInterface
{
protected
$supported_symbol
=
'supported_symbol_tsc'
;
protected
$quotation_prefix
=
'quotation_tsc_'
;
protected
$base_url
=
'https://api.tsc100.vip/openapi/quote/v1/ticker/24hr'
;
public
function
symbolExists
(
$tag
=
'TSC'
,
$aim
=
"CNDT"
)
{
$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
=
'TSC'
,
$aim
=
'CNDT'
)
{
return
strtoupper
(
$tag
.
'_'
.
$aim
);
}
/**
* 保存支持的交易对到redis数据库,使用crontab定时更新
*
* @return mixed|void
*/
public
function
setSupportedSymbol
()
{
$this
->
redis
->
sadd
(
$this
->
supported_symbol
,
'TSCCNDT'
);
}
/**
* 更新交易对行情保存到redis,使用crontab定时更新
*
* @return mixed|void
*/
public
function
setQuotation
()
{
$curl
=
new
Curl
();
$content
=
$curl
->
get
(
$this
->
base_url
,
false
);
if
(
is_array
(
$content
))
{
foreach
(
$content
as
$item
)
{
if
(
in_array
(
$item
[
'symbol'
],
[
'TSCCNDT'
]))
{
$data
=
$item
;
$key
=
$this
->
quotation_prefix
.
$item
[
'symbol'
];
$this
->
redis
->
hmset
(
$key
,
'low'
,
$data
[
'lowPrice'
],
'high'
,
$data
[
'highPrice'
],
'last'
,
$data
[
'lastPrice'
]);
$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