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
4e52c5a3
Commit
4e52c5a3
authored
Aug 16, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
okex ticker
parent
784121e5
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
105 additions
and
11 deletions
+105
-11
TickerController.php
api/controllers/TickerController.php
+5
-4
BinanceBuilder.php
common/service/exchange/factory/BinanceBuilder.php
+7
-3
HuobiBuilder.php
common/service/exchange/factory/HuobiBuilder.php
+37
-2
OkexBuilder.php
common/service/exchange/factory/OkexBuilder.php
+56
-2
No files found.
api/controllers/TickerController.php
View file @
4e52c5a3
...
...
@@ -17,16 +17,17 @@ class TickerController extends BaseController
if
(
!
in_array
(
$exchange
,
$exchange_arr
))
{
$msg
=
'不存在的交易平台'
;
$code
=
-
1
;
$data
=
[];
goto
doEnd
;
}
$builder
=
ExchangeBuilderFactory
::
create
(
$exchange
);
$result
=
$builder
->
getTicker
();
$code
=
$result
[
'code'
];
$data
=
$result
[
'ticker'
];
$msg
=
'success'
;
doEnd
:
return
[
'code'
=>
$code
,
'msg'
=>
$msg
];
return
[
'code'
=>
$code
,
'msg'
=>
$msg
,
'data'
=>
$data
];
}
public
function
actionGameTradeUpdate
()
...
...
common/service/exchange/factory/BinanceBuilder.php
View file @
4e52c5a3
...
...
@@ -15,17 +15,20 @@ class BinanceBuilder
protected
$base_url
=
'https://api.binance.com'
;
protected
$base_coin
=
[
'ETH'
,
'BTC'
,
'USDT'
,
'BTC'
];
function
__construct
()
public
function
__construct
()
{
}
function
getTicker
()
public
function
getTicker
()
{
$curl
=
new
Curl
();
$api
=
$this
->
base_url
.
'/api/v1/ticker/24hr'
;
$res
=
$curl
->
get
(
$api
,
false
);
$code
=
-
1
;
$ticker
=
[];
if
(
is_array
(
$res
))
{
$code
=
0
;
foreach
(
$res
as
$val
)
{
foreach
(
$this
->
base_coin
as
$k
=>
$coin
)
{
$explode_arr
=
explode
(
$coin
,
$val
[
'symbol'
]);
...
...
@@ -40,6 +43,6 @@ class BinanceBuilder
}
}
}
echo
json_encode
(
$ticker
);
exit
;
return
[
'code'
=>
$code
,
'ticker'
=>
$ticker
]
;
}
}
\ No newline at end of file
common/service/exchange/factory/HuobiBuilder.php
View file @
4e52c5a3
<?php
namespace
common\service\exchange\factory
;
/**
* Created by PhpStorm.
* User: jiaming
...
...
@@ -8,7 +6,43 @@ namespace common\service\exchange\factory;
* Time: 10:10
*/
namespace
common\service\exchange\factory
;
use
linslin\yii2\curl\Curl
;
class
HuobiBuilder
{
protected
$base_url
=
'https://api.huobi.pro'
;
protected
$base_coin
=
[
'ETH'
,
'BTC'
,
'USDT'
,
'BTC'
];
public
function
__construct
()
{
}
public
function
getTicker
()
{
$curl
=
new
Curl
();
$api
=
$this
->
base_url
.
'/market/tickers'
;
$res
=
$curl
->
get
(
$api
,
false
);
$code
=
-
1
;
$ticker
=
[];
if
(
isset
(
$res
[
'status'
])
&&
'ok'
==
$res
[
'status'
])
{
$code
=
0
;
foreach
(
$res
[
'data'
]
as
$val
)
{
foreach
(
$this
->
base_coin
as
$k
=>
$coin
)
{
$explode_arr
=
explode
(
$coin
,
$val
[
'symbol'
]);
if
(
2
==
count
(
$explode_arr
)
&&
empty
(
$explode_arr
[
1
]))
{
$ticker
[
$val
[
'symbol'
]][
'symbol'
]
=
$explode_arr
[
0
]
.
'/'
.
$coin
;
$ticker
[
$val
[
'symbol'
]][
'close'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'close'
]);
$ticker
[
$val
[
'symbol'
]][
'change'
]
=
(
float
)
sprintf
((
$val
[
'close'
]
-
$val
[
'open'
])
/
$val
[
'open'
]
*
100
);
$ticker
[
$val
[
'symbol'
]][
'high'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'highPrice'
]);
$ticker
[
$val
[
'symbol'
]][
'low'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'lowPrice'
]);
$ticker
[
$val
[
'symbol'
]][
'vol'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'vol'
]);
}
}
}
}
return
[
'code'
=>
$code
,
'ticker'
=>
$ticker
];
}
}
\ No newline at end of file
common/service/exchange/factory/OkexBuilder.php
View file @
4e52c5a3
<?php
namespace
common\service\exchange\factory
;
/**
* Created by PhpStorm.
* User: jiaming
* Date: 2019/8/15
* Time: 10:10
*/
namespace
common\service\exchange\factory
;
use
Yii
;
use
linslin\yii2\curl\Curl
;
class
OkexBuilder
{
protected
$base_url
=
'https://api.huobi.pro'
;
protected
$base_coin
=
[
'ETH'
,
'BTC'
,
'USDT'
,
'BTC'
];
protected
$redis
;
protected
$supported_symbol
=
'supported_symbol_bitfinex_v2'
;
public
function
__construct
()
{
$this
->
redis
=
Yii
::
$app
->
redis
;
}
public
function
getSymbol
()
{
$curl
=
new
Curl
();
$api
=
$this
->
base_url
.
'/v2/spot/markets/products'
;
$res
=
$curl
->
get
(
$api
,
false
);
$res
=
json_decode
(
$res
,
true
);
if
(
isset
(
$res
[
'code'
])
&&
0
==
$res
[
'code'
])
{
foreach
(
$res
[
'data'
]
as
$val
)
{
if
(
$this
->
redis
->
sismember
(
$this
->
supported_symbol
,
$val
[
'symbol'
]))
continue
;
$this
->
redis
->
sadd
(
$this
->
supported_symbol
,
$val
[
'symbol'
]);
}
}
}
public
function
getTicker
()
{
$symbols
=
$this
->
redis
->
smembers
(
$this
->
supported_symbol
);
if
(
empty
(
$symbols
))
$this
->
getSymbol
();
$symbols
=
$this
->
redis
->
smembers
(
$this
->
supported_symbol
);
$curl
=
new
Curl
();
$code
=
-
1
;
$ticker
=
[];
foreach
(
$symbols
as
$symbol
)
{
$api
=
$this
->
base_url
.
'/market/tickers?symbol='
.
$symbol
;
$res
=
$curl
->
get
(
$api
,
false
);
$res
=
json_decode
(
$res
,
true
);
if
(
isset
(
$res
[
'ticker'
]))
{
$code
=
0
;
$symbol
=
strtoupper
(
str_replace
(
'_'
,
'/'
,
$symbol
));
$ticker
[
$symbol
][
'symbol'
]
=
$symbol
;
$ticker
[
$symbol
][
'close'
]
=
$res
[
'ticker'
][
'last'
];
//$ticker[$symbol]['change'] = (float)sprintf(($val['close'] - $val['open']) / $val['open'] * 100);
$ticker
[
$symbol
][
'high'
]
=
$res
[
'ticker'
][
'high'
];
$ticker
[
$symbol
][
'low'
]
=
$res
[
'ticker'
][
'low'
];
$ticker
[
$symbol
][
'vol'
]
=
$res
[
'ticker'
][
'last'
];
}
}
return
[
'code'
=>
$code
,
'ticker'
=>
$ticker
];
}
}
\ No newline at end of file
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