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
784121e5
Commit
784121e5
authored
Aug 15, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ticker factory
parent
6575d4c5
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
206 additions
and
0 deletions
+206
-0
TickerController.php
api/controllers/TickerController.php
+92
-0
ExchangeBuilderFactory.php
common/service/exchange/ExchangeBuilderFactory.php
+24
-0
BinanceBuilder.php
common/service/exchange/factory/BinanceBuilder.php
+46
-0
HuobiBuilder.php
common/service/exchange/factory/HuobiBuilder.php
+15
-0
OkexBuilder.php
common/service/exchange/factory/OkexBuilder.php
+14
-0
ZhaobiBuilder.php
common/service/exchange/factory/ZhaobiBuilder.php
+15
-0
No files found.
api/controllers/TickerController.php
0 → 100644
View file @
784121e5
<?php
namespace
api\controllers
;
use
Yii
;
use
api\base\BaseController
;
use
common\service\exchange\ExchangeBuilderFactory
;
class
TickerController
extends
BaseController
{
public
function
actionIndex
()
{
$exchange
=
Yii
::
$app
->
request
->
get
(
'exchange'
,
'zhaobi'
);
$exchange_arr
=
[
'huobi'
,
'binance'
,
'okex'
,
'zhaobi'
];
if
(
!
in_array
(
$exchange
,
$exchange_arr
))
{
$msg
=
'不存在的交易平台'
;
$code
=
-
1
;
goto
doEnd
;
}
$builder
=
ExchangeBuilderFactory
::
create
(
$exchange
);
$result
=
$builder
->
getTicker
();
doEnd
:
return
[
'code'
=>
$code
,
'msg'
=>
$msg
];
}
public
function
actionGameTradeUpdate
()
{
$coinAirDropTrade
=
CoinAirDropTrade
::
find
()
->
where
([
'attach'
=>
2
,
'msg'
=>
'0'
])
->
limit
(
30
)
->
all
();
foreach
(
$coinAirDropTrade
as
$val
)
{
$fee
=
100000
;
$amount
=
1
*
1e8
;
$execer
=
'coins'
;
$note
=
''
;
$service
=
new
Chain33Service
();
$createRawTransaction
=
$service
->
createRawTransaction
(
$val
->
coins_address
,
$amount
,
$fee
,
$note
,
$execer
);
if
(
0
!=
$createRawTransaction
[
'code'
])
{
continue
;
}
$txHex
=
$createRawTransaction
[
'result'
];
$privkey
=
'72c3879f1f9b523f266a9545b69bd41c0251483a93e21e348e85118afe17a5e2'
;
$expire
=
'1m'
;
$signRawTx
=
$service
->
signRawTx
(
$privkey
,
$txHex
,
$expire
);
if
(
0
!=
$signRawTx
[
'code'
])
{
continue
;
}
$sign_str
=
$signRawTx
[
'result'
];
$result
=
$service
->
sendTransaction
(
$sign_str
);
if
(
0
!=
$result
[
'code'
])
{
continue
;
}
$currentModel
=
CoinAirDropTrade
::
findOne
(
$val
->
id
);
$currentModel
->
attach
=
2
;
$currentModel
->
balance
=
0
;
$currentModel
->
msg
=
$result
[
'result'
];
$currentModel
->
save
();
}
return
[
'code'
=>
1
,
'msg'
=>
'ok'
];
}
public
function
actionGetBalance
()
{
$coinAirDropTrade
=
CoinAirDropTrade
::
find
()
->
where
([
'balance'
=>
0
])
->
limit
(
60
)
->
all
();
$address
=
[];
foreach
(
$coinAirDropTrade
as
$val
)
{
$address
[]
=
$val
->
coins_address
;
}
$service
=
new
Chain33Service
();
$execer
=
'coins'
;
$result
=
$service
->
getBalance
(
$address
,
$execer
);
if
(
0
==
$result
[
'code'
])
{
$result_balance
=
$result
[
'result'
];
foreach
(
$result_balance
as
$val
)
{
$coinAirDropTrade
=
CoinAirDropTrade
::
find
()
->
where
([
'coins_address'
=>
$val
[
'addr'
]])
->
one
();
if
(
empty
(
$coinAirDropTrade
))
continue
;
$coinAirDropTrade
->
balance
=
$val
[
'balance'
];
$coinAirDropTrade
->
save
();
}
}
return
[
'code'
=>
1
,
'msg'
=>
'ok'
];
}
}
\ No newline at end of file
common/service/exchange/ExchangeBuilderFactory.php
0 → 100644
View file @
784121e5
<?php
namespace
common\service\exchange
;
/**
* Created by PhpStorm.
* User: jiaming
* Date: 2019/8/15
* Time: 10:10
*/
class
ExchangeBuilderFactory
{
private
static
$cached
=
[];
public
static
function
create
(
$type
)
{
if
(
empty
(
static
::
$cached
[
$type
]))
{
$type
=
str_replace
(
' '
,
''
,
ucwords
(
$type
));
$class
=
__NAMESPACE__
.
"
\\
factory
\\
{
$type
}
Builder"
;
static
::
$cached
[
$type
]
=
new
$class
;
}
return
static
::
$cached
[
$type
];
}
}
common/service/exchange/factory/BinanceBuilder.php
0 → 100644
View file @
784121e5
<?php
/**
* Created by PhpStorm.
* User: jiaming
* Date: 2019/8/15
* Time: 10:10
*/
namespace
common\service\exchange\factory
;
use
linslin\yii2\curl\Curl
;
class
BinanceBuilder
{
protected
$base_url
=
'https://api.binance.com'
;
protected
$base_coin
=
[
'ETH'
,
'BTC'
,
'USDT'
,
'BTC'
];
function
__construct
()
{
}
function
getTicker
()
{
$curl
=
new
Curl
();
$api
=
$this
->
base_url
.
'/api/v1/ticker/24hr'
;
$res
=
$curl
->
get
(
$api
,
false
);
if
(
is_array
(
$res
))
{
foreach
(
$res
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
[
'lastPrice'
]);
$ticker
[
$val
[
'symbol'
]][
'change'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$val
[
'priceChangePercent'
]);
$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
[
'volume'
]);
}
}
}
}
echo
json_encode
(
$ticker
);
exit
;
}
}
\ No newline at end of file
common/service/exchange/factory/HuobiBuilder.php
0 → 100644
View file @
784121e5
<?php
namespace
common\service\exchange\factory
;
/**
* Created by PhpStorm.
* User: jiaming
* Date: 2019/8/15
* Time: 10:10
*/
class
HuobiBuilder
{
}
\ No newline at end of file
common/service/exchange/factory/OkexBuilder.php
0 → 100644
View file @
784121e5
<?php
namespace
common\service\exchange\factory
;
/**
* Created by PhpStorm.
* User: jiaming
* Date: 2019/8/15
* Time: 10:10
*/
class
OkexBuilder
{
}
\ No newline at end of file
common/service/exchange/factory/ZhaobiBuilder.php
0 → 100644
View file @
784121e5
<?php
namespace
common\service\exchange\factory
;
/**
* Created by PhpStorm.
* User: jiaming
* Date: 2019/8/15
* Time: 10:10
*/
class
Zhaobi
{
}
\ 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