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
5fbea1bc
Commit
5fbea1bc
authored
Nov 22, 2018
by
rlgy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bugfix
parent
22a4e81b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
10 deletions
+26
-10
ExchangeBusiness.php
common/business/ExchangeBusiness.php
+26
-10
No files found.
common/business/ExchangeBusiness.php
View file @
5fbea1bc
...
@@ -12,14 +12,17 @@ use common\models\psources\Coin;
...
@@ -12,14 +12,17 @@ use common\models\psources\Coin;
use
common\service\coin\CoinFactory
;
use
common\service\coin\CoinFactory
;
use
common\service\exchange\ExchangeFactory
;
use
common\service\exchange\ExchangeFactory
;
use
Yii
;
use
Yii
;
/**
/**
* Class ExchangeBusiness
* Class ExchangeBusiness
* 各大交易所交易所api逻辑层
* 各大交易所交易所api逻辑层
*
* @package common\business
* @package common\business
*/
*/
class
ExchangeBusiness
class
ExchangeBusiness
{
{
/**支持的交易所
/**支持的交易所
*
* @var array
* @var array
*/
*/
private
static
$exchanges
=
[
private
static
$exchanges
=
[
...
@@ -33,8 +36,9 @@ class ExchangeBusiness
...
@@ -33,8 +36,9 @@ class ExchangeBusiness
/**
/**
* 获取行情
* 获取行情
* @param string $tag 目标币种
*
* @param string $aim 计数币种
* @param string $tag 目标币种
* @param string $aim 计数币种
* @return array|bool
* @return array|bool
*/
*/
public
static
function
getquatation
(
$tag
=
'btc'
,
$aim
=
''
)
public
static
function
getquatation
(
$tag
=
'btc'
,
$aim
=
''
)
...
@@ -64,7 +68,7 @@ class ExchangeBusiness
...
@@ -64,7 +68,7 @@ class ExchangeBusiness
if
(
$exchange
->
symbolExists
(
$tag
,
'btc'
))
{
if
(
$exchange
->
symbolExists
(
$tag
,
'btc'
))
{
$price_btc
=
$exchange
->
getTicker
(
$tag
,
'btc'
);
$price_btc
=
$exchange
->
getTicker
(
$tag
,
'btc'
);
//获取btcusdt
//获取btcusdt
$result
=
array_map
(
function
(
$a
,
$b
)
{
$result
=
array_map
(
function
(
$a
,
$b
)
{
return
$a
*
$b
;
return
$a
*
$b
;
},
$price_btc
,
$btc_usd
);
},
$price_btc
,
$btc_usd
);
$quotation
=
[
'low'
=>
$result
[
0
],
'high'
=>
$result
[
1
],
'last'
=>
$result
[
2
]];
$quotation
=
[
'low'
=>
$result
[
0
],
'high'
=>
$result
[
1
],
'last'
=>
$result
[
2
]];
...
@@ -78,14 +82,22 @@ class ExchangeBusiness
...
@@ -78,14 +82,22 @@ class ExchangeBusiness
}
}
//格式化行情数据
//格式化行情数据
foreach
(
$quotation
as
$key
=>
$item
)
{
foreach
(
$quotation
as
$key
=>
$item
)
{
$quotation
[
$key
]
=
(
float
)
sprintf
(
"%0.4f"
,
(
double
)
$item
);
$quotation
[
$key
]
=
(
float
)
sprintf
(
"%0.4f"
,
(
double
)
$item
);
}
}
$quotation
[
'rmb'
]
=
(
float
)
sprintf
(
"%0.2f"
,
6.6
*
$quotation
[
'last'
]);
//用YCC计算汇率
/**
* @var $exchange \common\service\exchange\Exchange
*/
$exchange
=
ExchangeFactory
::
createExchange
(
"Bty"
);
$rate
=
$exchange
->
getTicker
(
"BTY"
,
"USDT"
);
$rate
=
(
float
)
$rate
[
'rmb'
]
/
$rate
[
'last'
];
$quotation
[
'rmb'
]
=
(
float
)
sprintf
(
"%0.2f"
,
$rate
*
$quotation
[
'last'
]);
return
$quotation
;
return
$quotation
;
}
}
/**
/**
* 保存各个交易所支持的交易对到redis,定时用crontab更新
* 保存各个交易所支持的交易对到redis,定时用crontab更新
*
* @return void
* @return void
*/
*/
public
static
function
setSupportedSymbol
()
public
static
function
setSupportedSymbol
()
...
@@ -101,6 +113,7 @@ class ExchangeBusiness
...
@@ -101,6 +113,7 @@ class ExchangeBusiness
/**
/**
* 更新交易所的行情数据保存到redis,定时更新
* 更新交易所的行情数据保存到redis,定时更新
*
* @return void
* @return void
*/
*/
public
static
function
setQuotation
()
public
static
function
setQuotation
()
...
@@ -116,12 +129,13 @@ class ExchangeBusiness
...
@@ -116,12 +129,13 @@ class ExchangeBusiness
/**
/**
* 根据name返回币种信息
* 根据name返回币种信息
* @param array $condition 需要的币种sid列表
*
* @param array $condition 需要的币种sid列表
* @return array
* @return array
*/
*/
public
static
function
getApiListForIndex
(
$page
=
1
,
$limit
=
999
,
$condition
=
[])
public
static
function
getApiListForIndex
(
$page
=
1
,
$limit
=
999
,
$condition
=
[])
{
{
$rows
=
Coin
::
getSelectList
(
$page
,
$limit
,
[
'id'
,
'sid'
,
'icon'
,
'name'
,
'nickname'
,
'platform'
,
'chain'
],
$rows
=
Coin
::
getSelectList
(
$page
,
$limit
,
[
'id'
,
'sid'
,
'icon'
,
'name'
,
'nickname'
,
'platform'
,
'chain'
],
$condition
);
$condition
);
$count
=
0
;
$count
=
0
;
if
(
!
empty
(
$rows
)
&&
is_array
(
$rows
)
&&
array_key_exists
(
'count'
,
$rows
))
{
if
(
!
empty
(
$rows
)
&&
is_array
(
$rows
)
&&
array_key_exists
(
'count'
,
$rows
))
{
...
@@ -167,9 +181,10 @@ class ExchangeBusiness
...
@@ -167,9 +181,10 @@ class ExchangeBusiness
/**
/**
* 根据名称搜索
* 根据名称搜索
* @param int $page
*
* @param int $limit
* @param int $page
* @param array $condition
* @param int $limit
* @param array $condition
* @return array|\yii\db\ActiveRecord|\yii\db\ActiveRecord[]
* @return array|\yii\db\ActiveRecord|\yii\db\ActiveRecord[]
*/
*/
public
static
function
SearchByName
(
$page
=
1
,
$limit
=
10
,
$condition
=
[])
public
static
function
SearchByName
(
$page
=
1
,
$limit
=
10
,
$condition
=
[])
...
@@ -183,6 +198,7 @@ class ExchangeBusiness
...
@@ -183,6 +198,7 @@ class ExchangeBusiness
$rows
[
$key
][
'sid'
]
=
ucfirst
(
$rows
[
$key
][
'sid'
]);
$rows
[
$key
][
'sid'
]
=
ucfirst
(
$rows
[
$key
][
'sid'
]);
$platform
=
strtoupper
(
$rows
[
$key
][
'platform'
]);
$platform
=
strtoupper
(
$rows
[
$key
][
'platform'
]);
$platform_icon
=
Yii
::
$app
->
redis
->
hget
(
'platform_image_info'
,
$platform
);
$platform_icon
=
Yii
::
$app
->
redis
->
hget
(
'platform_image_info'
,
$platform
);
$rows
[
$key
][
'platform_icon'
]
=
$platform_icon
??
''
;
$rows
[
$key
][
'platform_icon'
]
=
$platform_icon
??
''
;
}
}
return
[
'total'
=>
$total
,
'data'
=>
$rows
];
return
[
'total'
=>
$total
,
'data'
=>
$rows
];
...
...
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