Commit 414a32a4 authored by shajiaiming's avatar shajiaiming

fix

parent 41e20e62
......@@ -2,7 +2,6 @@
namespace api\controllers;
use Yii;
use api\base\BaseController;
use common\service\exchange\ExchangeBuilderFactory;
......@@ -29,64 +28,4 @@ class TickerController extends BaseController
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
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
......@@ -8,39 +8,28 @@
namespace common\service\exchange\factory;
use common\service\exchange\ExchangeFactory;
use linslin\yii2\curl\Curl;
class BinanceBuilder
class BinanceBuilder extends FactoryService
{
protected $base_url = 'https://api.binance.com';
protected $base_coin = ['ETH', 'BTC', 'USDT', 'BTC'];
public function __construct()
{
}
public function getTicker()
{
$curl = new Curl();
$api = $this->base_url . '/api/v1/ticker/24hr';
$res = $curl->get($api, false);
$code = -1;
$ticker = [];
if (is_array($res)) {
$code = 0;
$exchange = ExchangeFactory::createExchange("Go");
$rate = $exchange->getTicker("CNY", "USD");
$cny_usd_rate = 1 / $rate['last'];
$this->code = 0;
foreach ($res as $val) {
foreach ($this->base_coin as $k => $coin) {
foreach ($this->basic_coin as $k => $coin) {
$explode_arr = explode($coin, $val['symbol']);
if (2 == count($explode_arr) && empty($explode_arr[1])) {
$temp = [];
$temp['symbol'] = $explode_arr[0] . '/' . $coin;
$temp['close'] = (float)sprintf("%0.4f", $val['lastPrice']);
$temp['close_rmb'] = (float)sprintf("%0.4f", $val['lastPrice'] / $cny_usd_rate);
$temp['close_rmb'] = (float)sprintf("%0.4f", $val['lastPrice'] * $this->basic_price[$coin]);
$temp['change'] = (float)sprintf("%0.4f", $val['priceChangePercent']);
$temp['high'] = (float)sprintf("%0.4f", $val['highPrice']);
$temp['low'] = (float)sprintf("%0.4f", $val['lowPrice']);
......@@ -51,6 +40,6 @@ class BinanceBuilder
}
}
}
return ['code' => $code, 'ticker' => $ticker];
return ['code' => $this->code, 'ticker' => $ticker];
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: jiaming
* Date: 2019/8/20
* Time: 10:10
*/
namespace common\service\exchange\factory;
use linslin\yii2\curl\Curl;
abstract class FactoryService
{
protected $code = -1;
protected $basic_coin = ['ETH', 'BTC', 'USDT', 'BTY'];
protected $basic_price = [];
public function __construct()
{
$curl = new Curl();
$data = [
"names" => [
"eth,ethereum",
"btc,btc",
"usdt,ethereum",
"bty,bty",
]
];
$params = json_encode($data);
$curl->setHeader('Content-Type', 'application/json');
$curl->setRawPostData($params);
$res = $curl->post('https://b.biqianbao.net/interface/coin/coin-index', true);
$res = json_decode($res, true);
foreach ($res['data'] as $val) {
$this->basic_price[$val['name']] = $val['rmb'];
}
}
public function symbolPrice($symbol = 'ETH')
{
}
}
\ No newline at end of file
......@@ -8,39 +8,28 @@
namespace common\service\exchange\factory;
use common\service\exchange\ExchangeFactory;
use linslin\yii2\curl\Curl;
class HuobiBuilder
class HuobiBuilder extends FactoryService
{
protected $base_url = 'https://api.huobi.pro';
protected $base_coin = ['ETH', 'BTC', 'USDT', 'BTC'];
public function __construct()
{
}
public function getTicker()
{
$curl = new Curl();
$api = $this->base_url . '/market/tickers';
$res = $curl->get($api, false);
$code = -1;
$ticker = [];
if (isset($res['status']) && 'ok' == $res['status']) {
$code = 0;
$exchange = ExchangeFactory::createExchange("Go");
$rate = $exchange->getTicker("CNY", "USD");
$cny_usd_rate = 1 / $rate['last'];
$this->code = 0;
foreach ($res['data'] as $val) {
foreach ($this->base_coin as $k => $coin) {
foreach ($this->basic_coin as $k => $coin) {
$explode_arr = explode(strtolower($coin), $val['symbol']);
if (2 == count($explode_arr) && empty($explode_arr[1])) {
$temp = [];
$temp['symbol'] = strtoupper($explode_arr[0]) . '/' . $coin;
$temp['close'] = (float)sprintf("%0.4f", $val['close']);
$temp['close_rmb'] = (float)sprintf("%0.4f", $val['close'] / $cny_usd_rate);
$temp['close_rmb'] = (float)sprintf("%0.4f", $val['close'] * $this->basic_price[$coin]);
$temp['change'] = (float)sprintf("%0.4f", ($val['close'] - $val['open']) / $val['open'] * 100);
$temp['high'] = (float)sprintf("%0.4f", $val['high']);
$temp['low'] = (float)sprintf("%0.4f", $val['low']);
......@@ -51,6 +40,6 @@ class HuobiBuilder
}
}
}
return ['code' => $code, 'ticker' => $ticker];
return ['code' => $this->code, 'ticker' => $ticker];
}
}
\ No newline at end of file
......@@ -8,34 +8,26 @@
namespace common\service\exchange\factory;
use common\service\exchange\ExchangeFactory;
use linslin\yii2\curl\Curl;
class ZhaobiBuilder
class ZhaobiBuilder extends FactoryService
{
protected $base_url = 'https://api.biqianbao.top';
protected $base_coin = ['ETH', 'BTC', 'USDT', 'BTC', 'BTY'];
public function __construct()
{
}
public function getTicker()
{
$curl = new Curl();
$api = $this->base_url . '/api/data/Ticker?sort=cname';
$res = $curl->get($api, false);
$code = -1;
$ticker = [];
if (isset($res['message']) && 'OK' == $res['message']) {
$code = 0;
$this->code = 0;
$ticker_temp = [];
foreach ($res['data'] as $val) {
$ticker_temp = array_merge($ticker_temp, $val);
}
foreach ($ticker_temp as $val) {
foreach ($this->base_coin as $k => $coin) {
foreach ($this->basic_coin as $k => $coin) {
$explode_arr = explode($coin, $val['symbol']);
if (2 == count($explode_arr) && empty($explode_arr[1])) {
$temp = [];
......@@ -52,6 +44,6 @@ class ZhaobiBuilder
}
}
}
return ['code' => $code, 'ticker' => $ticker];
return ['code' => $this->code, 'ticker' => $ticker];
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment