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
0dd97776
Commit
0dd97776
authored
Aug 14, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test
parent
eb1c5912
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
16 deletions
+37
-16
WorkermanWebSocketController.php
console/controllers/WorkermanWebSocketController.php
+37
-16
No files found.
console/controllers/WorkermanWebSocketController.php
View file @
0dd97776
<?php
namespace
console\controllers
;
use
Workerman\Worker
;
...
...
@@ -67,22 +68,42 @@ class WorkermanWebSocketController extends Controller
// Emitted when data received
$wsWorker
->
onMessage
=
function
(
$connection
,
$data
)
{
// ssl需要访问443端口
$con
=
new
\Workerman\Connection\AsyncTcpConnection
(
"ws://stream.binance.com:9443/ws/!ticker@arr"
);
// 设置以ssl加密方式访问,使之成为wss
$con
->
transport
=
'ssl'
;
// $con->onConnect = function($con) {
// $data = json_encode([
// 'sub' => 'market.btcusdt.kline.1min',
// 'id' => 'depth' . time()
// ]);
// $con->send($data);
// };
$con
->
onMessage
=
function
(
$con
,
$data
)
use
(
$connection
)
{
$connection
->
send
(
date
(
"Y-m-d H:i:s"
)
.
' : '
.
$data
);
};
$con
->
connect
();
if
(
'binance'
==
$data
)
{
$con
=
new
\Workerman\Connection\AsyncTcpConnection
(
"ws://stream.binance.com:9443/ws/!ticker@arr"
);
$con
->
transport
=
'ssl'
;
$con
->
onMessage
=
function
(
$con
,
$data
)
use
(
$connection
)
{
$base_coin
=
[
'ETH'
,
'BTC'
,
'USDT'
,
'BTC'
];
$result
=
json_decode
(
$data
,
true
);
$ticker
=
[];
foreach
(
$result
as
$val
)
{
go
(
function
()
use
(
$val
,
$base_coin
)
{
\Co
::
sleep
(
0.5
);
foreach
(
$base_coin
as
$k
=>
$coin
)
{
$explode_arr
=
explode
(
$coin
,
$val
[
's'
]);
if
(
2
==
count
(
$explode_arr
)
&&
empty
(
$explode_arr
[
1
]))
{
$ticker
[
$k
][
'symbol'
]
=
$explode_arr
[
0
]
.
'/'
.
$coin
;
$ticker
[
$k
][
'close'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'c'
]);
$ticker
[
$k
][
'change'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'p'
]
*
100
);
$ticker
[
$k
][
'high'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'h'
]);
$ticker
[
$k
][
'low'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'l'
]);
$ticker
[
$k
][
'vol'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'v'
]);
}
}
});
}
$connection
->
send
(
date
(
"Y-m-d H:i:s"
)
.
' : '
.
json_encode
(
$ticker
));
};
$con
->
connect
();
}
elseif
(
'huobi'
==
$data
)
{
$connection
->
send
(
'huobi'
);
}
elseif
(
'okex'
==
$data
)
{
$connection
->
send
(
'okex'
);
}
else
{
$connection
->
send
(
'other'
);
}
};
// Emitted when connection closed
...
...
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