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
86832200
Commit
86832200
authored
Nov 05, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
行情排序
parent
99457224
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
316 additions
and
124 deletions
+316
-124
Tools.php
common/components/Tools.php
+166
-0
BinanceBuilder.php
common/service/exchange/factory/BinanceBuilder.php
+50
-58
HuobiBuilder.php
common/service/exchange/factory/HuobiBuilder.php
+31
-27
ZhaobiBuilder.php
common/service/exchange/factory/ZhaobiBuilder.php
+68
-38
TickerController.php
console/controllers/TickerController.php
+1
-1
No files found.
common/components/Tools.php
0 → 100644
View file @
86832200
<?php
namespace
common\components
;
use
Yii
;
use
yii\helpers\Url
;
use
yii\helpers\ArrayHelper
;
class
Tools
{
/**
* 获取随机验证码
* @return string
*/
public
static
function
getRandomNumber
(
$count
=
6
,
$type
=
'mixed'
)
{
$chars
=
'1234567890abcdefghijklmnopqrstuvwxyz'
;
switch
(
$type
)
{
case
'number'
:
$startIndex
=
0
;
$endIndex
=
9
;
break
;
case
'letter'
:
$startIndex
=
10
;
$endIndex
=
35
;
break
;
default
:
$startIndex
=
0
;
$endIndex
=
35
;
break
;
}
$randomNumber
=
''
;
for
(
$i
=
0
;
$i
<
$count
;
$i
++
)
{
$randomNumber
.=
substr
(
$chars
,
rand
(
$startIndex
,
$endIndex
),
1
);
}
return
$randomNumber
;
}
/**
* 获取文件全路径
* @param type $filename
* @param type $type
* @return string
*/
public
static
function
getFileUrl
(
$filename
,
$type
)
{
return
$filename
;
switch
(
$type
)
{
case
'case'
:
return
$filename
?
Url
::
to
(
'@resDomain/'
.
$type
.
'/'
.
$filename
)
:
''
;
case
'video'
:
return
$filename
?
Url
::
to
(
'@resDomain/'
.
$type
.
'/'
.
$filename
)
:
''
;
case
'banner'
:
return
$filename
?
Url
::
to
(
'@resDomain/'
.
$type
.
'/'
.
$filename
)
:
''
;
case
'weixin'
:
return
$filename
?
Url
::
to
(
'@resDomain/'
.
$type
.
'/'
.
$filename
)
:
''
;
case
'public'
:
return
$filename
?
Url
::
to
(
'@resDomain/'
.
$type
.
'/'
.
$filename
)
:
''
;
default
:
return
''
;
}
}
public
static
function
getGradeFile
(
$grade
)
{
return
Url
::
to
(
'@resDomain/grade/a'
.
$grade
.
'.png'
);
}
/**
* 判断当前日期是否是可用日期
* @param type $startData
* @param type $endData
*/
public
static
function
isAvailableDate
(
$start
,
$end
)
{
$current
=
date
(
'Y-m-d'
);
$start
=
$start
?
date
(
'Y-m-d'
,
strtotime
(
$start
))
:
$current
;
$end
=
$end
?
date
(
'Y-m-d'
,
strtotime
(
$end
))
:
$current
;
if
(
$start
<=
$current
&&
$end
>=
$current
)
{
return
true
;
}
else
{
return
false
;
}
}
/**
* 添加get查询数据
* @param type $values
*/
public
static
function
addQueryParams
(
$values
)
{
Yii
::
$app
->
request
->
setQueryParams
(
ArrayHelper
::
merge
(
Yii
::
$app
->
request
->
get
(),
$values
));
}
/**
* 获取post数据, 可附加额外数据
* @param array $values 附加数据,必须是数组形式
* @param string $key 指定数据附加到特定键
*/
public
static
function
getPost
(
array
$values
,
$key
=
null
)
{
if
(
Yii
::
$app
->
request
->
isPost
)
{
$data
=
Yii
::
$app
->
request
->
post
();
if
(
$key
!==
null
)
{
$data
[
$key
]
=
ArrayHelper
::
merge
(
$data
[
$key
],
$values
);
}
else
{
$data
=
ArrayHelper
::
merge
(
$data
,
$values
);
}
return
$data
;
}
else
{
return
;
}
}
/*
* 截取字符串
*/
public
static
function
truncate_utf8_string
(
$string
,
$length
,
$etc
=
'...'
)
{
$result
=
''
;
$string
=
html_entity_decode
(
trim
(
strip_tags
(
$string
)),
ENT_QUOTES
,
'UTF-8'
);
$strlen
=
strlen
(
$string
);
for
(
$i
=
0
;
((
$i
<
$strlen
)
&&
(
$length
>
0
));
$i
++
)
{
if
(
$number
=
strpos
(
str_pad
(
decbin
(
ord
(
substr
(
$string
,
$i
,
1
))),
8
,
'0'
,
STR_PAD_LEFT
),
'0'
))
{
if
(
$length
<
1.0
)
{
break
;
}
$result
.=
substr
(
$string
,
$i
,
$number
);
$length
-=
1.0
;
$i
+=
$number
-
1
;
}
else
{
$result
.=
substr
(
$string
,
$i
,
1
);
$length
-=
0.5
;
}
}
$result
=
htmlspecialchars
(
$result
,
ENT_QUOTES
,
'UTF-8'
);
if
(
$i
<
$strlen
)
{
$result
.=
$etc
;
}
return
$result
;
}
public
static
function
arraySort
(
$array
,
$keys
,
$sort
=
SORT_DESC
)
{
$keysValue
=
[];
foreach
(
$array
as
$k
=>
$v
)
{
$keysValue
[
$k
]
=
$v
[
$keys
];
}
array_multisort
(
$keysValue
,
$sort
,
$array
);
return
$array
;
}
}
\ No newline at end of file
common/service/exchange/factory/BinanceBuilder.php
View file @
86832200
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
namespace
common\service\exchange\factory
;
namespace
common\service\exchange\factory
;
use
common\components\Tools
;
use
linslin\yii2\curl\Curl
;
use
linslin\yii2\curl\Curl
;
class
BinanceBuilder
extends
FactoryService
class
BinanceBuilder
extends
FactoryService
...
@@ -15,48 +16,13 @@ class BinanceBuilder extends FactoryService
...
@@ -15,48 +16,13 @@ class BinanceBuilder extends FactoryService
protected
$base_url
=
'https://api.binance.com'
;
protected
$base_url
=
'https://api.binance.com'
;
protected
$supported_symbol
=
'supported_symbol_binance'
;
protected
$supported_symbol
=
'supported_symbol_binance'
;
protected
$supported_symbol_list
=
'supported_symbol_binance_list'
;
protected
$supported_symbol_list
=
'supported_symbol_binance_list'
;
protected
$supported_symbol_close_sort_list
=
'supported_symbol_close_sort_binance_list'
;
protected
$supported_symbol_close_asc
=
'supported_symbol_close_asc_binance'
;
protected
$supported_symbol_change_sort_list
=
'supported_symbol_change_sort_binance_list'
;
protected
$supported_symbol_close_desc
=
'supported_symbol_close_desc_binance'
;
protected
$supported_symbol_change_asc
=
'supported_symbol_change_asc_binance'
;
protected
$supported_symbol_change_desc
=
'supported_symbol_change_desc_binance'
;
protected
$quotation_prefix
=
'quotation_binance_'
;
protected
$quotation_prefix
=
'quotation_binance_'
;
public
function
getTicker
()
public
function
getTickerFromCache
(
$page
=
1
,
$condition
=
[])
{
$curl
=
new
Curl
();
$api
=
$this
->
base_url
.
'/api/v1/ticker/24hr'
;
$res
=
$curl
->
get
(
$api
,
false
);
$ticker
=
[];
if
(
is_array
(
$res
))
{
$this
->
code
=
0
;
foreach
(
$res
as
$val
)
{
foreach
(
$this
->
basic_coin
as
$k
=>
$coin
)
{
$explode_arr
=
explode
(
$coin
,
$val
[
'symbol'
]);
if
(
2
==
count
(
$explode_arr
)
&&
empty
(
$explode_arr
[
1
]))
{
$temp
=
[];
$temp
[
'symbol'
]
=
$explode_arr
[
0
]
.
'/'
.
$coin
;
$temp
[
'currency'
]
=
strtoupper
(
$explode_arr
[
0
]);
$temp
[
'base_currency'
]
=
strtoupper
(
$coin
);
$temp
[
'close'
]
=
number_format
(
$val
[
'lastPrice'
],
6
,
'.'
,
''
);
$temp
[
'close_usd'
]
=
(
float
)
sprintf
(
"%0.6f"
,
$val
[
'lastPrice'
]
*
$this
->
basic_price
[
$coin
][
'usd'
]);
$temp
[
'close_rmb'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'lastPrice'
]
*
$this
->
basic_price
[
$coin
][
'rmb'
]);
$temp
[
'change'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'priceChangePercent'
]);
$temp
[
'high_usd'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'highPrice'
]
*
$this
->
basic_price
[
$coin
][
'usd'
]);
$temp
[
'low_usd'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'lowPrice'
]
*
$this
->
basic_price
[
$coin
][
'usd'
]);
$temp
[
'high_rmb'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'highPrice'
]
*
$this
->
basic_price
[
$coin
][
'rmb'
]);
$temp
[
'low_rmb'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'lowPrice'
]
*
$this
->
basic_price
[
$coin
][
'rmb'
]);
$temp
[
'vol'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'volume'
]);
$temp
[
'optional'
]
=
false
;
$temp
[
'platform_zh'
]
=
'币安'
;
$temp
[
'platform_us'
]
=
'binance'
;
array_push
(
$ticker
,
$temp
);
break
;
}
}
}
}
return
[
'code'
=>
$this
->
code
,
'ticker'
=>
$ticker
];
}
public
function
getTickerFromCache
(
$page
=
1
)
{
{
$size
=
0
;
$size
=
0
;
for
(
$i
=
0
;
$i
<
$page
;
$i
++
)
{
for
(
$i
=
0
;
$i
<
$page
;
$i
++
)
{
...
@@ -76,16 +42,38 @@ class BinanceBuilder extends FactoryService
...
@@ -76,16 +42,38 @@ class BinanceBuilder extends FactoryService
}
}
}
}
}
}
$keys
=
$this
->
redis
->
lrange
(
$this
->
supported_symbol_list
,
$this
->
start
,
$this
->
end
);
if
(
false
!=
$condition
)
{
if
(
'price'
==
$condition
[
'data_value'
])
{
if
(
'price-asc'
==
$condition
[
'sort_value'
])
{
$keys
=
$this
->
redis_ticker
->
lrange
(
$this
->
supported_symbol_close_asc
,
$this
->
start
,
$this
->
end
);
}
if
(
'price-desc'
==
$condition
[
'sort_value'
])
{
$keys
=
$this
->
redis_ticker
->
lrange
(
$this
->
supported_symbol_close_desc
,
$this
->
start
,
$this
->
end
);
}
}
if
(
'change'
==
$condition
[
'data_value'
])
{
if
(
'change-asc'
==
$condition
[
'sort_value'
])
{
$keys
=
$this
->
redis_ticker
->
lrange
(
$this
->
supported_symbol_change_asc
,
$this
->
start
,
$this
->
end
);
}
if
(
'change-desc'
==
$condition
[
'sort_value'
])
{
$keys
=
$this
->
redis_ticker
->
lrange
(
$this
->
supported_symbol_change_desc
,
$this
->
start
,
$this
->
end
);
}
}
}
else
{
$keys
=
$this
->
redis
->
lrange
(
$this
->
supported_symbol_list
,
$this
->
start
,
$this
->
end
);
}
$ticker
=
[];
$ticker
=
[];
foreach
(
$keys
as
$val
)
{
foreach
(
$keys
as
$val
)
{
foreach
(
$this
->
basic_coin
as
$k
=>
$coin
)
{
foreach
(
$this
->
basic_coin
as
$k
=>
$coin
)
{
$explode_arr
=
explode
(
$coin
,
$val
);
$explode_arr
=
explode
(
$coin
,
$val
);
if
(
2
==
count
(
$explode_arr
)
&&
empty
(
$explode_arr
[
1
]))
{
if
(
2
==
count
(
$explode_arr
)
&&
empty
(
$explode_arr
[
1
]))
{
list
(
$low
,
$high
,
$close
,
$open
,
$vol
)
=
$this
->
redis
->
hmget
(
$this
->
quotation_prefix
.
strtolower
(
$val
),
'low'
,
'high'
,
'last'
,
'open'
,
'vol'
);
if
(
false
!=
$condition
)
{
list
(
$low
,
$high
,
$close
,
$open
,
$vol
)
=
$this
->
redis_ticker
->
hmget
(
$this
->
quotation_prefix
.
strtoupper
(
$val
),
'low'
,
'high'
,
'last'
,
'open'
,
'vol'
);
}
else
{
list
(
$low
,
$high
,
$close
,
$open
,
$vol
)
=
$this
->
redis
->
hmget
(
$this
->
quotation_prefix
.
strtolower
(
$val
),
'low'
,
'high'
,
'last'
,
'open'
,
'vol'
);
}
$temp
=
[];
$temp
=
[];
$temp
[
'symbol'
]
=
strtoupper
(
$explode_arr
[
0
])
.
'/'
.
$coin
;
$temp
[
'symbol'
]
=
strtoupper
(
$explode_arr
[
0
])
.
'/'
.
$coin
;
#if ('BCC/USDT' != $temp['symbol']) continue;
$temp
[
'currency'
]
=
strtoupper
(
$explode_arr
[
0
]);
$temp
[
'currency'
]
=
strtoupper
(
$explode_arr
[
0
]);
$temp
[
'base_currency'
]
=
strtoupper
(
$coin
);
$temp
[
'base_currency'
]
=
strtoupper
(
$coin
);
$temp
[
'close'
]
=
$this
->
sctonum
(
$close
,
8
);
$temp
[
'close'
]
=
$this
->
sctonum
(
$close
,
8
);
...
@@ -121,31 +109,35 @@ class BinanceBuilder extends FactoryService
...
@@ -121,31 +109,35 @@ class BinanceBuilder extends FactoryService
$ticker
=
[];
$ticker
=
[];
for
(
$i
=
0
;
$i
<
$len
;
$i
++
)
{
for
(
$i
=
0
;
$i
<
$len
;
$i
++
)
{
$symbol
=
$this
->
redis
->
lindex
(
$this
->
supported_symbol_list
,
$i
);
$symbol
=
$this
->
redis
->
lindex
(
$this
->
supported_symbol_list
,
$i
);
list
(
$close
,
$open
)
=
$this
->
redis
->
hmget
(
$this
->
quotation_prefix
.
strtolower
(
$symbol
),
'last'
,
'open
'
);
list
(
$close
,
$open
,
$low
,
$high
,
$vol
)
=
$this
->
redis
->
hmget
(
$this
->
quotation_prefix
.
strtolower
(
$symbol
),
'last'
,
'open'
,
'low'
,
'high'
,
'vol
'
);
$temp
=
[];
$temp
=
[];
$temp
[
'symbol'
]
=
strtoupper
(
$symbol
);
$temp
[
'symbol'
]
=
strtoupper
(
$symbol
);
$temp
[
'close'
]
=
number_format
(
$close
,
6
,
'.'
,
''
);
$temp
[
'close'
]
=
number_format
(
$close
,
6
,
'.'
,
''
);
$temp
[
'low'
]
=
$low
;
$temp
[
'high'
]
=
$high
;
$temp
[
'open'
]
=
$open
;
$temp
[
'vol'
]
=
$vol
;
$temp
[
'change'
]
=
(
0
==
$open
)
?
0
:
(
float
)
sprintf
(
"%0.2f"
,
(
$close
-
$open
)
/
$open
*
100
);
$temp
[
'change'
]
=
(
0
==
$open
)
?
0
:
(
float
)
sprintf
(
"%0.2f"
,
(
$close
-
$open
)
/
$open
*
100
);
array_push
(
$ticker
,
$temp
);
array_push
(
$ticker
,
$temp
);
$key
=
$this
->
quotation_prefix
.
strtoupper
(
$symbol
);
$this
->
redis_ticker
->
hmset
(
$key
,
'low'
,
$low
,
'high'
,
$high
,
'last'
,
$close
,
'open'
,
$open
,
'vol'
,
$vol
);
}
}
$ticker_sort_close
=
$this
->
arraySort
(
$ticker
,
'close'
);
$ticker_sort_close
=
Tools
::
arraySort
(
$ticker
,
'close'
);
$this
->
redis_ticker
->
del
(
$this
->
supported_symbol_close_asc
);
$this
->
redis_ticker
->
del
(
$this
->
supported_symbol_close_desc
);
foreach
(
$ticker_sort_close
as
$val
)
{
foreach
(
$ticker_sort_close
as
$val
)
{
$this
->
redis
->
lpush
(
$this
->
supported_symbol_close_sort_list
,
$val
[
'symbol'
]);
$this
->
redis_ticker
->
lpush
(
$this
->
supported_symbol_close_asc
,
strtoupper
(
$val
[
'symbol'
]));
}
$this
->
redis_ticker
->
rpush
(
$this
->
supported_symbol_close_desc
,
strtoupper
(
$val
[
'symbol'
]));
$ticker_change_close
=
$this
->
arraySort
(
$ticker
,
'change'
);
foreach
(
$ticker_change_close
as
$val
)
{
$this
->
redis
->
lpush
(
$this
->
supported_symbol_change_sort_list
,
$val
[
'symbol'
]);
}
}
}
protected
function
arraySort
(
$array
,
$keys
,
$sort
=
SORT_DESC
)
$ticker_change_close
=
Tools
::
arraySort
(
$ticker
,
'change'
);
{
$this
->
redis_ticker
->
del
(
$this
->
supported_symbol_change_asc
);
$keysValue
=
[];
$this
->
redis_ticker
->
del
(
$this
->
supported_symbol_change_desc
);
foreach
(
$array
as
$k
=>
$v
)
{
foreach
(
$ticker_change_close
as
$val
)
{
$keysValue
[
$k
]
=
$v
[
$keys
];
$this
->
redis_ticker
->
lpush
(
$this
->
supported_symbol_change_asc
,
strtoupper
(
$val
[
'symbol'
]));
$this
->
redis_ticker
->
rpush
(
$this
->
supported_symbol_change_desc
,
strtoupper
(
$val
[
'symbol'
]));
}
}
array_multisort
(
$keysValue
,
$sort
,
$array
);
return
$array
;
}
}
protected
function
sctonum
(
$num
,
$double
=
5
)
protected
function
sctonum
(
$num
,
$double
=
5
)
...
...
common/service/exchange/factory/HuobiBuilder.php
View file @
86832200
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
namespace
common\service\exchange\factory
;
namespace
common\service\exchange\factory
;
use
common\components\Tools
;
use
linslin\yii2\curl\Curl
;
use
linslin\yii2\curl\Curl
;
class
HuobiBuilder
extends
FactoryService
class
HuobiBuilder
extends
FactoryService
...
@@ -15,8 +16,10 @@ class HuobiBuilder extends FactoryService
...
@@ -15,8 +16,10 @@ class HuobiBuilder extends FactoryService
protected
$base_url
=
'https://api.huobi.pro'
;
protected
$base_url
=
'https://api.huobi.pro'
;
protected
$supported_symbol
=
'supported_symbol_huobi'
;
protected
$supported_symbol
=
'supported_symbol_huobi'
;
protected
$supported_symbol_list
=
'supported_symbol_huobi_list'
;
protected
$supported_symbol_list
=
'supported_symbol_huobi_list'
;
protected
$supported_symbol_close_sort
=
'supported_symbol_close_sort_huobi'
;
protected
$supported_symbol_close_asc
=
'supported_symbol_close_asc_huobi'
;
protected
$supported_symbol_change_sort
=
'supported_symbol_change_sort_huobi'
;
protected
$supported_symbol_close_desc
=
'supported_symbol_close_desc_huobi'
;
protected
$supported_symbol_change_asc
=
'supported_symbol_change_asc_huobi'
;
protected
$supported_symbol_change_desc
=
'supported_symbol_change_desc_huobi'
;
protected
$quotation_prefix
=
'quotation_huobi_'
;
protected
$quotation_prefix
=
'quotation_huobi_'
;
public
function
hotTickerUpdate
()
public
function
hotTickerUpdate
()
...
@@ -61,10 +64,20 @@ class HuobiBuilder extends FactoryService
...
@@ -61,10 +64,20 @@ class HuobiBuilder extends FactoryService
}
}
if
(
false
!=
$condition
)
{
if
(
false
!=
$condition
)
{
if
(
'price'
==
$condition
[
'data_value'
])
{
if
(
'price'
==
$condition
[
'data_value'
])
{
$keys
=
$this
->
redis_ticker
->
lrange
(
$this
->
supported_symbol_close_sort
,
$this
->
start
,
$this
->
end
);
if
(
'price-asc'
==
$condition
[
'sort_value'
])
{
$keys
=
$this
->
redis_ticker
->
lrange
(
$this
->
supported_symbol_close_asc
,
$this
->
start
,
$this
->
end
);
}
if
(
'price-desc'
==
$condition
[
'sort_value'
])
{
$keys
=
$this
->
redis_ticker
->
lrange
(
$this
->
supported_symbol_close_desc
,
$this
->
start
,
$this
->
end
);
}
}
}
if
(
'change'
==
$condition
[
'data_value'
])
{
if
(
'change'
==
$condition
[
'data_value'
])
{
$keys
=
$this
->
redis_ticker
->
lrange
(
$this
->
supported_symbol_change_sort
,
$this
->
start
,
$this
->
end
);
if
(
'change-asc'
==
$condition
[
'sort_value'
])
{
$keys
=
$this
->
redis_ticker
->
lrange
(
$this
->
supported_symbol_change_asc
,
$this
->
start
,
$this
->
end
);
}
if
(
'change-desc'
==
$condition
[
'sort_value'
])
{
$keys
=
$this
->
redis_ticker
->
lrange
(
$this
->
supported_symbol_change_desc
,
$this
->
start
,
$this
->
end
);
}
}
}
}
else
{
}
else
{
$keys
=
$this
->
redis
->
lrange
(
$this
->
supported_symbol_list
,
$this
->
start
,
$this
->
end
);
$keys
=
$this
->
redis
->
lrange
(
$this
->
supported_symbol_list
,
$this
->
start
,
$this
->
end
);
...
@@ -127,34 +140,25 @@ class HuobiBuilder extends FactoryService
...
@@ -127,34 +140,25 @@ class HuobiBuilder extends FactoryService
$temp
[
'vol'
]
=
$vol
;
$temp
[
'vol'
]
=
$vol
;
$temp
[
'change'
]
=
(
0
==
$open
)
?
0
:
(
float
)
sprintf
(
"%0.2f"
,
(
$close
-
$open
)
/
$open
*
100
);
$temp
[
'change'
]
=
(
0
==
$open
)
?
0
:
(
float
)
sprintf
(
"%0.2f"
,
(
$close
-
$open
)
/
$open
*
100
);
array_push
(
$ticker
,
$temp
);
array_push
(
$ticker
,
$temp
);
$key
=
$this
->
quotation_prefix
.
strtoupper
(
$symbol
);
$this
->
redis_ticker
->
hmset
(
$key
,
'low'
,
$low
,
'high'
,
$high
,
'last'
,
$close
,
'open'
,
$open
,
'vol'
,
$vol
);
}
}
$ticker_sort_close
=
$this
->
arraySort
(
$ticker
,
'close'
);
foreach
(
$ticker_sort_close
as
$val
)
{
$key
=
$this
->
quotation_prefix
.
strtoupper
(
$val
[
'symbol'
]);
$this
->
redis_ticker
->
hmset
(
$key
,
'low'
,
$val
[
'low'
],
'high'
,
$val
[
'high'
],
'last'
,
$val
[
'close'
],
'open'
,
$val
[
'open'
],
'vol'
,
$val
[
'vol'
]);
$this
->
redis_ticker
->
sadd
(
$this
->
supported_symbol
,
$val
[
'symbol'
]);
$this
->
redis_ticker
->
lpush
(
$this
->
supported_symbol_close_sort
,
strtoupper
(
$val
[
'symbol'
]));
}
$ticker_change_close
=
$this
->
arraySort
(
$ticker
,
'change'
);
foreach
(
$ticker_change_close
as
$val
)
{
$key
=
$this
->
quotation_prefix
.
strtoupper
(
$val
[
'symbol'
]);
$this
->
redis_ticker
->
hmset
(
$key
,
'low'
,
$val
[
'low'
],
'high'
,
$val
[
'high'
],
'last'
,
$val
[
'close'
],
'open'
,
$val
[
'open'
],
'vol'
,
$val
[
'vol'
]);
$this
->
redis_ticker
->
sadd
(
$this
->
supported_symbol
,
$val
[
'symbol'
]);
$this
->
redis_ticker
->
lpush
(
$this
->
supported_symbol_change_sort
,
strtoupper
(
$val
[
'symbol'
]));
$ticker_sort_close
=
Tools
::
arraySort
(
$ticker
,
'close'
);
$this
->
redis_ticker
->
del
(
$this
->
supported_symbol_close_asc
);
$this
->
redis_ticker
->
del
(
$this
->
supported_symbol_close_desc
);
foreach
(
$ticker_sort_close
as
$val
)
{
$this
->
redis_ticker
->
lpush
(
$this
->
supported_symbol_close_asc
,
strtoupper
(
$val
[
'symbol'
]));
$this
->
redis_ticker
->
rpush
(
$this
->
supported_symbol_close_desc
,
strtoupper
(
$val
[
'symbol'
]));
}
}
}
protected
function
arraySort
(
$array
,
$keys
,
$sort
=
SORT_DESC
)
$ticker_change_close
=
Tools
::
arraySort
(
$ticker
,
'change'
);
{
$this
->
redis_ticker
->
del
(
$this
->
supported_symbol_change_asc
);
$keysValue
=
[];
$this
->
redis_ticker
->
del
(
$this
->
supported_symbol_change_desc
);
foreach
(
$array
as
$k
=>
$v
)
{
foreach
(
$ticker_change_close
as
$val
)
{
$keysValue
[
$k
]
=
$v
[
$keys
];
$this
->
redis_ticker
->
lpush
(
$this
->
supported_symbol_change_asc
,
strtoupper
(
$val
[
'symbol'
]));
$this
->
redis_ticker
->
rpush
(
$this
->
supported_symbol_change_desc
,
strtoupper
(
$val
[
'symbol'
]));
}
}
array_multisort
(
$keysValue
,
$sort
,
$array
);
return
$array
;
}
}
public
function
getHotTicker
()
public
function
getHotTicker
()
...
...
common/service/exchange/factory/ZhaobiBuilder.php
View file @
86832200
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
namespace
common\service\exchange\factory
;
namespace
common\service\exchange\factory
;
use
common\components\Tools
;
use
linslin\yii2\curl\Curl
;
use
linslin\yii2\curl\Curl
;
class
ZhaobiBuilder
extends
FactoryService
class
ZhaobiBuilder
extends
FactoryService
...
@@ -15,44 +16,63 @@ class ZhaobiBuilder extends FactoryService
...
@@ -15,44 +16,63 @@ class ZhaobiBuilder extends FactoryService
protected
$base_url
=
'https://api.biqianbao.top'
;
protected
$base_url
=
'https://api.biqianbao.top'
;
protected
$supported_symbol
=
'supported_symbol_zhaobi'
;
protected
$supported_symbol
=
'supported_symbol_zhaobi'
;
protected
$supported_symbol_list
=
'supported_symbol_zhaobi_list'
;
protected
$supported_symbol_list
=
'supported_symbol_zhaobi_list'
;
protected
$supported_symbol_close_sort_list
=
'supported_symbol_close_sort_zhaobi_list'
;
protected
$supported_symbol_close_asc
=
'supported_symbol_close_asc_zhaobi'
;
protected
$supported_symbol_change_sort_list
=
'supported_symbol_change_sort_zhaobi_list'
;
protected
$supported_symbol_close_desc
=
'supported_symbol_close_desc_zhaobi'
;
protected
$supported_symbol_change_asc
=
'supported_symbol_change_asc_zhaobi'
;
protected
$supported_symbol_change_desc
=
'supported_symbol_change_desc_zhaobi'
;
protected
$quotation_prefix
=
'quotation_zhaobi_'
;
protected
$quotation_prefix
=
'quotation_zhaobi_'
;
public
function
getTickerFromCache
()
public
function
getTickerFromCache
(
$page
=
1
,
$condition
=
[]
)
{
{
$curl
=
new
Curl
();
$this
->
start
=
0
;
$api
=
$this
->
base_url
.
'/api/data/Ticker?sort=cname'
;
$this
->
end
=
50
;
$res
=
$curl
->
get
(
$api
,
false
);
if
(
false
!=
$condition
)
{
$ticker
=
[];
if
(
'price'
==
$condition
[
'data_value'
])
{
if
(
isset
(
$res
[
'message'
])
&&
'OK'
==
$res
[
'message'
])
{
if
(
'price-asc'
==
$condition
[
'sort_value'
])
{
$ticker_temp
=
[];
$keys
=
$this
->
redis_ticker
->
lrange
(
$this
->
supported_symbol_close_asc
,
$this
->
start
,
$this
->
end
);
foreach
(
$res
[
'data'
]
as
$val
)
{
}
$ticker_temp
=
array_merge
(
$ticker_temp
,
$val
);
if
(
'price-desc'
==
$condition
[
'sort_value'
])
{
$keys
=
$this
->
redis_ticker
->
lrange
(
$this
->
supported_symbol_close_desc
,
$this
->
start
,
$this
->
end
);
}
}
}
foreach
(
$ticker_temp
as
$val
)
{
if
(
'change'
==
$condition
[
'data_value'
])
{
foreach
(
$this
->
basic_coin
as
$k
=>
$coin
)
{
if
(
'change-asc'
==
$condition
[
'sort_value'
])
{
$explode_arr
=
explode
(
$coin
,
$val
[
'symbol'
]);
$keys
=
$this
->
redis_ticker
->
lrange
(
$this
->
supported_symbol_change_asc
,
$this
->
start
,
$this
->
end
);
if
(
2
==
count
(
$explode_arr
)
&&
empty
(
$explode_arr
[
1
]))
{
}
$temp
=
[];
if
(
'change-desc'
==
$condition
[
'sort_value'
])
{
$temp
[
'symbol'
]
=
(
'BCC'
==
strtoupper
(
$explode_arr
[
0
]))
?
'BCH'
.
'/'
.
$coin
:
strtoupper
(
$explode_arr
[
0
])
.
'/'
.
$coin
;
$keys
=
$this
->
redis_ticker
->
lrange
(
$this
->
supported_symbol_change_desc
,
$this
->
start
,
$this
->
end
);
$temp
[
'currency'
]
=
(
'BCC'
==
strtoupper
(
$explode_arr
[
0
]))
?
'BCH'
:
strtoupper
(
$explode_arr
[
0
]);
}
$temp
[
'base_currency'
]
=
strtoupper
(
$coin
);
}
$temp
[
'close'
]
=
number_format
(
$val
[
'last'
],
6
,
'.'
,
''
);
}
else
{
if
(
'0.000000'
==
$temp
[
'close'
])
continue
;
$keys
=
$this
->
redis
->
lrange
(
$this
->
supported_symbol_list
,
$this
->
start
,
$this
->
end
);
$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'
]);
$ticker
=
[];
$temp
[
'change'
]
=
(
0
==
$val
[
'open'
])
?
0
:
(
float
)
sprintf
(
"%0.2f"
,
(
$val
[
'last'
]
-
$val
[
'open'
])
/
$val
[
'open'
]
*
100
);
foreach
(
$keys
as
$val
)
{
$temp
[
'high_usd'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'high'
]
*
$this
->
basic_price
[
$coin
][
'usd'
]);
foreach
(
$this
->
basic_coin
as
$k
=>
$coin
)
{
$temp
[
'low_usd'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'low'
]
*
$this
->
basic_price
[
$coin
][
'usd'
]);
$explode_arr
=
explode
(
$coin
,
$val
);
$temp
[
'high_rmb'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'high'
]
*
$this
->
basic_price
[
$coin
][
'rmb'
]);
if
(
2
==
count
(
$explode_arr
)
&&
empty
(
$explode_arr
[
1
]))
{
$temp
[
'low_rmb'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'low'
]
*
$this
->
basic_price
[
$coin
][
'rmb'
]);
if
(
false
!=
$condition
)
{
$temp
[
'vol'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'vol'
]);
list
(
$low
,
$high
,
$close
,
$open
,
$vol
)
=
$this
->
redis_ticker
->
hmget
(
$this
->
quotation_prefix
.
strtoupper
(
$val
),
'low'
,
'high'
,
'last'
,
'open'
,
'vol'
);
$temp
[
'optional'
]
=
false
;
}
else
{
$temp
[
'platform_zh'
]
=
'找币'
;
list
(
$low
,
$high
,
$close
,
$open
,
$vol
)
=
$this
->
redis
->
hmget
(
$this
->
quotation_prefix
.
strtolower
(
$val
),
'low'
,
'high'
,
'last'
,
'open'
,
'vol'
);
$temp
[
'platform_us'
]
=
'zhaobi'
;
array_push
(
$ticker
,
$temp
);
}
}
$temp
=
[];
$temp
[
'symbol'
]
=
strtoupper
(
$explode_arr
[
0
])
.
'/'
.
$coin
;
$temp
[
'currency'
]
=
strtoupper
(
$explode_arr
[
0
]);
$temp
[
'base_currency'
]
=
strtoupper
(
$coin
);
$temp
[
'close'
]
=
$close
;
$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.2f"
,
(
$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'
]
=
'zhaobi'
;
array_push
(
$ticker
,
$temp
);
}
}
}
}
}
}
...
@@ -79,20 +99,30 @@ class ZhaobiBuilder extends FactoryService
...
@@ -79,20 +99,30 @@ class ZhaobiBuilder extends FactoryService
$ticker
=
[];
$ticker
=
[];
for
(
$i
=
0
;
$i
<
$len
;
$i
++
)
{
for
(
$i
=
0
;
$i
<
$len
;
$i
++
)
{
$symbol
=
$this
->
redis
->
lindex
(
$this
->
supported_symbol_list
,
$i
);
$symbol
=
$this
->
redis
->
lindex
(
$this
->
supported_symbol_list
,
$i
);
list
(
$close
,
$open
)
=
$this
->
redis
->
hmget
(
$this
->
quotation_prefix
.
strtolower
(
$symbol
),
'last'
,
'open
'
);
list
(
$close
,
$open
,
$low
,
$high
,
$vol
)
=
$this
->
redis
->
hmget
(
$this
->
quotation_prefix
.
strtolower
(
$symbol
),
'last'
,
'open'
,
'low'
,
'high'
,
'vol
'
);
$temp
=
[];
$temp
=
[];
$temp
[
'symbol'
]
=
strtoupper
(
$symbol
);
$temp
[
'symbol'
]
=
strtoupper
(
$symbol
);
$temp
[
'close'
]
=
number_format
(
$close
,
6
,
'.'
,
''
);
$temp
[
'close'
]
=
number_format
(
$close
,
6
,
'.'
,
''
);
$temp
[
'change'
]
=
(
0
==
$open
)
?
0
:
(
float
)
sprintf
(
"%0.2f"
,
(
$close
-
$open
)
/
$open
*
100
);
$temp
[
'change'
]
=
(
0
==
$open
)
?
0
:
(
float
)
sprintf
(
"%0.2f"
,
(
$close
-
$open
)
/
$open
*
100
);
array_push
(
$ticker
,
$temp
);
array_push
(
$ticker
,
$temp
);
$key
=
$this
->
quotation_prefix
.
strtoupper
(
$symbol
);
$this
->
redis_ticker
->
hmset
(
$key
,
'low'
,
$low
,
'high'
,
$high
,
'last'
,
$close
,
'open'
,
$open
,
'vol'
,
$vol
);
}
}
$ticker_sort_close
=
$this
->
arraySort
(
$ticker
,
'close'
);
$ticker_sort_close
=
Tools
::
arraySort
(
$ticker
,
'close'
);
$this
->
redis_ticker
->
del
(
$this
->
supported_symbol_close_asc
);
$this
->
redis_ticker
->
del
(
$this
->
supported_symbol_close_desc
);
foreach
(
$ticker_sort_close
as
$val
)
{
foreach
(
$ticker_sort_close
as
$val
)
{
$this
->
redis
->
lpush
(
$this
->
supported_symbol_close_sort_list
,
$val
[
'symbol'
]);
$this
->
redis_ticker
->
lpush
(
$this
->
supported_symbol_close_asc
,
strtoupper
(
$val
[
'symbol'
]));
$this
->
redis_ticker
->
rpush
(
$this
->
supported_symbol_close_desc
,
strtoupper
(
$val
[
'symbol'
]));
}
}
$ticker_change_close
=
$this
->
arraySort
(
$ticker
,
'change'
);
$ticker_change_close
=
Tools
::
arraySort
(
$ticker
,
'change'
);
$this
->
redis_ticker
->
del
(
$this
->
supported_symbol_change_asc
);
$this
->
redis_ticker
->
del
(
$this
->
supported_symbol_change_desc
);
foreach
(
$ticker_change_close
as
$val
)
{
foreach
(
$ticker_change_close
as
$val
)
{
$this
->
redis
->
lpush
(
$this
->
supported_symbol_change_sort_list
,
$val
[
'symbol'
]);
$this
->
redis_ticker
->
lpush
(
$this
->
supported_symbol_change_asc
,
strtoupper
(
$val
[
'symbol'
]));
$this
->
redis_ticker
->
rpush
(
$this
->
supported_symbol_change_desc
,
strtoupper
(
$val
[
'symbol'
]));
}
}
}
}
...
...
console/controllers/TickerController.php
View file @
86832200
...
@@ -14,7 +14,7 @@ class TickerController extends Controller
...
@@ -14,7 +14,7 @@ class TickerController extends Controller
{
{
public
function
actionSort
()
public
function
actionSort
()
{
{
$class
=
[
'
Hu
obi'
];
$class
=
[
'
Binance'
,
'Huobi'
,
'Zha
obi'
];
foreach
(
$class
as
$val
)
{
foreach
(
$class
as
$val
)
{
go
(
function
()
use
(
$val
)
{
go
(
function
()
use
(
$val
)
{
\Co
::
sleep
(
0.5
);
\Co
::
sleep
(
0.5
);
...
...
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