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
43ee5f02
Commit
43ee5f02
authored
6 years ago
by
rlgy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bittrex api
parent
5a42a900
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
46 additions
and
88 deletions
+46
-88
ExchangeBusiness.php
common/business/ExchangeBusiness.php
+2
-2
Bitfinex.php
common/service/exchange/Bitfinex.php
+8
-29
Exchange.php
common/service/exchange/Exchange.php
+26
-11
Hadax.php
common/service/exchange/Hadax.php
+3
-15
HuoBi.php
common/service/exchange/HuoBi.php
+6
-30
ExchangeController.php
console/controllers/ExchangeController.php
+1
-1
No files found.
common/business/ExchangeBusiness.php
View file @
43ee5f02
...
...
@@ -69,7 +69,7 @@ class ExchangeBusiness
$f
=
false
;
//是否获取到行情
foreach
(
self
::
$exchanges
as
$exchange
)
{
/**
* @var $exchange \common\service\exchange\Exchange
Interface
* @var $exchange \common\service\exchange\Exchange
*/
$exchange
=
ExchangeFactory
::
createExchange
(
$exchange
);
if
(
$exchange
->
symbolExists
(
$row
[
'name'
]))
{
...
...
@@ -85,7 +85,7 @@ class ExchangeBusiness
foreach
(
self
::
$exchanges
as
$exchange
)
{
/**
* @var $exchange \common\service\exchange\Exchange
Interface
* @var $exchange \common\service\exchange\Exchange
*/
$exchange
=
ExchangeFactory
::
createExchange
(
$exchange
);
if
(
$exchange
->
symbolExists
(
$row
[
'name'
],
'btc'
))
{
...
...
This diff is collapsed.
Click to expand it.
common/service/exchange/Bitfinex.php
View file @
43ee5f02
...
...
@@ -23,45 +23,24 @@ class Bitfinex extends Exchange implements ExchangeInterface
public
function
setSupportedSymbol
()
{
/**
* @var $redis \yii\redis\Connection
*/
$redis
=
Yii
::
$app
->
redis
;
$ch
=
new
Curl
();
//http代理
if
(
Yii
::
$app
->
params
[
'http_proxy'
][
'use'
])
{
$ch
->
setOptions
([
CURLOPT_PROXY
=>
Yii
::
$app
->
params
[
'http_proxy'
][
'host'
],
CURLOPT_PROXYPORT
=>
Yii
::
$app
->
params
[
'http_proxy'
][
'port'
],
]);
}
$result
=
$ch
->
get
(
'https://api.bitfinex.com/v1/symbols'
,
false
);
$result
=
$this
->
ch
->
get
(
'https://api.bitfinex.com/v1/symbols'
,
false
);
if
(
$result
)
{
foreach
(
$result
as
$item
)
{
$redis
->
sadd
(
$this
->
supported_symbol
,
't'
.
strtoupper
(
$item
));
$
this
->
redis
->
sadd
(
$this
->
supported_symbol
,
't'
.
strtoupper
(
$item
));
}
}
}
public
function
setQuotation
()
{
/**
* @var $redis \yii\redis\Connection
*/
$redis
=
Yii
::
$app
->
redis
;
$ch
=
new
Curl
();
//http代理
if
(
Yii
::
$app
->
params
[
'http_proxy'
][
'use'
])
{
$ch
->
setOptions
([
CURLOPT_PROXY
=>
Yii
::
$app
->
params
[
'http_proxy'
][
'host'
],
CURLOPT_PROXYPORT
=>
Yii
::
$app
->
params
[
'http_proxy'
][
'port'
],
]);
}
$symbols
=
$redis
->
smembers
(
$this
->
supported_symbol
);
$symbols
=
$this
->
redis
->
smembers
(
$this
->
supported_symbol
);
$query
=
'?symbols='
.
implode
(
','
,
$symbols
);
$res
=
$ch
->
get
(
'https://api.bitfinex.com/v2/tickers'
.
$query
,
false
);
$res
=
$
this
->
ch
->
get
(
'https://api.bitfinex.com/v2/tickers'
.
$query
,
false
);
foreach
(
$res
as
$item
)
{
$redis
->
hmset
(
$this
->
quotation_prefix
.
$item
[
0
],
'low'
,
$item
[
10
],
'high'
,
$item
[
'9'
],
'last'
,
$item
[
7
]);
$this
->
redis
->
hmset
(
$this
->
quotation_prefix
.
$item
[
0
],
'low'
,
$item
[
10
],
'high'
,
$item
[
'9'
],
'last'
,
$item
[
7
]);
}
}
...
...
This diff is collapsed.
Click to expand it.
common/service/exchange/Exchange.php
View file @
43ee5f02
...
...
@@ -8,6 +8,7 @@
namespace
common\service\exchange
;
use
common\helpers\Curl
;
use
Yii
;
/**
...
...
@@ -19,6 +20,27 @@ abstract class Exchange
{
protected
$supported_symbol
=
''
;
protected
$quotation_prefix
=
''
;
/**
* @var $redis \yii\redis\Connection
*/
protected
$redis
;
/**
* @var $ch \common\helpers\Curl
*/
protected
$ch
;
public
function
__construct
()
{
$this
->
redis
=
Yii
::
$app
->
redis
;
$this
->
ch
=
new
Curl
();
if
(
Yii
::
$app
->
params
[
'http_proxy'
][
'use'
])
{
$this
->
ch
->
setOptions
([
CURLOPT_PROXY
=>
Yii
::
$app
->
params
[
'http_proxy'
][
'host'
],
CURLOPT_PROXYPORT
=>
Yii
::
$app
->
params
[
'http_proxy'
][
'port'
]
]);
}
}
/**
* 转化交易对为请求变量
...
...
@@ -38,11 +60,7 @@ abstract class Exchange
*/
public
function
symbolExists
(
$tag
=
'BTC'
,
$aim
=
"USD"
)
{
/**
* @var $redis \yii\redis\Connection
*/
$redis
=
Yii
::
$app
->
redis
;
$supported
=
$redis
->
smembers
(
$this
->
supported_symbol
);
$supported
=
$this
->
redis
->
smembers
(
$this
->
supported_symbol
);
if
(
is_array
(
$supported
)
&&
in_array
(
$this
->
formatSymbol
(
$tag
,
$aim
),
$supported
))
{
return
true
;
}
...
...
@@ -59,12 +77,8 @@ abstract class Exchange
public
function
getTicker
(
$tag
=
'BTC'
,
$aim
=
"USDT"
)
{
$symbol
=
$this
->
formatSymbol
(
$tag
,
$aim
);
/**
* @var $redis \yii\redis\Connection
*/
$redis
=
Yii
::
$app
->
redis
;
$keys
=
$redis
->
hkeys
(
$this
->
quotation_prefix
.
$symbol
);
$values
=
$redis
->
hvals
(
$this
->
quotation_prefix
.
$symbol
);
$keys
=
$this
->
redis
->
hkeys
(
$this
->
quotation_prefix
.
$symbol
);
$values
=
$this
->
redis
->
hvals
(
$this
->
quotation_prefix
.
$symbol
);
return
array_combine
(
$keys
,
$values
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
common/service/exchange/Hadax.php
View file @
43ee5f02
...
...
@@ -20,24 +20,12 @@ class Hadax extends HuoBi
public
function
setSupportedSymbol
()
{
$api
=
$this
->
base_url
.
'/v1/hadax/common/symbols'
;
$key
=
$this
->
supported_symbol
;
$ch
=
new
Curl
();
//http代理
if
(
USER_PROXY
)
{
$ch
->
setOptions
([
CURLOPT_PROXY
=>
'127.0.0.1'
,
CURLOPT_PROXYPORT
=>
1080
,
]);
}
$res
=
$ch
->
get
(
$api
,
false
);
//json
$res
=
$this
->
ch
->
get
(
$api
,
false
);
//json
if
(
$res
&&
$res
[
'status'
]
==
'ok'
)
{
$data
=
$res
[
'data'
];
/**
* @var $redis \yii\redis\Connection
*/
$redis
=
Yii
::
$app
->
redis
;
foreach
(
$data
as
$item
)
{
$redis
->
sadd
(
$key
,
$this
->
formatSymbol
(
$item
[
'base-currency'
],
$item
[
'quote-currency'
]));
$this
->
redis
->
sadd
(
$this
->
supported_symbol
,
$this
->
formatSymbol
(
$item
[
'base-currency'
],
$item
[
'quote-currency'
]));
}
}
}
...
...
This diff is collapsed.
Click to expand it.
common/service/exchange/HuoBi.php
View file @
43ee5f02
...
...
@@ -25,24 +25,12 @@ class HuoBi extends Exchange implements ExchangeInterface
public
function
setSupportedSymbol
()
{
$api
=
$this
->
base_url
.
'/v1/common/symbols'
;
$key
=
$this
->
supported_symbol
;
$ch
=
new
Curl
();
//http代理
if
(
USER_PROXY
)
{
$ch
->
setOptions
([
CURLOPT_PROXY
=>
'127.0.0.1'
,
CURLOPT_PROXYPORT
=>
1080
,
]);
}
$res
=
$ch
->
get
(
$api
,
false
);
//json
$res
=
$this
->
ch
->
get
(
$api
,
false
);
//json
if
(
$res
&&
$res
[
'status'
]
==
'ok'
)
{
$data
=
$res
[
'data'
];
/**
* @var $redis \yii\redis\Connection
*/
$redis
=
Yii
::
$app
->
redis
;
foreach
(
$data
as
$item
)
{
$redis
->
sadd
(
$key
,
$this
->
formatSymbol
(
$item
[
'base-currency'
],
$item
[
'quote-currency'
]));
$this
->
redis
->
sadd
(
$this
->
supported_symbol
,
$this
->
formatSymbol
(
$item
[
'base-currency'
],
$item
[
'quote-currency'
]));
}
}
}
...
...
@@ -50,25 +38,13 @@ class HuoBi extends Exchange implements ExchangeInterface
public
function
setQuotation
()
{
$api
=
$this
->
base_url
.
'/market/tickers'
;
$ch
=
new
Curl
();
//http代理
if
(
USER_PROXY
)
{
$ch
->
setOptions
([
CURLOPT_PROXY
=>
'127.0.0.1'
,
CURLOPT_PROXYPORT
=>
1080
,
]);
}
$res
=
$ch
->
get
(
$api
,
false
);
$res
=
$this
->
ch
->
get
(
$api
,
false
);
if
(
$res
&&
$res
[
'status'
]
==
'ok'
)
{
$datas
=
$res
[
'data'
];
/**
* @var $redis \yii\redis\Connection
*/
$redis
=
Yii
::
$app
->
redis
;
foreach
(
$datas
as
$item
)
{
$key
=
$this
->
quotation_prefix
.
$item
[
'symbol'
];
$redis
->
hmset
(
$key
,
'low'
,
$item
[
'low'
],
'high'
,
$item
[
'high'
],
'last'
,
$item
[
'close'
]);
$redis
->
sadd
(
$this
->
supported_symbol
,
$item
[
'symbol'
]);
$
this
->
redis
->
hmset
(
$key
,
'low'
,
$item
[
'low'
],
'high'
,
$item
[
'high'
],
'last'
,
$item
[
'close'
]);
$
this
->
redis
->
sadd
(
$this
->
supported_symbol
,
$item
[
'symbol'
]);
}
}
}
...
...
This diff is collapsed.
Click to expand it.
console/controllers/ExchangeController.php
View file @
43ee5f02
...
...
@@ -37,7 +37,7 @@ class ExchangeController extends Controller
public
function
actionTest
()
{
$a
=
new
\common\service\exchange\Bit
fin
ex
();
$a
=
new
\common\service\exchange\Bit
tr
ex
();
// $a->setSupportedSymbol();
$a
->
setQuotation
();
...
...
This diff is collapsed.
Click to expand it.
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