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
38057608
Commit
38057608
authored
Feb 15, 2022
by
shajiaiming
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/optimize' into 'master'
行情 See merge request
!490
parents
b64c07c7
22e15b07
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
110 additions
and
75 deletions
+110
-75
ExchangeBusiness.php
common/business/ExchangeBusiness.php
+32
-68
CoinBTYService.php
common/service/coin/CoinBTYService.php
+1
-1
Rate.php
common/service/exchange/Rate.php
+6
-6
Superx.php
common/service/exchange/Superx.php
+71
-0
No files found.
common/business/ExchangeBusiness.php
View file @
38057608
...
@@ -27,21 +27,21 @@ class ExchangeBusiness
...
@@ -27,21 +27,21 @@ class ExchangeBusiness
* @var array
* @var array
*/
*/
private
static
$exchanges
=
[
private
static
$exchanges
=
[
0
=>
'Bty'
,
//
0 => 'Bty',
1
=>
'HuoBi'
,
0
=>
'HuoBi'
,
2
=>
'Hadax'
,
1
=>
'Hadax'
,
3
=>
'Bittrex'
,
2
=>
'Bittrex'
,
4
=>
'Zb'
,
3
=>
'Zb'
,
5
=>
'Go
'
,
4
=>
'Rate
'
,
6
=>
'Zhaobi
'
,
5
=>
'Superx
'
,
7
=>
'Binance'
,
6
=>
'Binance'
,
8
=>
'Bilaxy'
,
7
=>
'Bilaxy'
,
9
=>
'Bitnasdaq'
,
8
=>
'Bitnasdaq'
,
10
=>
'Isummit'
,
9
=>
'Isummit'
,
1
1
=>
'Boc'
,
1
0
=>
'Boc'
,
1
2
=>
'Ztb'
,
1
1
=>
'Ztb'
,
1
3
=>
'Wbf'
,
1
2
=>
'Wbf'
,
1
4
=>
'Gwa'
1
3
=>
'Gwa'
//1 => 'Hadax', //不需要
//1 => 'Hadax', //不需要
//2 => 'Bitfinex', //不需要
//2 => 'Bitfinex', //不需要
...
@@ -61,6 +61,7 @@ class ExchangeBusiness
...
@@ -61,6 +61,7 @@ class ExchangeBusiness
//5 => 'Zg',//已挂
//5 => 'Zg',//已挂
//13 => 'Jinwang',//已挂
//13 => 'Jinwang',//已挂
//14 => 'Hd',//已挂
//14 => 'Hd',//已挂
//15 => 'Zhaobi',//已挂
];
];
/**
/**
...
@@ -84,21 +85,6 @@ class ExchangeBusiness
...
@@ -84,21 +85,6 @@ class ExchangeBusiness
}
}
$coin_quotation_disable_items
=
Yii
::
$app
->
params
[
'coin_quotation_disable_items'
];
$coin_quotation_disable_items
=
Yii
::
$app
->
params
[
'coin_quotation_disable_items'
];
if
(
strtoupper
(
$tag
)
==
'CCNY'
||
strtoupper
(
$tag
)
==
'CNYT'
||
strtoupper
(
$tag
)
==
'ETC'
||
strtoupper
(
$tag
)
==
'YX'
)
{
$exchange
=
ExchangeFactory
::
createExchange
(
"Zhaobi"
);
if
(
strtoupper
(
$tag
)
==
'ETC'
)
{
$quotation
=
$exchange
->
getTicker
(
$tag
,
'USDT'
);
$quotation
[
'rmb'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$quotation
[
'last'
]);
goto
doEnd
;
}
$rate
=
$exchange
->
getTicker
(
"BTY"
,
"USDT"
);
$rate
=
(
float
)
$rate
[
'rmb'
]
/
$rate
[
'last'
];
$quotation
[
'rmb'
]
=
1.00
;
$quotation
[
'low'
]
=
1.00
;
$quotation
[
'high'
]
=
1.00
;
$quotation
[
'last'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$quotation
[
'rmb'
]
/
$rate
);
goto
doEnd
;
}
if
(
strtoupper
(
$tag
)
==
'USAT'
)
{
if
(
strtoupper
(
$tag
)
==
'USAT'
)
{
$tag
=
'USDT'
;
$tag
=
'USDT'
;
...
@@ -300,16 +286,6 @@ class ExchangeBusiness
...
@@ -300,16 +286,6 @@ class ExchangeBusiness
goto
doEnd
;
goto
doEnd
;
}
}
if
(
in_array
(
strtoupper
(
$tag
),
[
'SFT'
]))
{
$exchange
=
ExchangeFactory
::
createExchange
(
"Zhaobi"
);
$quotation
=
$exchange
->
getTicker
(
$tag
,
'USDT'
);
$quotation
[
'low'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$quotation
[
'low'
]);
$quotation
[
'high'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$quotation
[
'high'
]);
$quotation
[
'last'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$quotation
[
'last'
]);
$quotation
[
'rmb'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$quotation
[
'last'
]);
goto
doEnd
;
}
if
(
in_array
(
strtoupper
(
$tag
),
[
'CTG'
]))
{
if
(
in_array
(
strtoupper
(
$tag
),
[
'CTG'
]))
{
$exchange
=
ExchangeFactory
::
createExchange
(
"Gdpro"
);
$exchange
=
ExchangeFactory
::
createExchange
(
"Gdpro"
);
$quotation
=
$exchange
->
getTicker
(
$tag
,
'CNY'
);
$quotation
=
$exchange
->
getTicker
(
$tag
,
'CNY'
);
...
@@ -317,19 +293,19 @@ class ExchangeBusiness
...
@@ -317,19 +293,19 @@ class ExchangeBusiness
goto
doEnd
;
goto
doEnd
;
}
}
if
(
in_array
(
strtoupper
(
$tag
),
[
'USDT'
]))
{
//
if (in_array(strtoupper($tag), ['USDT'])) {
$exchange
=
ExchangeFactory
::
createExchange
(
"Go"
);
//
$exchange = ExchangeFactory::createExchange("Go");
$quotation
=
$exchange
->
getTicker
(
'CNY'
,
'USD'
);
//
$quotation = $exchange->getTicker('CNY', 'USD');
$quotation
[
'rmb'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$quotation
[
'last'
]);
//
$quotation['rmb'] = (float)sprintf("%0.4f", $quotation['last']);
goto
doEnd
;
//
goto doEnd;
}
//
}
//
if
(
in_array
(
strtoupper
(
$tag
),
[
'SUSD'
]))
{
//
if (in_array(strtoupper($tag), ['SUSD'])) {
$exchange
=
ExchangeFactory
::
createExchange
(
"Go"
);
//
$exchange = ExchangeFactory::createExchange("Go");
$quotation
=
$exchange
->
getTicker
(
'CNY'
,
'USD'
);
//
$quotation = $exchange->getTicker('CNY', 'USD');
$quotation
[
'rmb'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$quotation
[
'last'
]);
//
$quotation['rmb'] = (float)sprintf("%0.4f", $quotation['last']);
goto
doEnd
;
//
goto doEnd;
}
//
}
if
(
in_array
(
strtoupper
(
$tag
),
[
'CIC'
,
'MC'
]))
{
if
(
in_array
(
strtoupper
(
$tag
),
[
'CIC'
,
'MC'
]))
{
$exchange
=
ExchangeFactory
::
createExchange
(
"Ztb"
);
$exchange
=
ExchangeFactory
::
createExchange
(
"Ztb"
);
...
@@ -442,7 +418,7 @@ class ExchangeBusiness
...
@@ -442,7 +418,7 @@ class ExchangeBusiness
goto
doEnd
;
goto
doEnd
;
}
}
if
(
in_array
(
strtoupper
(
$tag
),
[
'GWA'
,
'KLG'
]))
{
if
(
in_array
(
strtoupper
(
$tag
),
[
'GWA'
,
'KLG'
]))
{
$exchange
=
ExchangeFactory
::
createExchange
(
"Gwa"
);
$exchange
=
ExchangeFactory
::
createExchange
(
"Gwa"
);
$quotation
=
$exchange
->
getTicker
(
strtoupper
(
$tag
),
'USDT'
);
$quotation
=
$exchange
->
getTicker
(
strtoupper
(
$tag
),
'USDT'
);
goto
doEnd
;
goto
doEnd
;
...
@@ -487,24 +463,12 @@ class ExchangeBusiness
...
@@ -487,24 +463,12 @@ class ExchangeBusiness
foreach
(
$quotation
as
$key
=>
$item
)
{
foreach
(
$quotation
as
$key
=>
$item
)
{
$quotation
[
$key
]
=
(
float
)
sprintf
(
"%0.4f"
,
(
double
)
$item
);
$quotation
[
$key
]
=
(
float
)
sprintf
(
"%0.4f"
,
(
double
)
$item
);
}
}
//用YCC计算汇率
/**
* @var $exchange \common\service\exchange\Exchange
*/
$exchange
=
ExchangeFactory
::
createExchange
(
"Go"
);
$rate
=
$exchange
->
getTicker
(
"CNY"
,
"USD"
);
$rate
=
$rate
[
'last'
]
??
''
;
if
(
empty
(
$rate
))
{
$exchange
=
ExchangeFactory
::
createExchange
(
"Bty"
);
$rate
=
$exchange
->
getTicker
(
"BTY"
,
"USDT"
);
$rate
=
(
float
)
$rate
[
'rmb'
]
/
$rate
[
'last'
];
}
$quotation
[
'rmb'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$rate
*
$quotation
[
'last'
]);
doEnd
:
doEnd
:
$exchange
=
ExchangeFactory
::
createExchange
(
"
Go
"
);
$exchange
=
ExchangeFactory
::
createExchange
(
"
Rate
"
);
$rate
=
$exchange
->
getTicker
(
"CNY"
,
"USD"
);
$rate
=
$exchange
->
getTicker
(
"CNY"
,
"USD"
);
$cny_usd_rate
=
1
/
$rate
[
'last'
];
$cny_usd_rate
=
1
/
$rate
[
'last'
];
if
(
in_array
(
strtoupper
(
$tag
),
[
'FOLI'
,
'CIC'
,
'MC'
,
'KPC8'
,
'BBD'
,
'BVA'
,
'DAG'
,
'BNC'
,
'BNB'
,
'GHP'
,
'DRA'
,
'ETC'
,
'PAX'
,
'STH'
,
'XJH'
,
'SFT'
,
'TSC'
,
'SUM'
,
'USDW'
,
'FUT'
,
'MBTC'
,
'METH'
,
'GLCW'
,
'HDC'
,
'GWA'
,
'KLG'
,
'LELE'
,
'ZUE'
]))
{
if
(
in_array
(
strtoupper
(
$tag
),
[
'FOLI'
,
'CIC'
,
'MC'
,
'KPC8'
,
'BBD'
,
'BVA'
,
'DAG'
,
'BNC'
,
'BNB'
,
'GHP'
,
'DRA'
,
'ETC'
,
'PAX'
,
'STH'
,
'XJH'
,
'SFT'
,
'TSC'
,
'SUM'
,
'USDW'
,
'FUT'
,
'MBTC'
,
'METH'
,
'GLCW'
,
'HDC'
,
'GWA'
,
'KLG'
,
'LELE'
,
'ZUE'
]))
{
$quotation
[
'usd'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$quotation
[
'last'
]);
$quotation
[
'usd'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$quotation
[
'last'
]);
$quotation
[
'rmb'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$quotation
[
'last'
]
/
$cny_usd_rate
);
$quotation
[
'rmb'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$quotation
[
'last'
]
/
$cny_usd_rate
);
...
...
common/service/coin/CoinBTYService.php
View file @
38057608
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
namespace
common\service\coin
;
namespace
common\service\coin
;
use
common\helpers
\Curl
;
use
linslin\yii2\curl
\Curl
;
use
Yii
;
use
Yii
;
class
CoinBTYService
extends
Coin
implements
CoinInterface
class
CoinBTYService
extends
Coin
implements
CoinInterface
...
...
common/service/exchange/
Go
.php
→
common/service/exchange/
Rate
.php
View file @
38057608
...
@@ -10,11 +10,11 @@ namespace common\service\exchange;
...
@@ -10,11 +10,11 @@ namespace common\service\exchange;
use
linslin\yii2\curl\Curl
;
use
linslin\yii2\curl\Curl
;
class
Go
extends
Exchange
implements
ExchangeInterface
class
Rate
extends
Exchange
implements
ExchangeInterface
{
{
protected
$supported_symbol
=
'supported_symbol_
go
'
;
protected
$supported_symbol
=
'supported_symbol_
rate
'
;
protected
$quotation_prefix
=
'quotation_
go
_'
;
protected
$quotation_prefix
=
'quotation_
rate
_'
;
protected
$base_url
=
'https://
otc-api.eiijo.cn/v1/data/trade-market?country=37¤cy=1&payMethod=0&currPage=1&coinId=2&tradeType=sell&blockType=general&online
=1'
;
protected
$base_url
=
'https://
ticker-api.cointelegraph.com/history/USDT/CNY/?coin=USDT¤cy=CNY&limit
=1'
;
public
function
symbolExists
(
$tag
=
'CNY'
,
$aim
=
"USD"
)
public
function
symbolExists
(
$tag
=
'CNY'
,
$aim
=
"USD"
)
{
{
...
@@ -55,11 +55,11 @@ class Go extends Exchange implements ExchangeInterface
...
@@ -55,11 +55,11 @@ class Go extends Exchange implements ExchangeInterface
{
{
$curl
=
new
Curl
();
$curl
=
new
Curl
();
$content
=
$curl
->
get
(
$this
->
base_url
,
false
);
$content
=
$curl
->
get
(
$this
->
base_url
,
false
);
if
(
is_array
(
$content
)
&&
isset
(
$content
[
'code'
])
&&
(
200
==
$content
[
'code'
])
)
{
if
(
is_array
(
$content
))
{
$data
=
$content
[
'data'
];
$data
=
$content
[
'data'
];
foreach
(
$data
as
$item
)
{
foreach
(
$data
as
$item
)
{
$key
=
$this
->
quotation_prefix
.
'CNY_USD'
;
$key
=
$this
->
quotation_prefix
.
'CNY_USD'
;
$this
->
redis
->
hmset
(
$key
,
'low'
,
$item
[
'p
rice'
],
'high'
,
$item
[
'price'
],
'last'
,
$item
[
'price
'
]);
$this
->
redis
->
hmset
(
$key
,
'low'
,
$item
[
'p
'
],
'high'
,
$item
[
'p'
],
'last'
,
$item
[
'p
'
]);
$this
->
redis
->
sadd
(
$this
->
supported_symbol
,
'CNY_USD'
);
$this
->
redis
->
sadd
(
$this
->
supported_symbol
,
'CNY_USD'
);
break
;
break
;
}
}
...
...
common/service/exchange/Superx.php
0 → 100644
View file @
38057608
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-8-7
* Time: 上午11:30
*/
namespace
common\service\exchange
;
use
linslin\yii2\curl\Curl
;
class
Superx
extends
Exchange
implements
ExchangeInterface
{
protected
$supported_symbol
=
'supported_symbol_superx'
;
protected
$quotation_prefix
=
'quotation_superx_'
;
protected
$base_url
=
'http://18.181.255.33:8091'
;
public
function
symbolExists
(
$tag
=
'bty'
,
$aim
=
"usdt"
)
{
$supported
=
$this
->
redis
->
smembers
(
$this
->
supported_symbol
);
if
(
is_array
(
$supported
)
&&
in_array
(
$this
->
formatSymbol
(
$tag
,
$aim
),
$supported
))
{
return
true
;
}
return
false
;
}
/**
* 转化交易对为请求变量
*
* @param string $tag
* @param string $aim
* @return mixed
*/
public
function
formatSymbol
(
$tag
=
'bty'
,
$aim
=
'usdt'
)
{
return
strtolower
(
trim
(
$tag
)
.
trim
(
$aim
));
}
/**
* 保存支持的交易对到redis数据库,使用crontab定时更新
*
* @return mixed|void
*/
public
function
setSupportedSymbol
()
{
$this
->
redis
->
sadd
(
$this
->
supported_symbol
,
'btyusdt'
);
}
/**
* 更新交易对行情保存到redis,使用crontab定时更新
*
* @return mixed|void
*/
public
function
setQuotation
()
{
$curl
=
new
Curl
();
$api
=
$this
->
base_url
.
'/api/ticker'
;
$content
=
$curl
->
get
(
$api
,
false
);
if
(
isset
(
$content
[
'msg'
])
&&
'succeed'
==
$content
[
'msg'
])
{
$ticker
=
isset
(
$content
[
'data'
][
'data'
][
'USDT'
])
?
$content
[
'data'
][
'data'
][
'USDT'
]
:
null
;
if
(
false
!=
$ticker
)
{
foreach
(
$ticker
as
$key
=>
$val
)
{
$key
=
$this
->
quotation_prefix
.
strtolower
(
$key
)
.
"usdt"
;
$this
->
redis
->
hmset
(
$key
,
'low'
,
$val
[
'low'
],
'high'
,
$val
[
'high'
],
'last'
,
$val
[
'last'
],
'open'
,
$val
[
'open'
],
'vol'
,
$val
[
'vol'
],
'range'
,
str_replace
(
'%'
,
''
,
$val
[
'range'
]));
$this
->
redis
->
sadd
(
$this
->
supported_symbol
,
$val
[
'symbol'
]);
}
}
}
}
}
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