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
8ed3a4ce
Commit
8ed3a4ce
authored
Aug 23, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
c332ed8f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
14 deletions
+26
-14
WorkermanWebSocketController.php
console/controllers/WorkermanWebSocketController.php
+26
-14
No files found.
console/controllers/WorkermanWebSocketController.php
View file @
8ed3a4ce
...
@@ -61,14 +61,20 @@ class WorkermanWebSocketController extends Controller
...
@@ -61,14 +61,20 @@ class WorkermanWebSocketController extends Controller
// 4 processes
// 4 processes
$wsWorker
->
count
=
4
;
$wsWorker
->
count
=
4
;
$wsWorker
->
uidConnections
=
[];
global
$uids
;
// Emitted when new connection come
// Emitted when new connection come
$wsWorker
->
onConnect
=
function
(
$connection
)
{
$wsWorker
->
onConnect
=
function
(
$connection
)
{
echo
"New connection
\n
"
;
echo
"New connection
\n
"
;
};
};
// Emitted when data received
// Emitted when data received
$wsWorker
->
onMessage
=
function
(
$connection
,
$data
)
{
$wsWorker
->
onMessage
=
function
(
$connection
,
$data
)
use
(
$wsWorker
,
$uids
)
{
if
(
!
isset
(
$connection
->
uid
))
{
$connection
->
uid
=
$data
;
$wsWorker
->
uidConnections
[
$connection
->
uid
]
=
$connection
;
echo
$connection
->
uid
.
' 一共 '
.
count
(
$wsWorker
->
uidConnections
[
$connection
->
uid
])
.
PHP_EOL
;
}
if
(
'binance'
==
$data
)
{
if
(
'binance'
==
$data
)
{
$con
=
new
\Workerman\Connection\AsyncTcpConnection
(
"ws://stream.binance.com:9443/ws/!ticker@arr"
);
$con
=
new
\Workerman\Connection\AsyncTcpConnection
(
"ws://stream.binance.com:9443/ws/!ticker@arr"
);
$con
->
transport
=
'ssl'
;
$con
->
transport
=
'ssl'
;
...
@@ -94,7 +100,7 @@ class WorkermanWebSocketController extends Controller
...
@@ -94,7 +100,7 @@ class WorkermanWebSocketController extends Controller
}
}
}
}
}
}
$connection
->
send
(
'binance : '
.
json_encode
(
$ticker
));
$connection
->
send
(
'binance : '
.
json_encode
(
$ticker
)
,
$connection
->
id
);
};
};
$con
->
connect
();
$con
->
connect
();
}
elseif
(
'huobi'
==
$data
)
{
}
elseif
(
'huobi'
==
$data
)
{
...
@@ -103,7 +109,7 @@ class WorkermanWebSocketController extends Controller
...
@@ -103,7 +109,7 @@ class WorkermanWebSocketController extends Controller
$con
=
new
\Workerman\Connection\AsyncTcpConnection
(
'ws://api.huobi.pro:443/ws'
);
$con
=
new
\Workerman\Connection\AsyncTcpConnection
(
'ws://api.huobi.pro:443/ws'
);
// 设置以ssl加密方式访问,使之成为wss
// 设置以ssl加密方式访问,使之成为wss
$con
->
transport
=
'ssl'
;
$con
->
transport
=
'ssl'
;
$con
->
onConnect
=
function
(
$con
)
{
$con
->
onConnect
=
function
(
$con
)
{
$data
=
json_encode
([
$data
=
json_encode
([
#'sub' => 'market.btcusdt.kline.1min',
#'sub' => 'market.btcusdt.kline.1min',
#'id' => 'depth' . time(),
#'id' => 'depth' . time(),
...
@@ -111,14 +117,14 @@ class WorkermanWebSocketController extends Controller
...
@@ -111,14 +117,14 @@ class WorkermanWebSocketController extends Controller
]);
]);
$con
->
send
(
$data
);
$con
->
send
(
$data
);
};
};
$con
->
onMessage
=
function
(
$con
,
$data
)
use
(
$connection
)
{
$con
->
onMessage
=
function
(
$con
,
$data
)
use
(
$connection
)
{
$data
=
gzdecode
(
$data
);
$data
=
gzdecode
(
$data
);
$data
=
json_decode
(
$data
,
true
);
$data
=
json_decode
(
$data
,
true
);
if
(
isset
(
$data
[
'ping'
]))
{
if
(
isset
(
$data
[
'ping'
]))
{
$con
->
send
(
json_encode
([
$con
->
send
(
json_encode
([
"pong"
=>
$data
[
'ping'
]
"pong"
=>
$data
[
'ping'
]
]));
]));
}
else
if
(
isset
(
$data
[
'ch'
])
&&
'market.overview'
==
$data
[
'ch'
])
{
}
else
if
(
isset
(
$data
[
'ch'
])
&&
'market.overview'
==
$data
[
'ch'
])
{
$base_coin
=
[
$base_coin
=
[
'ETH'
,
'BTC'
,
'USDT'
,
'BTY'
'ETH'
,
'BTC'
,
'USDT'
,
'BTY'
];
];
...
@@ -130,7 +136,7 @@ class WorkermanWebSocketController extends Controller
...
@@ -130,7 +136,7 @@ class WorkermanWebSocketController extends Controller
$temp
=
[];
$temp
=
[];
$temp
[
'symbol'
]
=
$explode_arr
[
0
]
.
'/'
.
$coin
;
$temp
[
'symbol'
]
=
$explode_arr
[
0
]
.
'/'
.
$coin
;
$temp
[
'close'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'close'
]);
$temp
[
'close'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'close'
]);
$temp
[
'change'
]
=
(
float
)
sprintf
(
"%0.4f"
,
(
$val
[
'close'
]
-
$val
[
'open'
])
/
$val
[
'open'
]
*
100
);
$temp
[
'change'
]
=
(
0
==
$val
[
'open'
])
?
0
:
(
float
)
sprintf
(
"%0.4f"
,
(
$val
[
'close'
]
-
$val
[
'open'
])
/
$val
[
'open'
]
*
100
);
$temp
[
'high'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'high'
]);
$temp
[
'high'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'high'
]);
$temp
[
'low'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'low'
]);
$temp
[
'low'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'low'
]);
$temp
[
'vol'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'vol'
]);
$temp
[
'vol'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'vol'
]);
...
@@ -139,13 +145,19 @@ class WorkermanWebSocketController extends Controller
...
@@ -139,13 +145,19 @@ class WorkermanWebSocketController extends Controller
}
}
}
}
}
}
$connection
->
send
(
'huobi : '
.
json_encode
(
$ticker
));
$connection
->
send
(
'huobi : '
.
json_encode
(
$ticker
),
$connection
->
id
);
}
else
{}
}
else
{
}
};
};
$con
->
onClose
=
function
(
$con
){
$con
->
onClose
=
function
(
$con
)
use
(
$wsWorker
)
{
echo
"connection closed
\n
"
;
echo
$con
->
id
,
"connection closed
\n
"
;
if
(
isset
(
$con
->
uid
))
{
// 连接断开时删除映射
unset
(
$wsWorker
->
uidConnections
[
$con
->
uid
]);
}
};
};
$con
->
onError
=
function
(
$con
,
$code
,
$msg
)
{
$con
->
onError
=
function
(
$con
,
$code
,
$msg
)
{
echo
"Error code:
$code
msg:
$msg
\n
"
;
echo
"Error code:
$code
msg:
$msg
\n
"
;
};
};
$con
->
connect
();
$con
->
connect
();
...
@@ -153,7 +165,7 @@ class WorkermanWebSocketController extends Controller
...
@@ -153,7 +165,7 @@ class WorkermanWebSocketController extends Controller
$connection
->
websocketType
=
Websocket
::
BINARY_TYPE_ARRAYBUFFER
;
$connection
->
websocketType
=
Websocket
::
BINARY_TYPE_ARRAYBUFFER
;
$con
=
new
\Workerman\Connection\AsyncTcpConnection
(
"ws://real.okex.com:8443/ws/v3"
);
$con
=
new
\Workerman\Connection\AsyncTcpConnection
(
"ws://real.okex.com:8443/ws/v3"
);
$con
->
transport
=
'ssl'
;
$con
->
transport
=
'ssl'
;
$con
->
onConnect
=
function
(
$con
)
{
$con
->
onConnect
=
function
(
$con
)
{
$data
=
json_encode
([
$data
=
json_encode
([
'op'
=>
'subscribe'
,
'op'
=>
'subscribe'
,
'args'
=>
[
'args'
=>
[
...
...
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