123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965 |
- <?php
- namespace Mobile\Controller;
- class AjaxtradeController extends MobileController
- {
-
- //获取当前最新价格
- public function getcoinprice($symbol = null){
- if($symbol == '' || $symbol == null){
- $this->ajaxReturn(['code'=>0]);
- }
- if($symbol == "UKB/USDT"){
- $symbol = "ukb_usdt";
- $mlist = M("market")->where(array('name'=>$symbol))->field("new_price,min_price,max_price,faxingjia,volume")->find();
- $num = 0.001 * rand(1,9);
-
- $open = $mlist['min_price'];//开盘价
- $close = $mlist['new_price'] + $num;//现价
- $lowhig = $close - $open; //涨跌
- $change = round(($lowhig / $open * 100),2); //涨跌幅
-
- if($change >= 0){
- $change = '<span class="green" style="font-size:18px;font-weight: 500;">+' .$change. '%</span>';
- }else{
- $change = '<span class="red" style="font-size:18px;font-weight: 500;">' .$change. '%</span>';
- }
-
- if($close >= $open){
- $close = '<span class="green" style="font-size:18px;font-weight: 500;">'.$close.'</span>';
- }else{
- $close = '<span class="red" style="font-size:18px;font-weight: 500;">'.$close.'</span>';
- }
-
- $data['code']=1;
- $data['price'] = $close;
- $data['change']= $change;
-
- $this->ajaxReturn($data);
-
- }else{
- $arr = explode('/',$symbol);
- $coinname = strtolower($arr[0]).strtolower($arr[1]);
- $url = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=".$coinname;
- $result = $this->get_maket_api($url);
- $pdata = $result['data'][0];
-
- $open = $pdata['open'];//开盘价
- $close = $pdata['close'];//现价
- $lowhig = $close - $open; //涨跌
- $change = round(($lowhig / $open * 100),2); //涨跌幅
- if($change >= 0){
- $change = '<span class="green" style="font-size:18px;font-weight: 500;">+' .$change. '%</span>';
- }else{
- $change = '<span class="red" style="font-size:18px;font-weight: 500;">' .$change. '%</span>';
- }
-
- if($close >= $open){
- $close = '<span class="green" style="font-size:18px;font-weight: 500;">'.$close.'</span>';
- }else{
- $close = '<span class="red" style="font-size:18px;font-weight: 500;">'.$close.'</span>';
- }
-
- $data['code']=1;
- $data['price'] = $close;
- $data['change']= $change;
- $data['ot_price'] = $pdata['close'];
-
- $this->ajaxReturn($data);
- }
- }
-
-
- //获取当前最新价格
- public function getnewprice($symbol = null){
- if($symbol == '' || $symbol == null){
- $this->ajaxReturn(['code'=>0]);
- }
-
- if($symbol == "UKB/USDT"){
- $symbol = "ukb_usdt";
- $mlist = M("market")->where(array('name'=>$symbol))->field("new_price")->find();
- $num = 0.001 * rand(1,9);
- $close = $mlist['new_price'] + $num;//现价
- $data['code']=1;
- $data['price']=$close;
- $this->ajaxReturn($data);
-
- }else{
-
- $arr = explode('/',$symbol);
- $coinname = strtolower($arr[0]).strtolower($arr[1]);
- $url = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=".$coinname;
- $result = $this->get_maket_api($url);
- $pdata = $result['data'][0];
- $price = $pdata['close'];
- $data['code']=1;
- $data['price']=$price;
- $this->ajaxReturn($data);
- }
- }
-
- //获取5条卖出记录
- public function gettradbuy($symbol = null){
- if($symbol == "UKB/USDT"){
- $market = "ukb_usdt";
- $list = M("trade")->where(array('market'=>$market))->order("id desc")->limit(20)->select();
- foreach($list as $key=>$vo){
- if($vo['type'] == 1){
- $ajdata[$key]['amount'] = sprintf("%.4f",$vo['num']);
- $ajdata[$key]['price'] = sprintf("%.4f",$vo['price']);
- }
- }
- $this->ajaxReturn(['code'=>1,'data'=>$ajdata]);
- }else{
- $arr = explode('/',$symbol);
- $coinname = strtolower($arr[0]).strtolower($arr[1]);
- $url = "https://api.huobi.pro/market/history/trade?symbol=".$coinname."&size=20";
- $result = $this->get_maket_api($url);
- $data = $result['data'];
- $ajdata = array();
- foreach($data as $key=>$vo){
- $direction = $vo['data'][0]['direction'];
- if($direction == "buy"){
- $ajdata[$key]['amount'] = sprintf("%.4f",$vo['data'][0]['amount']);
- $ajdata[$key]['price'] = sprintf("%.4f",$vo['data'][0]['price']);
- }
- }
- $this->ajaxReturn(['code'=>1,'data'=>$ajdata]);
- }
- }
- //获取5条购买记录
- public function gettradsell($symbol = null){
- if($symbol == "UKB/USDT"){
- $market = "ukb_usdt";
- $list = M("trade")->where(array('market'=>$market))->order("id desc")->limit(20)->select();
- foreach($list as $key=>$vo){
- if($vo['type'] == 2){
- $ajdata[$key]['amount'] = sprintf("%.4f",$vo['num']);
- $ajdata[$key]['price'] = sprintf("%.4f",$vo['price']);
- }
- }
- $this->ajaxReturn(['code'=>1,'data'=>$ajdata]);
- }else{
- $arr = explode('/',$symbol);
- $coinname = strtolower($arr[0]).strtolower($arr[1]);
- $url = "https://api.huobi.pro/market/history/trade?symbol=".$coinname."&size=40";
- $result = $this->get_maket_api($url);
- $data = $result['data'];
- $ajdata = array();
- foreach($data as $key=>$vo){
- $direction = $vo['data'][0]['direction'];
- if($direction == "sell"){
- $ajdata[$key]['amount'] = sprintf("%.4f",$vo['data'][0]['amount']);
- $ajdata[$key]['price'] = sprintf("%.4f",$vo['data'][0]['price']);
- }
- }
- $this->ajaxReturn(['code'=>1,'data'=>$ajdata]);
- }
- }
- //获取最新买卖记录
- public function gettradlist(){
- $coinname = trim(I('post.coinname'));
- if($coinname == "UKB"){
- $symbol = "ukb_usdt";
- $tlist = M("trade")->where(array("market"=>$symbol))->order("id desc")->limit(20)->select();
- $ajdata = array();
- foreach($tlist as $key=>$vo){
- if($vo['type'] == 1){
- $str = L('买入');
- $ajdata[$key]['strtype'] = '<span class="fzmm green">'. $str .'</span>';
- $ajdata[$key]['amount'] = '<span class="fzmm green">'. sprintf("%.4f",$vo['num']) .'</span>';
- $ajdata[$key]['price'] = '<span class="fzmm green">'. sprintf("%.4f",$vo['price']) .'</span>';
- }elseif($vo['type'] == 2){
- $str = L('卖出');
- $ajdata[$key]['strtype'] = '<span class="fzmm red">'. $str.'</span>';
- $ajdata[$key]['amount'] = '<span class="fzmm red">'. sprintf("%.4f",$vo['num']) .'</span>';
- $ajdata[$key]['price'] = '<span class="fzmm red">'. sprintf("%.4f",$vo['price']) .'</span>';
- }
- }
- $this->ajaxReturn(['code'=>1,'data'=>$ajdata]);
- }else{
- $symbol = strtolower($coinname).'usdt';
- $url = "https://api.huobi.pro/market/history/trade?symbol=".$symbol."&size=20";
- $result = $this->get_maket_api($url);
- $data = $result['data'];
- $ajdata = array();
- foreach($data as $key=>$vo){
- $direction = $vo['data'][0]['direction'];
- if($direction == "sell"){
- $str = L('卖出');
- $ajdata[$key]['strtype'] = '<span class="fzmm red">'. $str.'</span>';
- $ajdata[$key]['amount'] = '<span class="fzmm red">'. sprintf("%.4f",$vo['data'][0]['amount']) .'</span>';
- $ajdata[$key]['price'] = '<span class="fzmm red">'. sprintf("%.4f",$vo['data'][0]['price']) .'</span>';
- }elseif($direction == "buy"){
- $str = L('买入');
- $ajdata[$key]['strtype'] = '<span class="fzmm green">'. $str .'</span>';
- $ajdata[$key]['amount'] = '<span class="fzmm green">'. sprintf("%.4f",$vo['data'][0]['amount']) .'</span>';
- $ajdata[$key]['price'] = '<span class="fzmm green">'. sprintf("%.4f",$vo['data'][0]['price']) .'</span>';
- }
- }
- $this->ajaxReturn(['code'=>1,'data'=>$ajdata]);
- }
-
- }
-
- //获取主流货币详情
- public function get_market_one(){
- $btcapi = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=btcusdt";
- $ethapi = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=ethusdt";
- $bchapi = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=bchusdt";
- $btcresult = $this->get_maket_api($btcapi);
- $ethresult = $this->get_maket_api($ethapi);
- $bchresult = $this->get_maket_api($bchapi);
-
- $btcdata = $this->processing_onedata($btcresult);
- $ethdata = $this->processing_onedata($ethresult);
- $bchdata = $this->processing_onedata($bchresult);
-
- $market['btccoin'] = "BTC/USDT";
- $market['btcnewprice'] = $btcdata['open'];
- $market['btcchange'] = $btcdata['change'];
-
- $market['ethcoin'] = "ETH/USDT";
- $market['ethnewprice'] = $ethdata['open'];
- $market['ethchange'] = $ethdata['change'];
-
- $market['bchcoin'] = "BCH/USDT";
- $market['bchnewprice'] = $bchdata['open'];
- $market['bchchange'] = $bchdata['change'];
- $market['code'] = 1;
- $this->ajaxReturn($market);
- }
-
- //处理单个行情数理
- public function processing_onedata($array){
- $price_arr = $array['data'][0];
- $open = $price_arr['open'];//开盘价
- $close = $price_arr['close'];//现价
- $lowhig = $close - $open; //涨跌
- $change = round(($lowhig / $open * 100),2); //涨跌幅
- if($change >= 0){
- $change = '<span class="green" style="font-size:14px;font-weight: 500;">+' .$change. '%</span>';
- }else{
- $change = '<span class="red" style="font-size:14px;font-weight: 500;">' .$change. '%</span>';
- }
-
- if($close >= $open){
- $close = '<span class="green" style="font-size:16px;font-weight: 500;">'.$close.'</span>';
- }else{
- $close = '<span class="red" style="font-size:16px;font-weight: 500;">'.$close.'</span>';
- }
-
- $pdata['open'] = $close;
- $pdata['change'] = $change;
- return $pdata;
- }
-
-
- //获取行情单个行情数据
- public function obtain_btc($coin){
- $symbol = $coin."usdt";
- $cname = strtoupper($coin)."/USDT";
- $api = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=".$symbol;
- $data = $this->get_maket_api($api);
- if($data['status'] == 'ok'){
- $price_arr = $data['data'][0];
- $open = $price_arr['open'];//开盘价
- $close = $price_arr['close'];//现价
- $lowhig = $close - $open; //涨跌
- $change = round(($lowhig / $open * 100),2); //涨跌幅
- if($change >= 0){
- $changestr = "<span class='fzmm bgreen' style='color:#fff;border-radius: 2px;width:70px;height:35px;line-height:35px;text-align:center;display:inline-block;'>+". $change ."%</span>";
- }else{
- $changestr = "<span class='fzmm bred' style='color:#fff;border-radius: 2px;width:70px;height:35px;line-height:35px;text-align:center;display:inline-block;'>". $change ."%</span>";
- }
-
- if($close >= $open){
- $close = "<span class='fzmmm green'>".$close."</span>";
- }else{
- $close = "<span class='fzmmm red'>".$close."</span>";
- }
- $alldata['code'] = 1;
- $alldata['cname'] = $cname;
- $alldata['open'] = $close;
- $alldata['change'] = $changestr;
- $this->ajaxReturn($alldata);
- }else{
- $this->ajaxReturn(['code'=>0,'info'=>"error"]);
- }
-
- }
-
- //获取行情单个行情数据
- public function obtain_eth($coin){
- $symbol = $coin."usdt";
- $cname = strtoupper($coin)."/USDT";
- $api = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=".$symbol;
- $data = $this->get_maket_api($api);
- if($data['status'] == 'ok'){
- $price_arr = $data['data'][0];
- $open = $price_arr['open'];//开盘价
- $close = $price_arr['close'];//现价
- $lowhig = $close - $open; //涨跌
- $change = round(($lowhig / $open * 100),2); //涨跌幅
- if($change >= 0){
- $changestr = "<span class='fzmm bgreen' style='color:#fff;border-radius: 2px;width:70px;height:35px;line-height:35px;text-align:center;display:inline-block;'>+". $change ."%</span>";
- }else{
- $changestr = "<span class='fzmm bred' style='color:#fff;border-radius: 2px;width:70px;height:35px;line-height:35px;text-align:center;display:inline-block;'>". $change ."%</span>";
- }
-
- if($close >= $open){
- $close = "<span class='fzmmm green'>".$close."</span>";
- }else{
- $close = "<span class='fzmmm red'>".$close."</span>";
- }
- $alldata['code'] = 1;
- $alldata['cname'] = $cname;
- $alldata['open'] = $close;
- $alldata['change'] = $changestr;
- $this->ajaxReturn($alldata);
- }else{
- $this->ajaxReturn(['code'=>0,'info'=>"error"]);
- }
-
- }
-
- //获取行情单个行情数据
- public function obtain_eos($coin){
- $symbol = $coin."usdt";
- $cname = strtoupper($coin)."/USDT";
- $api = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=".$symbol;
- $data = $this->get_maket_api($api);
- if($data['status'] == 'ok'){
- $price_arr = $data['data'][0];
- $open = $price_arr['open'];//开盘价
- $close = $price_arr['close'];//现价
- $lowhig = $close - $open; //涨跌
- $change = round(($lowhig / $open * 100),2); //涨跌幅
- if($change >= 0){
- $changestr = "<span class='fzmm bgreen' style='color:#fff;border-radius: 2px;width:70px;height:35px;line-height:35px;text-align:center;display:inline-block;'>+". $change ."%</span>";
- }else{
- $changestr = "<span class='fzmm bred' style='color:#fff;border-radius: 2px;width:70px;height:35px;line-height:35px;text-align:center;display:inline-block;'>". $change ."%</span>";
- }
-
- if($close >= $open){
- $close = "<span class='fzmmm green'>".$close."</span>";
- }else{
- $close = "<span class='fzmmm red'>".$close."</span>";
- }
- $alldata['code'] = 1;
- $alldata['cname'] = $cname;
- $alldata['open'] = $close;
- $alldata['change'] = $changestr;
- $this->ajaxReturn($alldata);
- }else{
- $this->ajaxReturn(['code'=>0,'info'=>"error"]);
- }
-
- }
-
- //获取行情单个行情数据
- public function obtain_doge($coin){
- $symbol = $coin."usdt";
- $cname = strtoupper($coin)."/USDT";
- $api = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=".$symbol;
- $data = $this->get_maket_api($api);
- if($data['status'] == 'ok'){
- $price_arr = $data['data'][0];
- $open = $price_arr['open'];//开盘价
- $close = $price_arr['close'];//现价
- $lowhig = $close - $open; //涨跌
- $change = round(($lowhig / $open * 100),2); //涨跌幅
- if($change >= 0){
- $changestr = "<span class='fzmm bgreen' style='color:#fff;border-radius: 2px;width:70px;height:35px;line-height:35px;text-align:center;display:inline-block;'>+". $change ."%</span>";
- }else{
- $changestr = "<span class='fzmm bred' style='color:#fff;border-radius: 2px;width:70px;height:35px;line-height:35px;text-align:center;display:inline-block;'>". $change ."%</span>";
- }
-
- if($close >= $open){
- $close = "<span class='fzmmm green'>".$close."</span>";
- }else{
- $close = "<span class='fzmmm red'>".$close."</span>";
- }
- $alldata['code'] = 1;
- $alldata['cname'] = $cname;
- $alldata['open'] = $close;
- $alldata['change'] = $changestr;
- $this->ajaxReturn($alldata);
- }else{
- $this->ajaxReturn(['code'=>0,'info'=>"error"]);
- }
-
- }
-
- //获取行情单个行情数据
- public function obtain_bch($coin){
- $symbol = $coin."usdt";
- $cname = strtoupper($coin)."/USDT";
- $api = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=".$symbol;
- $data = $this->get_maket_api($api);
- if($data['status'] == 'ok'){
- $price_arr = $data['data'][0];
- $open = $price_arr['open'];//开盘价
- $close = $price_arr['close'];//现价
- $lowhig = $close - $open; //涨跌
- $change = round(($lowhig / $open * 100),2); //涨跌幅
- if($change >= 0){
- $changestr = "<span class='fzmm bgreen' style='color:#fff;border-radius: 2px;width:70px;height:35px;line-height:35px;text-align:center;display:inline-block;'>+". $change ."%</span>";
- }else{
- $changestr = "<span class='fzmm bred' style='color:#fff;border-radius: 2px;width:70px;height:35px;line-height:35px;text-align:center;display:inline-block;'>". $change ."%</span>";
- }
-
- if($close >= $open){
- $close = "<span class='fzmmm green'>".$close."</span>";
- }else{
- $close = "<span class='fzmmm red'>".$close."</span>";
- }
- $alldata['code'] = 1;
- $alldata['cname'] = $cname;
- $alldata['open'] = $close;
- $alldata['change'] = $changestr;
- $this->ajaxReturn($alldata);
- }else{
- $this->ajaxReturn(['code'=>0,'info'=>"error"]);
- }
-
- }
-
-
- //获取行情单个行情数据
- public function obtain_ltc($coin){
- $symbol = $coin."usdt";
- $cname = strtoupper($coin)."/USDT";
- $api = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=".$symbol;
- $data = $this->get_maket_api($api);
- if($data['status'] == 'ok'){
- $price_arr = $data['data'][0];
- $open = $price_arr['open'];//开盘价
- $close = $price_arr['close'];//现价
- $lowhig = $close - $open; //涨跌
- $change = round(($lowhig / $open * 100),2); //涨跌幅
- if($change >= 0){
- $changestr = "<span class='fzmm bgreen' style='color:#fff;border-radius: 2px;width:70px;height:35px;line-height:35px;text-align:center;display:inline-block;'>+". $change ."%</span>";
- }else{
- $changestr = "<span class='fzmm bred' style='color:#fff;border-radius: 2px;width:70px;height:35px;line-height:35px;text-align:center;display:inline-block;'>". $change ."%</span>";
- }
-
- if($close >= $open){
- $close = "<span class='fzmmm green'>".$close."</span>";
- }else{
- $close = "<span class='fzmmm red'>".$close."</span>";
- }
- $alldata['code'] = 1;
- $alldata['cname'] = $cname;
- $alldata['open'] = $close;
- $alldata['change'] = $changestr;
- $this->ajaxReturn($alldata);
- }else{
- $this->ajaxReturn(['code'=>0,'info'=>"error"]);
- }
-
- }
-
- //获取行情单个行情数据
- public function obtain_iota($coin){
- $symbol = $coin."usdt";
- $cname = strtoupper($coin)."/USDT";
- $api = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=".$symbol;
- $data = $this->get_maket_api($api);
- if($data['status'] == 'ok'){
- $price_arr = $data['data'][0];
- $open = $price_arr['open'];//开盘价
- $close = $price_arr['close'];//现价
- $lowhig = $close - $open; //涨跌
- $change = round(($lowhig / $open * 100),2); //涨跌幅
- if($change >= 0){
- $changestr = "<span class='fzmm bgreen' style='color:#fff;border-radius: 2px;width:70px;height:35px;line-height:35px;text-align:center;display:inline-block;'>+". $change ."%</span>";
- }else{
- $changestr = "<span class='fzmm bred' style='color:#fff;border-radius: 2px;width:70px;height:35px;line-height:35px;text-align:center;display:inline-block;'>". $change ."%</span>";
- }
-
- if($close >= $open){
- $close = "<span class='fzmmm green'>".$close."</span>";
- }else{
- $close = "<span class='fzmmm red'>".$close."</span>";
- }
- $alldata['code'] = 1;
- $alldata['cname'] = $cname;
- $alldata['open'] = $close;
- $alldata['change'] = $changestr;
- $this->ajaxReturn($alldata);
- }else{
- $this->ajaxReturn(['code'=>0,'info'=>"error"]);
- }
-
- }
-
- //获取行情单个行情数据
- public function obtain_fil($coin){
- $symbol = $coin."usdt";
- $cname = strtoupper($coin)."/USDT";
- $api = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=".$symbol;
- $data = $this->get_maket_api($api);
- if($data['status'] == 'ok'){
- $price_arr = $data['data'][0];
- $open = $price_arr['open'];//开盘价
- $close = $price_arr['close'];//现价
- $lowhig = $close - $open; //涨跌
- $change = round(($lowhig / $open * 100),2); //涨跌幅
- if($change >= 0){
- $changestr = "<span class='fzmm bgreen' style='color:#fff;border-radius: 2px;width:70px;height:35px;line-height:35px;text-align:center;display:inline-block;'>+". $change ."%</span>";
- }else{
- $changestr = "<span class='fzmm bred' style='color:#fff;border-radius: 2px;width:70px;height:35px;line-height:35px;text-align:center;display:inline-block;'>". $change ."%</span>";
- }
-
- if($close >= $open){
- $close = "<span class='fzmmm green'>".$close."</span>";
- }else{
- $close = "<span class='fzmmm red'>".$close."</span>";
- }
- $alldata['code'] = 1;
- $alldata['cname'] = $cname;
- $alldata['open'] = $close;
- $alldata['change'] = $changestr;
- $this->ajaxReturn($alldata);
- }else{
- $this->ajaxReturn(['code'=>0,'info'=>"error"]);
- }
-
- }
-
- //获取行情单个行情数据
- public function obtain_flow($coin){
- $symbol = $coin."usdt";
- $cname = strtoupper($coin)."/USDT";
- $api = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=".$symbol;
- $data = $this->get_maket_api($api);
- if($data['status'] == 'ok'){
- $price_arr = $data['data'][0];
- $open = $price_arr['open'];//开盘价
- $close = $price_arr['close'];//现价
- $lowhig = $close - $open; //涨跌
- $change = round(($lowhig / $open * 100),2); //涨跌幅
- if($change >= 0){
- $changestr = "<span class='fzmm bgreen' style='color:#fff;border-radius: 2px;width:70px;height:35px;line-height:35px;text-align:center;display:inline-block;'>+". $change ."%</span>";
- }else{
- $changestr = "<span class='fzmm bred' style='color:#fff;border-radius: 2px;width:70px;height:35px;line-height:35px;text-align:center;display:inline-block;'>". $change ."%</span>";
- }
-
- if($close >= $open){
- $close = "<span class='fzmmm green'>".$close."</span>";
- }else{
- $close = "<span class='fzmmm red'>".$close."</span>";
- }
- $alldata['code'] = 1;
- $alldata['cname'] = $cname;
- $alldata['open'] = $close;
- $alldata['change'] = $changestr;
- $this->ajaxReturn($alldata);
- }else{
- $this->ajaxReturn(['code'=>0,'info'=>"error"]);
- }
-
- }
-
- //获取行情单个行情数据
- public function obtain_jst($coin){
- $symbol = $coin."usdt";
- $cname = strtoupper($coin)."/USDT";
- $api = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=".$symbol;
- $data = $this->get_maket_api($api);
- if($data['status'] == 'ok'){
- $price_arr = $data['data'][0];
- $open = $price_arr['open'];//开盘价
- $close = $price_arr['close'];//现价
- $lowhig = $close - $open; //涨跌
- $change = round(($lowhig / $open * 100),2); //涨跌幅
- if($change >= 0){
- $changestr = "<span class='fzmm bgreen' style='color:#fff;border-radius: 2px;width:70px;height:35px;line-height:35px;text-align:center;display:inline-block;'>+". $change ."%</span>";
- }else{
- $changestr = "<span class='fzmm bred' style='color:#fff;border-radius: 2px;width:70px;height:35px;line-height:35px;text-align:center;display:inline-block;'>". $change ."%</span>";
- }
-
- if($close >= $open){
- $close = "<span class='fzmmm green'>".$close."</span>";
- }else{
- $close = "<span class='fzmmm red'>".$close."</span>";
- }
- $alldata['code'] = 1;
- $alldata['cname'] = $cname;
- $alldata['open'] = $close;
- $alldata['change'] = $changestr;
- $this->ajaxReturn($alldata);
- }else{
- $this->ajaxReturn(['code'=>0,'info'=>"error"]);
- }
-
- }
-
- //获取行情单个行情数据
- public function obtain_itc($coin){
- $symbol = $coin."usdt";
- $cname = strtoupper($coin)."/USDT";
- $api = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=".$symbol;
- $data = $this->get_maket_api($api);
- if($data['status'] == 'ok'){
- $price_arr = $data['data'][0];
- $open = $price_arr['open'];//开盘价
- $close = $price_arr['close'];//现价
- $lowhig = $close - $open; //涨跌
- $change = round(($lowhig / $open * 100),2); //涨跌幅
- if($change >= 0){
- $changestr = "<span class='fzmm bgreen' style='color:#fff;border-radius: 2px;width:70px;height:35px;line-height:35px;text-align:center;display:inline-block;'>+". $change ."%</span>";
- }else{
- $changestr = "<span class='fzmm bred' style='color:#fff;border-radius: 2px;width:70px;height:35px;line-height:35px;text-align:center;display:inline-block;'>". $change ."%</span>";
- }
-
- if($close >= $open){
- $close = "<span class='fzmmm green'>".$close."</span>";
- }else{
- $close = "<span class='fzmmm red'>".$close."</span>";
- }
- $alldata['code'] = 1;
- $alldata['cname'] = $cname;
- $alldata['open'] = $close;
- $alldata['change'] = $changestr;
- $this->ajaxReturn($alldata);
- }else{
- $this->ajaxReturn(['code'=>0,'info'=>"error"]);
- }
-
- }
-
- //获取行情单个行情数据
- public function obtain_ht($coin){
- $symbol = $coin."usdt";
- $cname = strtoupper($coin)."/USDT";
- $api = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=".$symbol;
- $data = $this->get_maket_api($api);
- if($data['status'] == 'ok'){
- $price_arr = $data['data'][0];
- $open = $price_arr['open'];//开盘价
- $close = $price_arr['close'];//现价
- $lowhig = $close - $open; //涨跌
- $change = round(($lowhig / $open * 100),2); //涨跌幅
- if($change >= 0){
- $changestr = "<span class='fzmm bgreen' style='color:#fff;border-radius: 2px;width:70px;height:35px;line-height:35px;text-align:center;display:inline-block;'>+". $change ."%</span>";
- }else{
- $changestr = "<span class='fzmm bred' style='color:#fff;border-radius: 2px;width:70px;height:35px;line-height:35px;text-align:center;display:inline-block;'>". $change ."%</span>";
- }
-
- if($close >= $open){
- $close = "<span class='fzmmm green'>".$close."</span>";
- }else{
- $close = "<span class='fzmmm red'>".$close."</span>";
- }
- $alldata['code'] = 1;
- $alldata['cname'] = $cname;
- $alldata['open'] = $close;
- $alldata['change'] = $changestr;
- $this->ajaxReturn($alldata);
- }else{
- $this->ajaxReturn(['code'=>0,'info'=>"error"]);
- }
-
- }
-
-
-
- //获取行情单个行情数据
- public function obtain_usdz($coin){
- $symbol = "ukb_usdt";
- $mlist = M("market")->where(array('name'=>$symbol))->field("new_price,min_price,max_price,faxingjia,volume")->find();
- //$num = 0.001 * rand(1,9);
- $open = $mlist['min_price'];//开盘价
- $close = $mlist['new_price']; //+ $num;//现价
- $lowhig = $close - $open; //涨跌
- $change = round(($lowhig / $open * 100),2); //涨跌幅
- if($change >= 0){
- $changestr = "<span class='fzmm bgreen' style='color:#fff;border-radius: 2px;width:70px;height:35px;line-height:35px;text-align:center;display:inline-block;'>+". $change ."%</span>";
- }else{
- $changestr = "<span class='fzmm bred' style='color:#fff;border-radius: 2px;width:70px;height:35px;line-height:35px;text-align:center;display:inline-block;'>". $change ."%</span>";
- }
-
- if($close >= $open){
- $close = "<span class='fzmmm green'>".$close."</span>";
- }else{
- $close = "<span class='fzmmm red'>".$close."</span>";
- }
-
- $alldata['code'] = 1;
- $alldata['cname'] = $cname;
- $alldata['open'] = $close;
- $alldata['change'] = $changestr;
- $this->ajaxReturn($alldata);
-
- }
-
-
-
-
- //获取行情数据
- public function get_maket_api($api){
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
- curl_setopt ($ch, CURLOPT_URL, $api );
- curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT,10);
- $result = json_decode(curl_exec($ch),true);
- return $result;
- }
-
- //处理行情数理
- public function processing_data($array,$cname){
- $price_arr = $array['data'][0];
- $open = $price_arr['open'];//开盘价
- $close = $price_arr['close'];//现价
- $lowhig = $close - $open; //涨跌
- $change = round(($lowhig / $open * 100),2); //涨跌幅
- if($change >= 0){
- $changestr = "<span class='fzmm bgreen' style='color:#fff;border-radius: 2px;width:70px;height:35px;line-height:35px;text-align:center;display:inline-block;'>+". $change ."%</span>";
- }else{
- $changestr = "<span class='fzmm bred' style='color:#fff;border-radius: 2px;width:70px;height:35px;line-height:35px;text-align:center;display:inline-block;'>". $change ."%</span>";
- }
-
- if($close >= $open){
- $close = "<span class='fzmmm green'>".$close."</span>";
- }else{
- $close = "<span class='fzmmm red'>".$close."</span>";
- }
-
-
- $pdata['open'] = $close;
- $pdata['cname'] = $cname;
- $pdata['change'] = $changestr;
-
- return $pdata;
- }
- //获取市场行情
- public function getallsymbol(){
- $list = M("ctmarket")->where(array('status'=>1))->field("coinname,id")->select();
- if(!empty($list)){
- foreach($list as $k=>$v){
- $symbol = $v['coinname']."usdt";
- $cname = strtoupper($v['coinname'])."/USDT";
-
- $sid = $v['id'];
- $api = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=".$symbol;
- $data = $this->get_maket_api($api);
- // print_r($data);die;
- $price_arr = $data['data'][0];
- $open = $price_arr['open'];//开盘价
- $close = $price_arr['close'];//现价
- $lowhig = $close - $open; //涨跌
- $change = round(($lowhig / $open * 100),2); //涨跌幅
- if($change >= 0){
- $changestr = "<span class='fzmm bgreen' style='color:#fff;border-radius: 2px;width:70px;height:35px;line-height:35px;text-align:center;display:inline-block;'>+". $change ."%</span>";
- }else{
- $changestr = "<span class='fzmm bred' style='color:#fff;border-radius: 2px;width:70px;height:35px;line-height:35px;text-align:center;display:inline-block;'>". $change ."%</span>";
- }
-
- if($close >= $open){
- $close = "<span class='fzmmm green'>".$close."</span>";
- }else{
- $close = "<span class='fzmmm red'>".$close."</span>";
- }
- $alldata[$k]['sid'] = $sid;
- $alldata[$k]['cname'] = $cname;
- $alldata[$k]['open'] = $close;
- $alldata[$k]['change'] = $changestr;
- }
- $this->ajaxReturn(['code'=>1,'data'=>$alldata]);
- }else{
- $this->ajaxReturn(['code'=>0]);
- }
- }
-
- //处理合约页面交易对数据
- public function hydata($array,$cname){
-
- $price_arr = $array['data'][0];
- $open = $price_arr['open'];//开盘价
- $close = $price_arr['close'];//现价
- $lowhig = $close - $open; //涨跌
- $change = round(($lowhig / $open * 100),2); //涨跌幅
- if($change >= 0){
- $changestr = "<span class='fzmm green'>+".$change."%</span>";
-
- }else{
- $changestr = "<span class='fzmm red'>".$change."%</span>";
- }
-
- if($close >= $open){
- $close = "<span class='fzmm green'>".$close."</span>";
- }else{
- $close = "<span class='fzmm red'>".$close."</span>";
- }
-
-
- $pdata['open'] = $close;
- $pdata['cname'] = $cname;
- $pdata['change'] = $changestr;
-
- return $pdata;
- }
-
- //合约页面获取所有交易对
- public function getallcoin(){
- $where['status'] = 1;
- //$where['coinname'] = array('neq','ukb');
- $list = M("ctmarket")->where($where)->field("coinname,id")->select();
- if(!empty($list)){
- foreach($list as $k=>$v){
- if($v['coinname'] == "ukb"){
- $cname = "UKB/USDT";
- $sid = $v['id'];
- $symbol = "ukb_usdt";
- $mlist = M("market")->where(array('name'=>$symbol))->field("new_price,min_price,max_price,faxingjia,volume")->find();
- //$num = 0.001 * rand(1,9);
- $open = $mlist['min_price'];//开盘价
- $close = $mlist['new_price']; //+ $num;//现价
- $lowhig = $close - $open; //涨跌
- $change = round(($lowhig / $open * 100),2); //涨跌幅
- if($change >= 0){
- $changestr = "<span class='fzmm green'>+".$change."%</span>";
- }else{
- $changestr = "<span class='fzmm red'>".$change."%</span>";
- }
-
- if($close >= $open){
- $close = "<span class='fzmm green'>".$close."</span>";
- }else{
- $close = "<span class='fzmm red'>".$close."</span>";
- }
- $alldata[$k]['sid'] = $sid;
- $alldata[$k]['coin'] = strtoupper($v['coinname']);
- $alldata[$k]['cname'] = $cname;
- $alldata[$k]['symbol'] = $v['coinname'];
- $alldata[$k]['open'] = $close;
- $alldata[$k]['change'] = $changestr;
- }else{
- $symbol = $v['coinname']."usdt";
- $cname = strtoupper($v['coinname'])."/USDT";
- $sid = $v['id'];
- $api = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=".$symbol;
- $data = $this->get_maket_api($api);
- $result = $this->hydata($data,$cname);
- $alldata[$k]['sid'] = $sid;
- $alldata[$k]['coin'] = strtoupper($v['coinname']);
- $alldata[$k]['cname'] = $result['cname'];
- $alldata[$k]['symbol'] = $v['coinname'];
- $alldata[$k]['open'] = $result['open'];
- $alldata[$k]['change'] = $result['change'];
- }
- }
- $this->ajaxReturn(['code'=>1,'data'=>$alldata]);
-
-
- }else{
- $this->ajaxReturn(['code'=>0]);
- }
- }
-
-
- //获取交易对数据
- public function getcoin_data(){
- $coinname = strtolower(trim($_POST['coinname']));
- if($coinname == "ukb"){
-
- $symbol = "ukb_usdt";
- $mlist = M("market")->where(array('name'=>$symbol))->field("new_price,min_price,max_price,faxingjia,volume")->find();
- $num = 0.001 * rand(1,9);
-
- $open = $mlist['min_price'];//开盘价
- $close = $mlist['new_price'] + $num;//现价
- $lowhig = $close - $open; //涨跌
- $change = round(($lowhig / $open * 100),2); //涨跌幅
- $_SESSION['close'] = $close;
- if($change >= 0){
- $changestr = "<span class='green' style='font-size:16px;'>+". $change ."%</span>";
- }else{
- $changestr = "<span class='red' style='font-size:16px;'>". $change ."%</span>";
- }
-
- if($close >= $open){
- $close = "<span class='green' style='font-size:22px;'>".$close."</span>";
- }else{
- $close = "<span class='red' style='font-size:22px;'>".$close."</span>";
- }
- $high = $mlist['max_price'];
- $low = $mlist['min_price'];
- $amount = $mlist['volume'];
-
- $result['close'] = $close;
- $result['change'] = $changestr;
- $result['high'] = $high;
- $result['low'] = $low;
- $result['amount'] = sprintf("%.6f",$amount);
- $result['code'] = 1;
- $result['aa'] = $_SESSION['close'];
- $this->ajaxReturn($result);
-
-
- }else{
- $symbol = strtolower($coinname)."usdt";
-
- $cname = strtoupper($coinname)."/USDT";
- $api = "https://api.huobi.pro/market/history/kline?period=1day&size=1&symbol=".$symbol;
- $data = $this->get_maket_api($api);
- $price_arr = $data['data'][0];
- $open = $price_arr['open'];//开盘价
- $close = $price_arr['close'];//现价
- $lowhig = $close - $open; //涨跌
- $change = round(($lowhig / $open * 100),2); //涨跌幅
- if($change >= 0){
- $changestr = "<span class='green' style='font-size:16px;'>+". $change ."%</span>";
- }else{
- $changestr = "<span class='red' style='font-size:16px;'>". $change ."%</span>";
- }
-
- if($close >= $open){
- $close = "<span class='green' style='font-size:22px;'>".$close."</span>";
- }else{
- $close = "<span class='red' style='font-size:22px;'>".$close."</span>";
- }
- $high = $price_arr['high'];
- $low = $price_arr['low'];
- $amount = $price_arr['amount'];
-
- $result['close'] = $close;
- $result['change'] = $changestr;
- $result['high'] = $high;
- $result['low'] = $low;
- $result['amount'] = sprintf("%.6f",$amount);
- $result['code'] = 1;
- $this->ajaxReturn($result);
- }
- }
-
- public function ajax_data(){
- $url = "https://api.huobi.pro/market/history";
- $url .= $_POST['url'].'?';
- foreach ($_POST as $k=>$v){
- if($k != 'url'){
- $url .= $k.'='.$v.'&';
- }
- }
- $data = $this->get_maket_api($url);
- echo json_encode($data);die();
-
- }
- }
- ?>
|