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
dd1cd4d3
Commit
dd1cd4d3
authored
Oct 17, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/ticker' into 'master'
Feature/ticker See merge request
!155
parents
c902ae05
e0755eed
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
148 additions
and
3 deletions
+148
-3
TickerController.php
api/controllers/TickerController.php
+2
-0
ExchangeBusiness.php
common/business/ExchangeBusiness.php
+1
-1
BinanceBuilder.php
common/service/exchange/factory/BinanceBuilder.php
+38
-2
HuobiBuilder.php
common/service/exchange/factory/HuobiBuilder.php
+34
-0
ZhaobiBuilder.php
common/service/exchange/factory/ZhaobiBuilder.php
+44
-0
TickerSortController.php
console/controllers/TickerSortController.php
+29
-0
No files found.
api/controllers/TickerController.php
View file @
dd1cd4d3
...
...
@@ -21,6 +21,8 @@ class TickerController extends BaseController
$page
=
Yii
::
$app
->
request
->
get
(
'page'
,
1
);
$device_code
=
Yii
::
$app
->
request
->
get
(
'device_code'
,
''
);
$exchange
=
Yii
::
$app
->
request
->
get
(
'exchange'
,
'zhaobi'
);
$data_value
=
Yii
::
$app
->
request
->
get
(
'data-value'
,
''
);
$sort
=
Yii
::
$app
->
request
->
get
(
'sort'
,
''
);
$exchange_arr
=
[
'huobi'
,
'binance'
,
'okex'
,
'zhaobi'
];
if
(
!
in_array
(
$exchange
,
$exchange_arr
))
{
...
...
common/business/ExchangeBusiness.php
View file @
dd1cd4d3
...
...
@@ -98,7 +98,7 @@ class ExchangeBusiness
goto
doEnd
;
}
if
(
strtoupper
(
$tag
)
==
'GM'
||
strtoupper
(
$tag
)
==
'BSTC'
||
strtoupper
(
$tag
)
==
'RYH'
||
strtoupper
(
$tag
)
==
'CNDT'
||
strtoupper
(
$tag
)
==
'WL'
||
strtoupper
(
$tag
)
==
'ETS'
||
strtoupper
(
$tag
)
==
'LIMS'
||
strtoupper
(
$tag
)
==
'AT'
||
strtoupper
(
$tag
)
==
'BTJ'
)
{
if
(
strtoupper
(
$tag
)
==
'
STO'
||
strtoupper
(
$tag
)
==
'
GM'
||
strtoupper
(
$tag
)
==
'BSTC'
||
strtoupper
(
$tag
)
==
'RYH'
||
strtoupper
(
$tag
)
==
'CNDT'
||
strtoupper
(
$tag
)
==
'WL'
||
strtoupper
(
$tag
)
==
'ETS'
||
strtoupper
(
$tag
)
==
'LIMS'
||
strtoupper
(
$tag
)
==
'AT'
||
strtoupper
(
$tag
)
==
'BTJ'
)
{
$quotation
=
[
'low'
=>
0
,
'high'
=>
0
,
...
...
common/service/exchange/factory/BinanceBuilder.php
View file @
dd1cd4d3
...
...
@@ -15,6 +15,8 @@ class BinanceBuilder extends FactoryService
protected
$base_url
=
'https://api.binance.com'
;
protected
$supported_symbol
=
'supported_symbol_binance'
;
protected
$supported_symbol_list
=
'supported_symbol_binance_list'
;
protected
$supported_symbol_close_sort_list
=
'supported_symbol_close_sort_binance_list'
;
protected
$supported_symbol_change_sort_list
=
'supported_symbol_change_sort_binance_list'
;
protected
$quotation_prefix
=
'quotation_binance_'
;
public
function
getTicker
()
...
...
@@ -57,7 +59,7 @@ class BinanceBuilder extends FactoryService
public
function
getTickerFromCache
(
$page
=
1
)
{
$size
=
0
;
for
(
$i
=
0
;
$i
<
$page
;
$i
++
)
{
for
(
$i
=
0
;
$i
<
$page
;
$i
++
)
{
$size
+=
50
;
$this
->
end
=
$size
;
}
...
...
@@ -105,10 +107,43 @@ class BinanceBuilder extends FactoryService
$data
=
[
'ticker'
=>
$ticker
,
'page'
=>
[
'pageSize'
=>
50
,
'pageSize'
=>
50
,
'currentPage'
=>
(
int
)
$page
,
]
];
return
[
'code'
=>
$this
->
code
,
'data'
=>
$data
];
}
public
function
TickerSort
()
{
$len
=
$this
->
redis
->
llen
(
$this
->
supported_symbol_list
);
$ticker
=
[];
for
(
$i
=
0
;
$i
<
$len
;
$i
++
)
{
$symbol
=
$this
->
redis
->
lindex
(
$this
->
supported_symbol_list
,
$i
);
list
(
$close
,
$open
)
=
$this
->
redis
->
hmget
(
$this
->
quotation_prefix
.
strtolower
(
$symbol
),
'last'
,
'open'
);
$temp
=
[];
$temp
[
'symbol'
]
=
strtoupper
(
$symbol
);
$temp
[
'close'
]
=
number_format
(
$close
,
6
,
'.'
,
''
);
$temp
[
'change'
]
=
(
0
==
$open
)
?
0
:
(
float
)
sprintf
(
"%0.4f"
,
(
$close
-
$open
)
/
$open
*
100
);
array_push
(
$ticker
,
$temp
);
}
$ticker_sort_close
=
$this
->
arraySort
(
$ticker
,
'close'
);
foreach
(
$ticker_sort_close
as
$val
)
{
$this
->
redis
->
lpush
(
$this
->
supported_symbol_close_sort_list
,
$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
)
{
$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/HuobiBuilder.php
View file @
dd1cd4d3
...
...
@@ -15,6 +15,8 @@ class HuobiBuilder extends FactoryService
protected
$base_url
=
'https://api.huobi.pro'
;
protected
$supported_symbol
=
'supported_symbol_huobi'
;
protected
$supported_symbol_list
=
'supported_symbol_huobi_list'
;
protected
$supported_symbol_close_sort_list
=
'supported_symbol_close_sort_huobi_list'
;
protected
$supported_symbol_change_sort_list
=
'supported_symbol_change_sort_huobi_list'
;
protected
$quotation_prefix
=
'quotation_huobi_'
;
public
function
getTicker
()
...
...
@@ -111,6 +113,38 @@ class HuobiBuilder extends FactoryService
];
return
[
'code'
=>
$this
->
code
,
'data'
=>
$data
];
}
public
function
TickerSort
()
{
$len
=
$this
->
redis
->
llen
(
$this
->
supported_symbol_list
);
$ticker
=
[];
for
(
$i
=
0
;
$i
<
$len
;
$i
++
)
{
$symbol
=
$this
->
redis
->
lindex
(
$this
->
supported_symbol_list
,
$i
);
list
(
$close
,
$open
)
=
$this
->
redis
->
hmget
(
$this
->
quotation_prefix
.
strtolower
(
$symbol
),
'last'
,
'open'
);
$temp
=
[];
$temp
[
'symbol'
]
=
strtoupper
(
$symbol
);
$temp
[
'close'
]
=
number_format
(
$close
,
6
,
'.'
,
''
);
$temp
[
'change'
]
=
(
0
==
$open
)
?
0
:
(
float
)
sprintf
(
"%0.4f"
,
(
$close
-
$open
)
/
$open
*
100
);
array_push
(
$ticker
,
$temp
);
}
$ticker_sort_close
=
$this
->
arraySort
(
$ticker
,
'close'
);
foreach
(
$ticker_sort_close
as
$val
)
{
$this
->
redis
->
lpush
(
$this
->
supported_symbol_close_sort_list
,
$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
)
{
$keysValue
=
[];
foreach
(
$array
as
$k
=>
$v
)
{
$keysValue
[
$k
]
=
$v
[
$keys
];
}
array_multisort
(
$keysValue
,
$sort
,
$array
);
return
$array
;
}
public
function
getHotTicker
()
{
...
...
common/service/exchange/factory/ZhaobiBuilder.php
View file @
dd1cd4d3
...
...
@@ -13,6 +13,11 @@ use linslin\yii2\curl\Curl;
class
ZhaobiBuilder
extends
FactoryService
{
protected
$base_url
=
'https://api.biqianbao.top'
;
protected
$supported_symbol
=
'supported_symbol_zhaobi'
;
protected
$supported_symbol_list
=
'supported_symbol_zhaobi_list'
;
protected
$supported_symbol_close_sort_list
=
'supported_symbol_close_sort_zhaobi_list'
;
protected
$supported_symbol_change_sort_list
=
'supported_symbol_change_sort_zhaobi_list'
;
protected
$quotation_prefix
=
'quotation_zhaobi_'
;
public
function
getTickerFromCache
()
{
...
...
@@ -61,6 +66,35 @@ class ZhaobiBuilder extends FactoryService
return
[
'code'
=>
$this
->
code
,
'data'
=>
$data
];
}
public
function
TickerSort
()
{
$keys
=
$this
->
redis
->
smembers
(
$this
->
supported_symbol
);
if
(
false
==
$this
->
redis
->
exists
(
$this
->
supported_symbol_list
))
{
foreach
(
$keys
as
$val
)
{
$this
->
redis
->
lpush
(
$this
->
supported_symbol_list
,
$val
);
}
}
$len
=
$this
->
redis
->
llen
(
$this
->
supported_symbol_list
);
$ticker
=
[];
for
(
$i
=
0
;
$i
<
$len
;
$i
++
)
{
$symbol
=
$this
->
redis
->
lindex
(
$this
->
supported_symbol_list
,
$i
);
list
(
$close
,
$open
)
=
$this
->
redis
->
hmget
(
$this
->
quotation_prefix
.
strtolower
(
$symbol
),
'last'
,
'open'
);
$temp
=
[];
$temp
[
'symbol'
]
=
strtoupper
(
$symbol
);
$temp
[
'close'
]
=
number_format
(
$close
,
6
,
'.'
,
''
);
$temp
[
'change'
]
=
(
0
==
$open
)
?
0
:
(
float
)
sprintf
(
"%0.4f"
,
(
$close
-
$open
)
/
$open
*
100
);
array_push
(
$ticker
,
$temp
);
}
$ticker_sort_close
=
$this
->
arraySort
(
$ticker
,
'close'
);
foreach
(
$ticker_sort_close
as
$val
)
{
$this
->
redis
->
lpush
(
$this
->
supported_symbol_close_sort_list
,
$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'
]);
}
}
public
function
getNotice
(
$params
=
[])
{
$curl
=
new
Curl
();
...
...
@@ -90,6 +124,15 @@ class ZhaobiBuilder extends FactoryService
];
}
return
[
'code'
=>
$this
->
code
,
'notice'
=>
$data
];
}
protected
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
console/controllers/TickerSortController.php
0 → 100644
View file @
dd1cd4d3
<?php
namespace
console\controllers
;
use
common\business\Chain33Business
;
use
common\models\psources\CoinGameBet
;
use
common\service\chain33\Chain33Service
;
use
common\service\exchange\ExchangeBuilderFactory
;
use
yii\console\Controller
;
use
Yii
;
class
TickerSortController
extends
Controller
{
/**
* 行情排序
*/
public
function
actionIndex
()
{
$class
=
[
'Binance'
,
'Huobi'
,
'Zhaobi'
];
foreach
(
$class
as
$val
)
{
go
(
function
()
use
(
$val
)
{
\Co
::
sleep
(
0.5
);
$ticker_builder
=
ExchangeBuilderFactory
::
create
(
$val
);
$ticker_builder
->
TickerSort
();
});
}
}
}
\ 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