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
dbd91bc4
Commit
dbd91bc4
authored
Oct 15, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
行情排序
parent
9f223312
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
124 additions
and
2 deletions
+124
-2
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
+26
-0
TickerController.php
console/controllers/TickerController.php
+26
-0
No files found.
common/service/exchange/factory/BinanceBuilder.php
View file @
dbd91bc4
...
...
@@ -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 @
dbd91bc4
...
...
@@ -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 @
dbd91bc4
...
...
@@ -13,6 +13,9 @@ 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_close_sort_list
=
'supported_symbol_close_sort_zhaobi_list'
;
protected
$supported_symbol_change_sort_list
=
'supported_symbol_change_sort_zhaobi_list'
;
public
function
getTickerFromCache
()
{
...
...
@@ -61,6 +64,29 @@ class ZhaobiBuilder extends FactoryService
return
[
'code'
=>
$this
->
code
,
'data'
=>
$data
];
}
public
function
TickerSort
()
{
$len
=
$this
->
redis
->
llen
(
$this
->
supported_symbol
);
$ticker
=
[];
for
(
$i
=
0
;
$i
<
$len
;
$i
++
)
{
$symbol
=
$this
->
redis
->
lindex
(
$this
->
supported_symbol
,
$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
();
...
...
console/controllers/TickerController.php
0 → 100644
View file @
dbd91bc4
<?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
TickerController
extends
Controller
{
/**
* 行情排序
*/
public
function
actionTickerSort
()
{
$class
=
[
/*'Binance', 'Huobi', */
'Zhaobi'
];
foreach
(
$class
as
$val
)
{
$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