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
9c807aa6
Commit
9c807aa6
authored
Sep 18, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/ws_ticker' into 'master'
行情走cache See merge request
!119
parents
45ebad99
1e1420a9
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
88 additions
and
50 deletions
+88
-50
TickerController.php
api/controllers/TickerController.php
+22
-22
BinanceBuilder.php
common/service/exchange/factory/BinanceBuilder.php
+38
-0
FactoryService.php
common/service/exchange/factory/FactoryService.php
+4
-1
HuobiBuilder.php
common/service/exchange/factory/HuobiBuilder.php
+22
-24
ZhaobiBuilder.php
common/service/exchange/factory/ZhaobiBuilder.php
+2
-3
No files found.
api/controllers/TickerController.php
View file @
9c807aa6
...
...
@@ -15,27 +15,6 @@ class TickerController extends BaseController
protected
$basic_coin
=
[
'ETH'
,
'BTC'
,
'USDT'
,
'BTY'
];
protected
$basic_price
=
[];
public
function
init
()
{
$curl
=
new
Curl
();
$data
=
[
"names"
=>
[
"eth,ethereum"
,
"btc,btc"
,
"usdt,ethereum"
,
"bty,bty"
,
]
];
$params
=
json_encode
(
$data
);
$curl
->
setHeader
(
'Content-Type'
,
'application/json'
);
$curl
->
setRawPostData
(
$params
);
$res
=
$curl
->
post
(
'https://b.biqianbao.net/interface/coin/coin-index'
,
true
);
$res
=
json_decode
(
$res
,
true
);
foreach
(
$res
[
'data'
]
as
$val
)
{
$this
->
basic_price
[
$val
[
'name'
]]
=
$val
[
'rmb'
];
}
}
public
function
actionIndex
()
{
$device_code
=
Yii
::
$app
->
request
->
get
(
'device_code'
,
''
);
...
...
@@ -71,6 +50,24 @@ class TickerController extends BaseController
public
function
actionOptional
()
{
$curl
=
new
Curl
();
$data
=
[
"names"
=>
[
"eth,ethereum"
,
"btc,btc"
,
"usdt,ethereum"
,
"bty,bty"
,
]
];
$params
=
json_encode
(
$data
);
$curl
->
setHeader
(
'Content-Type'
,
'application/json'
);
$curl
->
setRawPostData
(
$params
);
$res
=
$curl
->
post
(
'https://b.biqianbao.net/interface/coin/coin-index'
,
true
);
$res
=
json_decode
(
$res
,
true
);
foreach
(
$res
[
'data'
]
as
$val
)
{
$this
->
basic_price
[
$val
[
'name'
]]
=
$val
[
'rmb'
];
}
$code
=
-
1
;
$msg
=
'fail'
;
$data
=
null
;
...
...
@@ -134,7 +131,7 @@ class TickerController extends BaseController
$temp
[
'close'
]
=
(
float
)
sprintf
(
"%0.6f"
,
$quotation
[
'last'
]);
$temp
[
'close_usd'
]
=
(
float
)
sprintf
(
"%0.6f"
,
$quotation
[
'last'
]
*
$this
->
basic_price
[
$tag_second
][
'usd'
]);
$temp
[
'close_rmb'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$quotation
[
'last'
]
*
$this
->
basic_price
[
$tag_second
][
'rmb'
]);
$temp
[
'change'
]
=
(
float
)
sprintf
(
"%0.4f"
,
(
$quotation
[
'last'
]
-
$quotation
[
'open'
])
/
$quotation
[
'open'
]
*
100
);
$temp
[
'change'
]
=
(
0
==
$quotation
[
'open'
])
?
0
:
(
float
)
sprintf
(
"%0.4f"
,
(
$quotation
[
'last'
]
-
$quotation
[
'open'
])
/
$quotation
[
'open'
]
*
100
);
$temp
[
'high_usd'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$quotation
[
'high'
]
*
$this
->
basic_price
[
$tag_second
][
'usd'
]);
$temp
[
'low_usd'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$quotation
[
'low'
]
*
$this
->
basic_price
[
$tag_second
][
'usd'
]);
$temp
[
'high_rmb'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$quotation
[
'high'
]
*
$this
->
basic_price
[
$tag_second
][
'rmb'
]);
...
...
@@ -142,12 +139,15 @@ class TickerController extends BaseController
$temp
[
'platform_us'
]
=
$val
[
'platform'
];
if
(
'ZHAOBI'
==
strtoupper
(
$val
[
'platform'
]))
{
$temp
[
'platform_zh'
]
=
'找币'
;
$temp
[
'platform_us'
]
=
'zhaobi'
;
}
if
(
'HUOBI'
==
strtoupper
(
$val
[
'platform'
]))
{
$temp
[
'platform_zh'
]
=
'火币'
;
$temp
[
'platform_us'
]
=
'huobi'
;
}
if
(
'BINANCE'
==
strtoupper
(
$val
[
'platform'
]))
{
$temp
[
'platform_zh'
]
=
'币安'
;
$temp
[
'platform_us'
]
=
'binance'
;
}
array_push
(
$data
,
$temp
);
}
...
...
common/service/exchange/factory/BinanceBuilder.php
View file @
9c807aa6
...
...
@@ -13,6 +13,8 @@ use linslin\yii2\curl\Curl;
class
BinanceBuilder
extends
FactoryService
{
protected
$base_url
=
'https://api.binance.com'
;
protected
$supported_symbol
=
'supported_symbol_binance'
;
protected
$quotation_prefix
=
'quotation_binance_'
;
public
function
getTicker
()
{
...
...
@@ -50,4 +52,39 @@ class BinanceBuilder extends FactoryService
}
return
[
'code'
=>
$this
->
code
,
'ticker'
=>
$ticker
];
}
public
function
getTickerFromCache
()
{
$keys
=
$this
->
redis
->
smembers
(
$this
->
supported_symbol
);
$ticker
=
[];
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
]))
{
list
(
$low
,
$high
,
$close
,
$open
,
$vol
)
=
$this
->
redis
->
hmget
(
$this
->
quotation_prefix
.
strtolower
(
$val
),
'low'
,
'high'
,
'last'
,
'open'
,
'vol'
);
$temp
=
[];
$temp
[
'symbol'
]
=
strtoupper
(
$explode_arr
[
0
])
.
'/'
.
$coin
;
$temp
[
'currency'
]
=
strtoupper
(
$explode_arr
[
0
]);
$temp
[
'base_currency'
]
=
strtoupper
(
$coin
);
$temp
[
'close'
]
=
number_format
(
$close
,
6
,
'.'
,
''
);
$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.4f"
,
(
$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'
]
=
'binance'
;
array_push
(
$ticker
,
$temp
);
}
}
}
if
(
count
(
$ticker
)
>
0
)
{
$this
->
code
=
0
;
}
return
[
'code'
=>
$this
->
code
,
'ticker'
=>
$ticker
];
}
}
\ No newline at end of file
common/service/exchange/factory/FactoryService.php
View file @
9c807aa6
...
...
@@ -16,7 +16,7 @@ abstract class FactoryService
protected
$basic_coin
=
[
'ETH'
,
'BTC'
,
'USDT'
,
'BTY'
];
protected
$basic_price
=
[];
protected
$redis
;
public
function
__construct
()
{
...
...
@@ -39,5 +39,7 @@ abstract class FactoryService
$this
->
basic_price
[
$val
[
'name'
]][
'rmb'
]
=
$val
[
'rmb'
];
$this
->
basic_price
[
$val
[
'name'
]][
'usd'
]
=
$val
[
'usd'
];
}
$this
->
redis
=
\Yii
::
$app
->
redis
;
}
}
\ No newline at end of file
common/service/exchange/factory/HuobiBuilder.php
View file @
9c807aa6
...
...
@@ -35,7 +35,7 @@ class HuobiBuilder extends FactoryService
$temp
[
'close'
]
=
number_format
(
$val
[
'close'
],
6
,
'.'
,
''
);
$temp
[
'close_usd'
]
=
(
float
)
sprintf
(
"%0.6f"
,
$val
[
'close'
]
*
$this
->
basic_price
[
$coin
][
'usd'
]);
$temp
[
'close_rmb'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'close'
]
*
$this
->
basic_price
[
$coin
][
'rmb'
]);
$temp
[
'change'
]
=
(
float
)
sprintf
(
"%0.4f"
,
(
$val
[
'close'
]
-
$val
[
'open'
])
/
$val
[
'open'
]
*
100
);
$temp
[
'change'
]
=
(
f
alse
==
$val
[
'open'
])
?
0
:
(
f
loat
)
sprintf
(
"%0.4f"
,
(
$val
[
'close'
]
-
$val
[
'open'
])
/
$val
[
'open'
]
*
100
);
$temp
[
'high_usd'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'high'
]
*
$this
->
basic_price
[
$coin
][
'usd'
]);
$temp
[
'low_usd'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'low'
]
*
$this
->
basic_price
[
$coin
][
'usd'
]);
$temp
[
'high_rmb'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'high'
]
*
$this
->
basic_price
[
$coin
][
'rmb'
]);
...
...
@@ -43,7 +43,7 @@ class HuobiBuilder extends FactoryService
$temp
[
'vol'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'vol'
]);
$temp
[
'optional'
]
=
false
;
$temp
[
'platform_zh'
]
=
'火币'
;
$temp
[
'platform_us'
]
=
'huo
B
i'
;
$temp
[
'platform_us'
]
=
'huo
b
i'
;
array_push
(
$ticker
,
$temp
);
break
;
}
...
...
@@ -55,14 +55,13 @@ class HuobiBuilder extends FactoryService
public
function
getTickerFromCache
()
{
$redis
=
\Yii
::
$app
->
redis
;
$keys
=
$redis
->
smembers
(
$this
->
supported_symbol
);
$keys
=
$this
->
redis
->
smembers
(
$this
->
supported_symbol
);
$ticker
=
[];
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
]))
{
list
(
$low
,
$high
,
$close
,
$open
,
$vol
)
=
$
redis
->
hmget
(
$this
->
quotation_prefix
.
strtolower
(
$val
),
'low'
,
'high'
,
'last'
,
'open'
,
'vol'
);
list
(
$low
,
$high
,
$close
,
$open
,
$vol
)
=
$
this
->
redis
->
hmget
(
$this
->
quotation_prefix
.
strtolower
(
$val
),
'low'
,
'high'
,
'last'
,
'open'
,
'vol'
);
$temp
=
[];
$temp
[
'symbol'
]
=
strtoupper
(
$explode_arr
[
0
])
.
'/'
.
$coin
;
$temp
[
'currency'
]
=
strtoupper
(
$explode_arr
[
0
]);
...
...
@@ -78,46 +77,45 @@ class HuobiBuilder extends FactoryService
$temp
[
'vol'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$vol
);
$temp
[
'optional'
]
=
false
;
$temp
[
'platform_zh'
]
=
'火币'
;
$temp
[
'platform_us'
]
=
'huo
B
i'
;
$temp
[
'platform_us'
]
=
'huo
b
i'
;
array_push
(
$ticker
,
$temp
);
}
}
}
echo
json_encode
(
$ticker
);
exit
;
if
(
count
(
$ticker
)
>
0
)
{
$this
->
code
=
0
;
}
return
[
'code'
=>
$this
->
code
,
'ticker'
=>
$ticker
];
}
public
function
getHotTicker
()
{
$curl
=
new
Curl
();
$api
=
$this
->
base_url
.
'/market/detail'
;
$symbol
=
[
'btcusdt'
,
'ethusdt'
,
'eosusdt'
];
$ticker
=
[];
$this
->
code
=
0
;
foreach
(
$symbol
as
$key
=>
$val
)
{
$url
=
$api
.
'?symbol='
.
$val
;
$res
=
$curl
->
get
(
$url
,
false
);
if
(
isset
(
$res
[
'status'
])
&&
'ok'
==
$res
[
'status'
])
{
foreach
(
$symbol
as
$val
)
{
list
(
$low
,
$high
,
$close
,
$open
,
$vol
)
=
$this
->
redis
->
hmget
(
$this
->
quotation_prefix
.
strtolower
(
$val
),
'low'
,
'high'
,
'last'
,
'open'
,
'vol'
);
$explode_arr
=
explode
(
'usdt'
,
$val
);
$temp
=
[];
$temp
[
'symbol'
]
=
strtoupper
(
$explode_arr
[
0
])
.
'/USDT'
;
$temp
[
'currency'
]
=
strtoupper
(
$explode_arr
[
0
]);
$temp
[
'base_currency'
]
=
'USDT'
;
$temp
[
'close'
]
=
(
float
)
sprintf
(
"%0.6f"
,
$res
[
'tick'
][
'close'
]
);
$temp
[
'close_usd'
]
=
(
float
)
sprintf
(
"%0.6f"
,
$res
[
'tick'
][
'close'
]
*
$this
->
basic_price
[
'USDT'
][
'usd'
]);
$temp
[
'close_rmb'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$res
[
'tick'
][
'close'
]
*
$this
->
basic_price
[
'USDT'
][
'rmb'
]);
$temp
[
'change'
]
=
(
float
)
sprintf
(
"%0.4f"
,
(
$res
[
'tick'
][
'close'
]
-
$res
[
'tick'
][
'open'
])
/
$res
[
'tick'
][
'open'
]
*
100
);
$temp
[
'high_usd'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$res
[
'tick'
][
'high'
]
*
$this
->
basic_price
[
'USDT'
][
'usd'
]);
$temp
[
'low_usd'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$res
[
'tick'
][
'low'
]
*
$this
->
basic_price
[
'USDT'
][
'usd'
]);
$temp
[
'high_rmb'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$res
[
'tick'
][
'high'
]
*
$this
->
basic_price
[
'USDT'
][
'rmb'
]);
$temp
[
'low_rmb'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$res
[
'tick'
][
'low'
]
*
$this
->
basic_price
[
'USDT'
][
'rmb'
]);
$temp
[
'vol'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$res
[
'tick'
][
'amount'
]
);
$temp
[
'close'
]
=
(
float
)
sprintf
(
"%0.6f"
,
$close
);
$temp
[
'close_usd'
]
=
(
float
)
sprintf
(
"%0.6f"
,
$close
*
$this
->
basic_price
[
'USDT'
][
'usd'
]);
$temp
[
'close_rmb'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$close
*
$this
->
basic_price
[
'USDT'
][
'rmb'
]);
$temp
[
'change'
]
=
(
0
==
$open
)
?
0
:
(
float
)
sprintf
(
"%0.4f"
,
(
$close
-
$open
)
/
$open
*
100
);
$temp
[
'high_usd'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$high
*
$this
->
basic_price
[
'USDT'
][
'usd'
]);
$temp
[
'low_usd'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$low
*
$this
->
basic_price
[
'USDT'
][
'usd'
]);
$temp
[
'high_rmb'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$high
*
$this
->
basic_price
[
'USDT'
][
'rmb'
]);
$temp
[
'low_rmb'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$low
*
$this
->
basic_price
[
'USDT'
][
'rmb'
]);
$temp
[
'vol'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$vol
);
array_push
(
$ticker
,
$temp
);
}
if
(
count
(
$ticker
)
>
0
)
{
$this
->
code
=
0
;
}
return
[
'code'
=>
$this
->
code
,
'ticker'
=>
$ticker
];
}
...
...
common/service/exchange/factory/ZhaobiBuilder.php
View file @
9c807aa6
...
...
@@ -14,7 +14,7 @@ class ZhaobiBuilder extends FactoryService
{
protected
$base_url
=
'https://api.biqianbao.top'
;
public
function
getTicker
()
public
function
getTicker
FromCache
()
{
$curl
=
new
Curl
();
$api
=
$this
->
base_url
.
'/api/data/Ticker?sort=cname'
;
...
...
@@ -37,7 +37,7 @@ class ZhaobiBuilder extends FactoryService
$temp
[
'close'
]
=
(
float
)
sprintf
(
"%0.6f"
,
$val
[
'last'
]);
$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'
]);
$temp
[
'change'
]
=
(
float
)
sprintf
(
"%0.4f"
,
(
$val
[
'last'
]
-
$val
[
'open'
])
/
$val
[
'open'
]
*
100
);
$temp
[
'change'
]
=
(
0
==
$val
[
'open'
])
?
0
:
(
float
)
sprintf
(
"%0.4f"
,
(
$val
[
'last'
]
-
$val
[
'open'
])
/
$val
[
'open'
]
*
100
);
$temp
[
'high_usd'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'high'
]
*
$this
->
basic_price
[
$coin
][
'usd'
]);
$temp
[
'low_usd'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'low'
]
*
$this
->
basic_price
[
$coin
][
'usd'
]);
$temp
[
'high_rmb'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'high'
]
*
$this
->
basic_price
[
$coin
][
'rmb'
]);
...
...
@@ -47,7 +47,6 @@ class ZhaobiBuilder extends FactoryService
$temp
[
'platform_zh'
]
=
'找币'
;
$temp
[
'platform_us'
]
=
'zhaobi'
;
array_push
(
$ticker
,
$temp
);
break
;
}
}
}
...
...
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