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
Jun 28, 2018
by
rlgy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bittrex api
parent
5a42a900
Hide 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
...
@@ -69,7 +69,7 @@ class ExchangeBusiness
$f
=
false
;
//是否获取到行情
$f
=
false
;
//是否获取到行情
foreach
(
self
::
$exchanges
as
$exchange
)
{
foreach
(
self
::
$exchanges
as
$exchange
)
{
/**
/**
* @var $exchange \common\service\exchange\Exchange
Interface
* @var $exchange \common\service\exchange\Exchange
*/
*/
$exchange
=
ExchangeFactory
::
createExchange
(
$exchange
);
$exchange
=
ExchangeFactory
::
createExchange
(
$exchange
);
if
(
$exchange
->
symbolExists
(
$row
[
'name'
]))
{
if
(
$exchange
->
symbolExists
(
$row
[
'name'
]))
{
...
@@ -85,7 +85,7 @@ class ExchangeBusiness
...
@@ -85,7 +85,7 @@ class ExchangeBusiness
foreach
(
self
::
$exchanges
as
$exchange
)
{
foreach
(
self
::
$exchanges
as
$exchange
)
{
/**
/**
* @var $exchange \common\service\exchange\Exchange
Interface
* @var $exchange \common\service\exchange\Exchange
*/
*/
$exchange
=
ExchangeFactory
::
createExchange
(
$exchange
);
$exchange
=
ExchangeFactory
::
createExchange
(
$exchange
);
if
(
$exchange
->
symbolExists
(
$row
[
'name'
],
'btc'
))
{
if
(
$exchange
->
symbolExists
(
$row
[
'name'
],
'btc'
))
{
...
...
common/service/exchange/Bitfinex.php
View file @
43ee5f02
...
@@ -23,45 +23,24 @@ class Bitfinex extends Exchange implements ExchangeInterface
...
@@ -23,45 +23,24 @@ class Bitfinex extends Exchange implements ExchangeInterface
public
function
setSupportedSymbol
()
public
function
setSupportedSymbol
()
{
{
/**
$result
=
$this
->
ch
->
get
(
'https://api.bitfinex.com/v1/symbols'
,
false
);
* @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
);
if
(
$result
)
{
if
(
$result
)
{
foreach
(
$result
as
$item
)
{
foreach
(
$result
as
$item
)
{
$redis
->
sadd
(
$this
->
supported_symbol
,
't'
.
strtoupper
(
$item
));
$
this
->
redis
->
sadd
(
$this
->
supported_symbol
,
't'
.
strtoupper
(
$item
));
}
}
}
}
}
}
public
function
setQuotation
()
public
function
setQuotation
()
{
{
/**
$symbols
=
$this
->
redis
->
smembers
(
$this
->
supported_symbol
);
* @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
);
$query
=
'?symbols='
.
implode
(
','
,
$symbols
);
$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
)
{
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
]);
}
}
}
}
...
...
common/service/exchange/Exchange.php
View file @
43ee5f02
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
namespace
common\service\exchange
;
namespace
common\service\exchange
;
use
common\helpers\Curl
;
use
Yii
;
use
Yii
;
/**
/**
...
@@ -19,6 +20,27 @@ abstract class Exchange
...
@@ -19,6 +20,27 @@ abstract class Exchange
{
{
protected
$supported_symbol
=
''
;
protected
$supported_symbol
=
''
;
protected
$quotation_prefix
=
''
;
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
...
@@ -38,11 +60,7 @@ abstract class Exchange
*/
*/
public
function
symbolExists
(
$tag
=
'BTC'
,
$aim
=
"USD"
)
public
function
symbolExists
(
$tag
=
'BTC'
,
$aim
=
"USD"
)
{
{
/**
$supported
=
$this
->
redis
->
smembers
(
$this
->
supported_symbol
);
* @var $redis \yii\redis\Connection
*/
$redis
=
Yii
::
$app
->
redis
;
$supported
=
$redis
->
smembers
(
$this
->
supported_symbol
);
if
(
is_array
(
$supported
)
&&
in_array
(
$this
->
formatSymbol
(
$tag
,
$aim
),
$supported
))
{
if
(
is_array
(
$supported
)
&&
in_array
(
$this
->
formatSymbol
(
$tag
,
$aim
),
$supported
))
{
return
true
;
return
true
;
}
}
...
@@ -59,12 +77,8 @@ abstract class Exchange
...
@@ -59,12 +77,8 @@ abstract class Exchange
public
function
getTicker
(
$tag
=
'BTC'
,
$aim
=
"USDT"
)
public
function
getTicker
(
$tag
=
'BTC'
,
$aim
=
"USDT"
)
{
{
$symbol
=
$this
->
formatSymbol
(
$tag
,
$aim
);
$symbol
=
$this
->
formatSymbol
(
$tag
,
$aim
);
/**
$keys
=
$this
->
redis
->
hkeys
(
$this
->
quotation_prefix
.
$symbol
);
* @var $redis \yii\redis\Connection
$values
=
$this
->
redis
->
hvals
(
$this
->
quotation_prefix
.
$symbol
);
*/
$redis
=
Yii
::
$app
->
redis
;
$keys
=
$redis
->
hkeys
(
$this
->
quotation_prefix
.
$symbol
);
$values
=
$redis
->
hvals
(
$this
->
quotation_prefix
.
$symbol
);
return
array_combine
(
$keys
,
$values
);
return
array_combine
(
$keys
,
$values
);
}
}
}
}
\ No newline at end of file
common/service/exchange/Hadax.php
View file @
43ee5f02
...
@@ -20,24 +20,12 @@ class Hadax extends HuoBi
...
@@ -20,24 +20,12 @@ class Hadax extends HuoBi
public
function
setSupportedSymbol
()
public
function
setSupportedSymbol
()
{
{
$api
=
$this
->
base_url
.
'/v1/hadax/common/symbols'
;
$api
=
$this
->
base_url
.
'/v1/hadax/common/symbols'
;
$key
=
$this
->
supported_symbol
;
$res
=
$this
->
ch
->
get
(
$api
,
false
);
//json
$ch
=
new
Curl
();
//http代理
if
(
USER_PROXY
)
{
$ch
->
setOptions
([
CURLOPT_PROXY
=>
'127.0.0.1'
,
CURLOPT_PROXYPORT
=>
1080
,
]);
}
$res
=
$ch
->
get
(
$api
,
false
);
//json
if
(
$res
&&
$res
[
'status'
]
==
'ok'
)
{
if
(
$res
&&
$res
[
'status'
]
==
'ok'
)
{
$data
=
$res
[
'data'
];
$data
=
$res
[
'data'
];
/**
* @var $redis \yii\redis\Connection
*/
$redis
=
Yii
::
$app
->
redis
;
foreach
(
$data
as
$item
)
{
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'
]));
}
}
}
}
}
}
...
...
common/service/exchange/HuoBi.php
View file @
43ee5f02
...
@@ -25,24 +25,12 @@ class HuoBi extends Exchange implements ExchangeInterface
...
@@ -25,24 +25,12 @@ class HuoBi extends Exchange implements ExchangeInterface
public
function
setSupportedSymbol
()
public
function
setSupportedSymbol
()
{
{
$api
=
$this
->
base_url
.
'/v1/common/symbols'
;
$api
=
$this
->
base_url
.
'/v1/common/symbols'
;
$key
=
$this
->
supported_symbol
;
$res
=
$this
->
ch
->
get
(
$api
,
false
);
//json
$ch
=
new
Curl
();
//http代理
if
(
USER_PROXY
)
{
$ch
->
setOptions
([
CURLOPT_PROXY
=>
'127.0.0.1'
,
CURLOPT_PROXYPORT
=>
1080
,
]);
}
$res
=
$ch
->
get
(
$api
,
false
);
//json
if
(
$res
&&
$res
[
'status'
]
==
'ok'
)
{
if
(
$res
&&
$res
[
'status'
]
==
'ok'
)
{
$data
=
$res
[
'data'
];
$data
=
$res
[
'data'
];
/**
* @var $redis \yii\redis\Connection
*/
$redis
=
Yii
::
$app
->
redis
;
foreach
(
$data
as
$item
)
{
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
...
@@ -50,25 +38,13 @@ class HuoBi extends Exchange implements ExchangeInterface
public
function
setQuotation
()
public
function
setQuotation
()
{
{
$api
=
$this
->
base_url
.
'/market/tickers'
;
$api
=
$this
->
base_url
.
'/market/tickers'
;
$ch
=
new
Curl
();
$res
=
$this
->
ch
->
get
(
$api
,
false
);
//http代理
if
(
USER_PROXY
)
{
$ch
->
setOptions
([
CURLOPT_PROXY
=>
'127.0.0.1'
,
CURLOPT_PROXYPORT
=>
1080
,
]);
}
$res
=
$ch
->
get
(
$api
,
false
);
if
(
$res
&&
$res
[
'status'
]
==
'ok'
)
{
if
(
$res
&&
$res
[
'status'
]
==
'ok'
)
{
$datas
=
$res
[
'data'
];
$datas
=
$res
[
'data'
];
/**
* @var $redis \yii\redis\Connection
*/
$redis
=
Yii
::
$app
->
redis
;
foreach
(
$datas
as
$item
)
{
foreach
(
$datas
as
$item
)
{
$key
=
$this
->
quotation_prefix
.
$item
[
'symbol'
];
$key
=
$this
->
quotation_prefix
.
$item
[
'symbol'
];
$redis
->
hmset
(
$key
,
'low'
,
$item
[
'low'
],
'high'
,
$item
[
'high'
],
'last'
,
$item
[
'close'
]);
$
this
->
redis
->
hmset
(
$key
,
'low'
,
$item
[
'low'
],
'high'
,
$item
[
'high'
],
'last'
,
$item
[
'close'
]);
$redis
->
sadd
(
$this
->
supported_symbol
,
$item
[
'symbol'
]);
$
this
->
redis
->
sadd
(
$this
->
supported_symbol
,
$item
[
'symbol'
]);
}
}
}
}
}
}
...
...
console/controllers/ExchangeController.php
View file @
43ee5f02
...
@@ -37,7 +37,7 @@ class ExchangeController extends Controller
...
@@ -37,7 +37,7 @@ class ExchangeController extends Controller
public
function
actionTest
()
public
function
actionTest
()
{
{
$a
=
new
\common\service\exchange\Bit
fin
ex
();
$a
=
new
\common\service\exchange\Bit
tr
ex
();
// $a->setSupportedSymbol();
// $a->setSupportedSymbol();
$a
->
setQuotation
();
$a
->
setQuotation
();
...
...
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