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
f891431f
Commit
f891431f
authored
Nov 15, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/ticker' into 'master'
Feature/ticker See merge request
!194
parents
642fa5fc
22487a52
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
235 additions
and
10 deletions
+235
-10
TickerController.php
api/controllers/TickerController.php
+6
-4
ExchangeBusiness.php
common/business/ExchangeBusiness.php
+3
-1
Bitnasdaq.php
common/service/exchange/Bitnasdaq.php
+57
-0
BinanceBuilder.php
common/service/exchange/factory/BinanceBuilder.php
+7
-1
BitnasdaqBuilder.php
common/service/exchange/factory/BitnasdaqBuilder.php
+146
-0
FactoryService.php
common/service/exchange/factory/FactoryService.php
+1
-1
HuobiBuilder.php
common/service/exchange/factory/HuobiBuilder.php
+7
-1
ZhaobiBuilder.php
common/service/exchange/factory/ZhaobiBuilder.php
+7
-1
TickerController.php
console/controllers/TickerController.php
+1
-1
No files found.
api/controllers/TickerController.php
View file @
f891431f
...
...
@@ -26,7 +26,7 @@ class TickerController extends BaseController
$data_value
=
Yii
::
$app
->
request
->
get
(
'data_value'
,
''
);
$sort_value
=
Yii
::
$app
->
request
->
get
(
'sort_value'
,
''
);
$exchange_arr
=
[
'huobi'
,
'binance'
,
'
okex'
,
'zhaobi
'
];
$exchange_arr
=
[
'huobi'
,
'binance'
,
'
zhaobi'
,
'bitnasdaq
'
];
if
(
!
in_array
(
$exchange
,
$exchange_arr
))
{
$msg
=
'不存在的交易平台'
;
...
...
@@ -168,14 +168,16 @@ class TickerController extends BaseController
}
$symbol
=
explode
(
'/'
,
$val
[
'symbol'
]);
$tag_first
=
$symbol
[
0
];
$tag_first
=
$
currency
=
$
symbol
[
0
];
$tag_second
=
$symbol
[
1
];
if
(
'BCH'
==
strtoupper
(
$tag_first
)){
$tag_first
=
'BCC'
;
}
$exchange
=
ExchangeFactory
::
createExchange
(
$exchange
);
$quotation
=
$exchange
->
getTicker
(
strtolower
(
$tag_first
),
strtolower
(
$tag_second
));
if
(
empty
(
$quotation
))
continue
;
$temp
[
'symbol'
]
=
$val
[
'symbol'
];
$temp
[
'currency'
]
=
strtoupper
(
$
tag_first
);
$temp
[
'currency'
]
=
strtoupper
(
$
currency
);
$temp
[
'base_currency'
]
=
strtoupper
(
$tag_second
);
$temp
[
'close'
]
=
rtrim
(
sprintf
(
'%.8f'
,
floatval
(
$quotation
[
'last'
])),
'0'
);
$temp
[
'close_usd'
]
=
rtrim
(
sprintf
(
'%.6f'
,
floatval
(
$quotation
[
'last'
]
*
$this
->
basic_price
[
$tag_second
][
'usd'
])),
'0'
);
...
...
common/business/ExchangeBusiness.php
View file @
f891431f
...
...
@@ -45,7 +45,9 @@ class ExchangeBusiness
16
=>
'Ceohk'
,
17
=>
'Biki'
,
18
=>
'Bilaxy'
,
19
=>
'Boc'
19
=>
'Bitnasdaq'
,
20
=>
'Boc'
];
/**
...
...
common/service/exchange/Bitnasdaq.php
0 → 100644
View file @
f891431f
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-6-26
* Time: 下午7:21
*/
namespace
common\service\exchange
;
use
Yii
;
use
linslin\yii2\curl\Curl
;
class
Bitnasdaq
extends
Exchange
implements
ExchangeInterface
{
protected
$supported_symbol
=
'supported_symbol_bitnasdaq'
;
protected
$quotation_prefix
=
'quotation_bitnasdaq_'
;
protected
$base_url
=
'https://www.bitnasdaq.com/'
;
public
function
formatSymbol
(
$tag
=
'BTC'
,
$aim
=
'USDT'
)
{
return
strtolower
(
trim
(
$tag
)
.
trim
(
$aim
));
}
public
function
setSupportedSymbol
()
{
$curl
=
new
Curl
();
$api
=
$this
->
base_url
.
'/api/v1/ticker/24hr'
;
$res
=
$curl
->
get
(
$api
,
false
);
//json
if
(
is_array
(
$res
))
{
foreach
(
$res
as
$item
)
{
$this
->
redis
->
sadd
(
$this
->
supported_symbol
,
strtolower
(
$item
[
'symbol'
]));
}
}
}
public
function
setQuotation
()
{
$curl
=
new
Curl
();
$api
=
$this
->
base_url
.
'/app/tradeMarket/coinPrice'
;
$res
=
$curl
->
get
(
$api
,
false
);
if
(
is_array
(
$res
)
&&
isset
(
$res
[
'obj'
]))
{
$data
=
$res
[
'obj'
];
foreach
(
$data
as
$key
=>
$item
)
{
$low
=
isset
(
$item
[
'minPrice'
])
?
$item
[
'minPrice'
]
:
0
;
$high
=
isset
(
$item
[
'maxPrice'
])
?
$item
[
'maxPrice'
]
:
0
;
$last
=
isset
(
$item
[
'currentExchangPrice'
])
?
$item
[
'currentExchangPrice'
]
:
0
;
$open
=
isset
(
$item
[
'openPrice'
])
?
$item
[
'openPrice'
]
:
0
;
$vol
=
isset
(
$item
[
'transactionSum'
])
?
$item
[
'transactionSum'
]
:
0
;
$cache_key
=
strtolower
(
$this
->
quotation_prefix
.
str_replace
(
'_'
,
''
,
$key
));
$this
->
redis
->
hmset
(
$cache_key
,
'low'
,
$low
,
'high'
,
$high
,
'last'
,
$last
,
'open'
,
$open
,
'vol'
,
$vol
);
$this
->
redis
->
sadd
(
$this
->
supported_symbol
,
strtoupper
(
str_replace
(
'_'
,
''
,
$key
)));
}
}
}
}
common/service/exchange/factory/BinanceBuilder.php
View file @
f891431f
...
...
@@ -114,6 +114,12 @@ class BinanceBuilder extends FactoryService
$temp
=
[];
$temp
[
'symbol'
]
=
strtoupper
(
$symbol
);
$temp
[
'close'
]
=
$close
;
foreach
(
$this
->
basic_coin
as
$k
=>
$coin
)
{
$explode_arr
=
explode
(
strtoupper
(
$coin
),
strtoupper
(
$symbol
));
if
(
2
==
count
(
$explode_arr
)
&&
empty
(
$explode_arr
[
1
]))
{
$temp
[
'close_rmb'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$close
*
$this
->
basic_price
[
$coin
][
'rmb'
]);
}
}
$temp
[
'low'
]
=
$low
;
$temp
[
'high'
]
=
$high
;
$temp
[
'open'
]
=
$open
;
...
...
@@ -124,7 +130,7 @@ class BinanceBuilder extends FactoryService
$this
->
redis_ticker
->
hmset
(
$key
,
'low'
,
$low
,
'high'
,
$high
,
'last'
,
$close
,
'open'
,
$open
,
'vol'
,
$vol
);
}
$ticker_sort_close
=
Tools
::
arraySort
(
$ticker
,
'close'
);
$ticker_sort_close
=
Tools
::
arraySort
(
$ticker
,
'close
_rmb
'
);
$this
->
redis_ticker
->
del
(
$this
->
supported_symbol_close_asc
);
$this
->
redis_ticker
->
del
(
$this
->
supported_symbol_close_desc
);
foreach
(
$ticker_sort_close
as
$val
)
{
...
...
common/service/exchange/factory/BitnasdaqBuilder.php
0 → 100644
View file @
f891431f
<?php
/**
* Created by PhpStorm.
* User: jiaming
* Date: 2019/8/15
* Time: 10:10
*/
namespace
common\service\exchange\factory
;
use
common\components\Tools
;
use
linslin\yii2\curl\Curl
;
class
BitnasdaqBuilder
extends
FactoryService
{
protected
$base_url
=
'https://www.bitnasdaq.com'
;
protected
$supported_symbol
=
'supported_symbol_bitnasdaq'
;
protected
$supported_symbol_list
=
'supported_symbol_bitnasdaq_list'
;
protected
$supported_symbol_close_asc
=
'supported_symbol_close_asc_bitnasdaq'
;
protected
$supported_symbol_close_desc
=
'supported_symbol_close_desc_bitnasdaq'
;
protected
$supported_symbol_change_asc
=
'supported_symbol_change_asc_bitnasdaq'
;
protected
$supported_symbol_change_desc
=
'supported_symbol_change_desc_bitnasdaq'
;
protected
$quotation_prefix
=
'quotation_bitnasdaq_'
;
public
function
getTickerFromCache
(
$page
=
1
,
$condition
=
[])
{
$size
=
0
;
for
(
$i
=
0
;
$i
<
$page
;
$i
++
)
{
$size
+=
50
;
$this
->
end
=
$size
;
}
$this
->
start
=
$this
->
end
-
50
;
$this
->
end
=
$this
->
end
-
1
;
$keys
=
$this
->
redis
->
smembers
(
$this
->
supported_symbol
);
if
(
false
==
$this
->
redis
->
exists
(
$this
->
supported_symbol_list
))
{
foreach
(
$keys
as
$val
)
{
if
(
in_array
(
strtoupper
(
$val
),
[
'BNCUSDT'
,
'BTCUSDT'
,
'CNYTUSDT'
,
'ETCUSDT'
,
'ETHUSDT'
,
'GHPUSDT'
,
'LTCUSDT'
]))
{
$this
->
redis
->
lpush
(
$this
->
supported_symbol_list
,
strtoupper
(
$val
));
}
}
}
if
(
false
!=
$condition
)
{
if
(
'price'
==
$condition
[
'data_value'
])
{
if
(
'price_asc'
==
$condition
[
'sort_value'
])
{
$keys
=
$this
->
redis_ticker
->
lrange
(
$this
->
supported_symbol_close_asc
,
$this
->
start
,
$this
->
end
);
}
if
(
'price_desc'
==
$condition
[
'sort_value'
])
{
$keys
=
$this
->
redis_ticker
->
lrange
(
$this
->
supported_symbol_close_desc
,
$this
->
start
,
$this
->
end
);
}
}
if
(
'change'
==
$condition
[
'data_value'
])
{
if
(
'change_asc'
==
$condition
[
'sort_value'
])
{
$keys
=
$this
->
redis_ticker
->
lrange
(
$this
->
supported_symbol_change_asc
,
$this
->
start
,
$this
->
end
);
}
if
(
'change_desc'
==
$condition
[
'sort_value'
])
{
$keys
=
$this
->
redis_ticker
->
lrange
(
$this
->
supported_symbol_change_desc
,
$this
->
start
,
$this
->
end
);
}
}
}
else
{
$keys
=
$this
->
redis
->
lrange
(
$this
->
supported_symbol_list
,
$this
->
start
,
$this
->
end
);
}
$ticker
=
[];
foreach
(
$keys
as
$val
)
{
foreach
(
$this
->
basic_coin
as
$k
=>
$coin
)
{
$explode_arr
=
explode
(
strtoupper
(
$coin
),
strtoupper
(
$val
));
if
(
2
==
count
(
$explode_arr
)
&&
empty
(
$explode_arr
[
1
]))
{
if
(
false
!=
$condition
)
{
list
(
$low
,
$high
,
$close
,
$open
,
$vol
)
=
$this
->
redis_ticker
->
hmget
(
$this
->
quotation_prefix
.
strtoupper
(
$val
),
'low'
,
'high'
,
'last'
,
'open'
,
'vol'
);
}
else
{
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'
]
=
rtrim
(
sprintf
(
'%.8f'
,
floatval
(
$close
)),
'0'
);
$temp
[
'close_usd'
]
=
rtrim
(
sprintf
(
'%.6f'
,
floatval
(
$close
*
$this
->
basic_price
[
$coin
][
'usd'
])),
'0'
);
$temp
[
'close_rmb'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$close
*
$this
->
basic_price
[
$coin
][
'rmb'
]);
$temp
[
'change'
]
=
(
false
==
$open
)
?
0
:
(
float
)
sprintf
(
"%0.2f"
,
(
$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'
]
=
'BitNasdaq'
;
array_push
(
$ticker
,
$temp
);
}
}
}
$this
->
code
=
0
;
$data
=
[
'ticker'
=>
$ticker
,
'page'
=>
[
'pageSize'
=>
50
,
'currentPage'
=>
(
int
)
$page
,
]
];
return
[
'code'
=>
$this
->
code
,
'data'
=>
$data
];
}
public
function
TickerSort
()
{
$len
=
$this
->
redis
->
llen
(
$this
->
supported_symbol_list
);
$ticker
=
[];
for
(
$i
=
0
;
$i
<
$len
;
$i
++
)
{
$symbol
=
$this
->
redis
->
lindex
(
$this
->
supported_symbol_list
,
$i
);
list
(
$close
,
$open
,
$low
,
$high
,
$vol
)
=
$this
->
redis
->
hmget
(
$this
->
quotation_prefix
.
strtolower
(
$symbol
),
'last'
,
'open'
,
'low'
,
'high'
,
'vol'
);
if
(
'0.00000000'
==
$close
)
continue
;
$temp
=
[];
$temp
[
'symbol'
]
=
strtoupper
(
$symbol
);
$temp
[
'close'
]
=
$close
;
foreach
(
$this
->
basic_coin
as
$k
=>
$coin
)
{
$explode_arr
=
explode
(
strtoupper
(
$coin
),
strtoupper
(
$symbol
));
if
(
2
==
count
(
$explode_arr
)
&&
empty
(
$explode_arr
[
1
]))
{
$temp
[
'close_rmb'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$close
*
$this
->
basic_price
[
$coin
][
'rmb'
]);
}
}
$temp
[
'low'
]
=
$low
;
$temp
[
'high'
]
=
$high
;
$temp
[
'open'
]
=
$open
;
$temp
[
'vol'
]
=
$vol
;
$temp
[
'change'
]
=
(
0
==
$open
)
?
0
:
(
float
)
sprintf
(
"%0.2f"
,
(
$close
-
$open
)
/
$open
*
100
);
array_push
(
$ticker
,
$temp
);
$key
=
$this
->
quotation_prefix
.
strtoupper
(
$symbol
);
$this
->
redis_ticker
->
hmset
(
$key
,
'low'
,
$low
,
'high'
,
$high
,
'last'
,
$close
,
'open'
,
$open
,
'vol'
,
$vol
);
}
$ticker_sort_close
=
Tools
::
arraySort
(
$ticker
,
'close_rmb'
);
$this
->
redis_ticker
->
del
(
$this
->
supported_symbol_close_asc
);
$this
->
redis_ticker
->
del
(
$this
->
supported_symbol_close_desc
);
foreach
(
$ticker_sort_close
as
$val
)
{
$this
->
redis_ticker
->
lpush
(
$this
->
supported_symbol_close_asc
,
strtoupper
(
$val
[
'symbol'
]));
$this
->
redis_ticker
->
rpush
(
$this
->
supported_symbol_close_desc
,
strtoupper
(
$val
[
'symbol'
]));
}
$ticker_change_close
=
Tools
::
arraySort
(
$ticker
,
'change'
);
$this
->
redis_ticker
->
del
(
$this
->
supported_symbol_change_asc
);
$this
->
redis_ticker
->
del
(
$this
->
supported_symbol_change_desc
);
foreach
(
$ticker_change_close
as
$val
)
{
$this
->
redis_ticker
->
lpush
(
$this
->
supported_symbol_change_asc
,
strtoupper
(
$val
[
'symbol'
]));
$this
->
redis_ticker
->
rpush
(
$this
->
supported_symbol_change_desc
,
strtoupper
(
$val
[
'symbol'
]));
}
}
}
common/service/exchange/factory/FactoryService.php
View file @
f891431f
...
...
@@ -30,7 +30,7 @@ abstract class FactoryService
"eth,ethereum"
,
"btc,btc"
,
"usdt,ethereum"
,
"bty,bty"
,
"bty,bty"
]
];
$params
=
json_encode
(
$data
);
...
...
common/service/exchange/factory/HuobiBuilder.php
View file @
f891431f
...
...
@@ -135,6 +135,12 @@ class HuobiBuilder extends FactoryService
$temp
=
[];
$temp
[
'symbol'
]
=
strtoupper
(
$symbol
);
$temp
[
'close'
]
=
$close
;
foreach
(
$this
->
basic_coin
as
$k
=>
$coin
)
{
$explode_arr
=
explode
(
strtoupper
(
$coin
),
strtoupper
(
$symbol
));
if
(
2
==
count
(
$explode_arr
)
&&
empty
(
$explode_arr
[
1
]))
{
$temp
[
'close_rmb'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$close
*
$this
->
basic_price
[
$coin
][
'rmb'
]);
}
}
$temp
[
'low'
]
=
$low
;
$temp
[
'high'
]
=
$high
;
$temp
[
'open'
]
=
$open
;
...
...
@@ -145,7 +151,7 @@ class HuobiBuilder extends FactoryService
$this
->
redis_ticker
->
hmset
(
$key
,
'low'
,
$low
,
'high'
,
$high
,
'last'
,
$close
,
'open'
,
$open
,
'vol'
,
$vol
);
}
$ticker_sort_close
=
Tools
::
arraySort
(
$ticker
,
'close'
);
$ticker_sort_close
=
Tools
::
arraySort
(
$ticker
,
'close
_rmb
'
);
$this
->
redis_ticker
->
del
(
$this
->
supported_symbol_close_asc
);
$this
->
redis_ticker
->
del
(
$this
->
supported_symbol_close_desc
);
foreach
(
$ticker_sort_close
as
$val
)
{
...
...
common/service/exchange/factory/ZhaobiBuilder.php
View file @
f891431f
...
...
@@ -103,13 +103,19 @@ class ZhaobiBuilder extends FactoryService
$temp
=
[];
$temp
[
'symbol'
]
=
strtoupper
(
$symbol
);
$temp
[
'close'
]
=
number_format
(
$close
,
6
,
'.'
,
''
);
foreach
(
$this
->
basic_coin
as
$k
=>
$coin
)
{
$explode_arr
=
explode
(
strtoupper
(
$coin
),
strtoupper
(
$symbol
));
if
(
2
==
count
(
$explode_arr
)
&&
empty
(
$explode_arr
[
1
]))
{
$temp
[
'close_rmb'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$close
*
$this
->
basic_price
[
$coin
][
'rmb'
]);
}
}
$temp
[
'change'
]
=
(
0
==
$open
)
?
0
:
(
float
)
sprintf
(
"%0.2f"
,
(
$close
-
$open
)
/
$open
*
100
);
array_push
(
$ticker
,
$temp
);
$key
=
$this
->
quotation_prefix
.
strtoupper
(
$symbol
);
$this
->
redis_ticker
->
hmset
(
$key
,
'low'
,
$low
,
'high'
,
$high
,
'last'
,
$close
,
'open'
,
$open
,
'vol'
,
$vol
);
}
$ticker_sort_close
=
Tools
::
arraySort
(
$ticker
,
'close'
);
$ticker_sort_close
=
Tools
::
arraySort
(
$ticker
,
'close
_rmb
'
);
$this
->
redis_ticker
->
del
(
$this
->
supported_symbol_close_asc
);
$this
->
redis_ticker
->
del
(
$this
->
supported_symbol_close_desc
);
foreach
(
$ticker_sort_close
as
$val
)
{
...
...
console/controllers/TickerController.php
View file @
f891431f
...
...
@@ -14,7 +14,7 @@ class TickerController extends Controller
{
public
function
actionSort
()
{
$class
=
[
'Binance'
,
'Huobi'
,
'Zhaobi'
];
$class
=
[
'Binance'
,
'Huobi'
,
'Zhaobi'
,
'Bitnasdaq'
];
foreach
(
$class
as
$val
)
{
go
(
function
()
use
(
$val
)
{
\Co
::
sleep
(
0.5
);
...
...
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