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
cc0863b0
Commit
cc0863b0
authored
Aug 21, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
1c395bc1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
2 deletions
+52
-2
WorkermanWebSocketController.php
console/controllers/WorkermanWebSocketController.php
+52
-2
No files found.
console/controllers/WorkermanWebSocketController.php
View file @
cc0863b0
...
@@ -94,11 +94,61 @@ class WorkermanWebSocketController extends Controller
...
@@ -94,11 +94,61 @@ class WorkermanWebSocketController extends Controller
}
}
}
}
}
}
$connection
->
send
(
date
(
"Y-m-d H:i:s"
)
.
'
: '
.
json_encode
(
$ticker
));
$connection
->
send
(
'binance
: '
.
json_encode
(
$ticker
));
};
};
$con
->
connect
();
$con
->
connect
();
}
elseif
(
'huobi'
==
$data
)
{
}
elseif
(
'huobi'
==
$data
)
{
$connection
->
send
(
'huobi'
);
//$connection->websocketType = Websocket::BINARY_TYPE_ARRAYBUFFER;
// ssl需要访问443端口
$con
=
new
\Workerman\Connection\AsyncTcpConnection
(
'ws://api.huobi.pro:443/ws'
);
// 设置以ssl加密方式访问,使之成为wss
$con
->
transport
=
'ssl'
;
$con
->
onConnect
=
function
(
$con
)
{
$data
=
json_encode
([
#'sub' => 'market.btcusdt.kline.1min',
#'id' => 'depth' . time(),
'sub'
=>
'market.overview'
]);
$con
->
send
(
$data
);
};
$con
->
onMessage
=
function
(
$con
,
$data
)
use
(
$connection
)
{
$data
=
gzdecode
(
$data
);
$data
=
json_decode
(
$data
,
true
);
if
(
isset
(
$data
[
'ping'
]))
{
$con
->
send
(
json_encode
([
"pong"
=>
$data
[
'ping'
]
]));
}
else
if
(
isset
(
$data
[
'ch'
])
&&
'market.overview'
==
$data
[
'ch'
]){
$base_coin
=
[
'ETH'
,
'BTC'
,
'USDT'
,
'BTY'
];
$ticker
=
[];
foreach
(
$data
[
'data'
]
as
$val
)
{
foreach
(
$base_coin
as
$k
=>
$coin
)
{
$explode_arr
=
explode
(
$coin
,
strtoupper
(
$val
[
'symbol'
]));
if
(
2
==
count
(
$explode_arr
)
&&
empty
(
$explode_arr
[
1
]))
{
$temp
=
[];
$temp
[
'symbol'
]
=
$explode_arr
[
0
]
.
'/'
.
$coin
;
$temp
[
'close'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'close'
]);
$temp
[
'change'
]
=
(
float
)
sprintf
(
"%0.4f"
,
(
$val
[
'close'
]
-
$val
[
'open'
])
/
$val
[
'open'
]
*
100
);
$temp
[
'high'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'high'
]);
$temp
[
'low'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'low'
]);
$temp
[
'vol'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'vol'
]);
array_push
(
$ticker
,
$temp
);
break
;
}
}
}
$connection
->
send
(
'huobi : '
.
json_encode
(
$ticker
));
}
else
{}
};
$con
->
onClose
=
function
(
$con
){
echo
"connection closed
\n
"
;
};
$con
->
onError
=
function
(
$con
,
$code
,
$msg
){
echo
"Error code:
$code
msg:
$msg
\n
"
;
};
$con
->
connect
();
}
elseif
(
'okex'
==
$data
)
{
}
elseif
(
'okex'
==
$data
)
{
$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"
);
...
...
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