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
19ecbec7
Commit
19ecbec7
authored
Sep 25, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
行情分页
parent
4f03b113
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
76 additions
and
16 deletions
+76
-16
TickerController.php
api/controllers/TickerController.php
+4
-3
BinanceBuilder.php
common/service/exchange/factory/BinanceBuilder.php
+30
-5
FactoryService.php
common/service/exchange/factory/FactoryService.php
+4
-1
HuobiBuilder.php
common/service/exchange/factory/HuobiBuilder.php
+29
-5
ZhaobiBuilder.php
common/service/exchange/factory/ZhaobiBuilder.php
+9
-2
No files found.
api/controllers/TickerController.php
View file @
19ecbec7
...
@@ -17,6 +17,7 @@ class TickerController extends BaseController
...
@@ -17,6 +17,7 @@ class TickerController extends BaseController
public
function
actionIndex
()
public
function
actionIndex
()
{
{
$page
=
Yii
::
$app
->
request
->
get
(
'page'
,
1
);
$device_code
=
Yii
::
$app
->
request
->
get
(
'device_code'
,
''
);
$device_code
=
Yii
::
$app
->
request
->
get
(
'device_code'
,
''
);
$exchange
=
Yii
::
$app
->
request
->
get
(
'exchange'
,
'zhaobi'
);
$exchange
=
Yii
::
$app
->
request
->
get
(
'exchange'
,
'zhaobi'
);
...
@@ -28,14 +29,14 @@ class TickerController extends BaseController
...
@@ -28,14 +29,14 @@ class TickerController extends BaseController
goto
doEnd
;
goto
doEnd
;
}
}
$builder
=
ExchangeBuilderFactory
::
create
(
$exchange
);
$builder
=
ExchangeBuilderFactory
::
create
(
$exchange
);
$result
=
$builder
->
getTickerFromCache
();
$result
=
$builder
->
getTickerFromCache
(
$page
);
$code
=
$result
[
'code'
];
$code
=
$result
[
'code'
];
$data
=
$result
[
'
ticker
'
];
$data
=
$result
[
'
data
'
];
if
(
false
!=
$device_code
)
{
if
(
false
!=
$device_code
)
{
$coin_optional
=
CoinOptional
::
find
()
->
select
(
'symbol'
)
->
where
([
'platform'
=>
$exchange
,
'device_code'
=>
$device_code
])
->
asArray
()
->
all
();
$coin_optional
=
CoinOptional
::
find
()
->
select
(
'symbol'
)
->
where
([
'platform'
=>
$exchange
,
'device_code'
=>
$device_code
])
->
asArray
()
->
all
();
$coin_optional
=
ArrayHelper
::
getColumn
(
$coin_optional
,
'symbol'
);
$coin_optional
=
ArrayHelper
::
getColumn
(
$coin_optional
,
'symbol'
);
foreach
(
$data
as
&
$val
)
{
foreach
(
$data
[
'ticker'
]
as
&
$val
)
{
if
(
in_array
(
$val
[
'symbol'
],
$coin_optional
))
{
if
(
in_array
(
$val
[
'symbol'
],
$coin_optional
))
{
$val
[
'optional'
]
=
true
;
$val
[
'optional'
]
=
true
;
}
}
...
...
common/service/exchange/factory/BinanceBuilder.php
View file @
19ecbec7
...
@@ -14,6 +14,7 @@ class BinanceBuilder extends FactoryService
...
@@ -14,6 +14,7 @@ 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
$quotation_prefix
=
'quotation_binance_'
;
protected
$quotation_prefix
=
'quotation_binance_'
;
public
function
getTicker
()
public
function
getTicker
()
...
@@ -53,9 +54,27 @@ class BinanceBuilder extends FactoryService
...
@@ -53,9 +54,27 @@ class BinanceBuilder extends FactoryService
return
[
'code'
=>
$this
->
code
,
'ticker'
=>
$ticker
];
return
[
'code'
=>
$this
->
code
,
'ticker'
=>
$ticker
];
}
}
public
function
getTickerFromCache
()
public
function
getTickerFromCache
(
$page
=
1
)
{
{
$size
=
0
;
for
(
$i
=
0
;
$i
<
$page
;
$i
++
)
{
$size
+=
50
;
$this
->
end
=
$size
;
}
$this
->
start
=
$this
->
end
-
50
;
$keys
=
$this
->
redis
->
smembers
(
$this
->
supported_symbol
);
$keys
=
$this
->
redis
->
smembers
(
$this
->
supported_symbol
);
if
(
false
==
$this
->
redis
->
exists
(
$this
->
supported_symbol_list
))
{
foreach
(
$keys
as
$val
)
{
foreach
(
$this
->
basic_coin
as
$k
=>
$coin
)
{
$explode_arr
=
explode
(
$coin
,
$val
);
if
(
2
==
count
(
$explode_arr
)
&&
empty
(
$explode_arr
[
1
]))
{
$this
->
redis
->
lpush
(
$this
->
supported_symbol_list
,
$val
);
}
}
}
}
$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
)
{
...
@@ -82,9 +101,14 @@ class BinanceBuilder extends FactoryService
...
@@ -82,9 +101,14 @@ class BinanceBuilder extends FactoryService
}
}
}
}
}
}
if
(
count
(
$ticker
)
>
0
)
{
$this
->
code
=
0
;
$this
->
code
=
0
;
$data
=
[
}
'ticker'
=>
$ticker
,
return
[
'code'
=>
$this
->
code
,
'ticker'
=>
$ticker
];
'page'
=>
[
'pageSize'
=>
50
,
'currentPage'
=>
(
int
)
$page
,
]
];
return
[
'code'
=>
$this
->
code
,
'data'
=>
$data
];
}
}
}
}
\ No newline at end of file
common/service/exchange/factory/FactoryService.php
View file @
19ecbec7
...
@@ -18,6 +18,9 @@ abstract class FactoryService
...
@@ -18,6 +18,9 @@ abstract class FactoryService
protected
$basic_price
=
[];
protected
$basic_price
=
[];
protected
$redis
;
protected
$redis
;
protected
$start
;
protected
$end
;
public
function
__construct
()
public
function
__construct
()
{
{
$curl
=
new
Curl
();
$curl
=
new
Curl
();
...
@@ -32,7 +35,7 @@ abstract class FactoryService
...
@@ -32,7 +35,7 @@ abstract class FactoryService
$params
=
json_encode
(
$data
);
$params
=
json_encode
(
$data
);
$curl
->
setHeader
(
'Content-Type'
,
'application/json'
);
$curl
->
setHeader
(
'Content-Type'
,
'application/json'
);
$curl
->
setRawPostData
(
$params
);
$curl
->
setRawPostData
(
$params
);
$res
=
$curl
->
post
(
'http
s://b.biqianbao.net
/interface/coin/coin-index'
,
true
);
$res
=
$curl
->
post
(
'http
://127.0.0.1:8082
/interface/coin/coin-index'
,
true
);
$res
=
json_decode
(
$res
,
true
);
$res
=
json_decode
(
$res
,
true
);
foreach
(
$res
[
'data'
]
as
$val
)
{
foreach
(
$res
[
'data'
]
as
$val
)
{
...
...
common/service/exchange/factory/HuobiBuilder.php
View file @
19ecbec7
...
@@ -14,6 +14,7 @@ class HuobiBuilder extends FactoryService
...
@@ -14,6 +14,7 @@ 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
$quotation_prefix
=
'quotation_huobi_'
;
protected
$quotation_prefix
=
'quotation_huobi_'
;
public
function
getTicker
()
public
function
getTicker
()
...
@@ -53,9 +54,27 @@ class HuobiBuilder extends FactoryService
...
@@ -53,9 +54,27 @@ class HuobiBuilder extends FactoryService
return
[
'code'
=>
$this
->
code
,
'ticker'
=>
$ticker
];
return
[
'code'
=>
$this
->
code
,
'ticker'
=>
$ticker
];
}
}
public
function
getTickerFromCache
()
public
function
getTickerFromCache
(
$page
=
1
)
{
{
$size
=
0
;
for
(
$i
=
0
;
$i
<
$page
;
$i
++
)
{
$size
+=
50
;
$this
->
end
=
$size
;
}
$this
->
start
=
$this
->
end
-
50
;
$keys
=
$this
->
redis
->
smembers
(
$this
->
supported_symbol
);
$keys
=
$this
->
redis
->
smembers
(
$this
->
supported_symbol
);
if
(
false
==
$this
->
redis
->
exists
(
$this
->
supported_symbol_list
))
{
foreach
(
$keys
as
$val
)
{
foreach
(
$this
->
basic_coin
as
$k
=>
$coin
)
{
$explode_arr
=
explode
(
strtolower
(
$coin
),
$val
);
if
(
2
==
count
(
$explode_arr
)
&&
empty
(
$explode_arr
[
1
]))
{
$this
->
redis
->
lpush
(
$this
->
supported_symbol_list
,
$val
);
}
}
}
}
$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
)
{
...
@@ -82,10 +101,15 @@ class HuobiBuilder extends FactoryService
...
@@ -82,10 +101,15 @@ class HuobiBuilder extends FactoryService
}
}
}
}
}
}
if
(
count
(
$ticker
)
>
0
)
{
$this
->
code
=
0
;
$this
->
code
=
0
;
$data
=
[
}
'ticker'
=>
$ticker
,
return
[
'code'
=>
$this
->
code
,
'ticker'
=>
$ticker
];
'page'
=>
[
'pageSize'
=>
50
,
'currentPage'
=>
(
int
)
$page
,
]
];
return
[
'code'
=>
$this
->
code
,
'data'
=>
$data
];
}
}
public
function
getHotTicker
()
public
function
getHotTicker
()
...
...
common/service/exchange/factory/ZhaobiBuilder.php
View file @
19ecbec7
...
@@ -21,7 +21,6 @@ class ZhaobiBuilder extends FactoryService
...
@@ -21,7 +21,6 @@ class ZhaobiBuilder extends FactoryService
$res
=
$curl
->
get
(
$api
,
false
);
$res
=
$curl
->
get
(
$api
,
false
);
$ticker
=
[];
$ticker
=
[];
if
(
isset
(
$res
[
'message'
])
&&
'OK'
==
$res
[
'message'
])
{
if
(
isset
(
$res
[
'message'
])
&&
'OK'
==
$res
[
'message'
])
{
$this
->
code
=
0
;
$ticker_temp
=
[];
$ticker_temp
=
[];
foreach
(
$res
[
'data'
]
as
$val
)
{
foreach
(
$res
[
'data'
]
as
$val
)
{
$ticker_temp
=
array_merge
(
$ticker_temp
,
$val
);
$ticker_temp
=
array_merge
(
$ticker_temp
,
$val
);
...
@@ -51,7 +50,15 @@ class ZhaobiBuilder extends FactoryService
...
@@ -51,7 +50,15 @@ class ZhaobiBuilder extends FactoryService
}
}
}
}
}
}
return
[
'code'
=>
$this
->
code
,
'ticker'
=>
$ticker
];
$this
->
code
=
0
;
$data
=
[
'ticker'
=>
$ticker
,
'page'
=>
[
'pageSize'
=>
50
,
'currentPage'
=>
1
,
]
];
return
[
'code'
=>
$this
->
code
,
'data'
=>
$data
];
}
}
public
function
getNotice
(
$params
=
[])
public
function
getNotice
(
$params
=
[])
...
...
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