You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.6 KiB
59 lines
1.6 KiB
<?php
|
|
/*
|
|
* @Descripttion:
|
|
* @version:
|
|
* @Author: GuaPi
|
|
* @Date: 2021-07-29 10:40:49
|
|
* @LastEditors: GuaPi
|
|
* @LastEditTime: 2021-08-09 17:40:57
|
|
*/
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class CoinData extends Model
|
|
{
|
|
// 空气币Kline数据
|
|
|
|
protected $table = 'data_ceb';
|
|
protected $primaryKey = 'id';
|
|
protected $guarded = [];
|
|
public $timestamps = false;
|
|
|
|
public static function getKlineData($symbol, $period, $size)
|
|
{
|
|
$builder = self::query();
|
|
|
|
$wheres = [
|
|
'1min' => 'is_1min',
|
|
'5min' => 'is_5min',
|
|
'15min' => 'is_15min',
|
|
'30min' => 'is_30min',
|
|
'60min' => 'is_1h',
|
|
'1day' => 'is_day',
|
|
'1week' => 'is_week',
|
|
'1mon' => 'is_month',
|
|
];
|
|
$where = $wheres[$period] ?? 'is_1min';
|
|
$builder->where($where, 1);
|
|
|
|
$data = $builder->where('Date', '<', time())->limit($size)->orderByDesc('Date')->get();
|
|
if (blank($data)) return [];
|
|
$data = $data->sortBy('Date')->values()->map(function ($kline) {
|
|
$item = [
|
|
"id" => $kline['Date'],
|
|
"amount" => $kline['Amount'],
|
|
"count" => $kline['Amount'],
|
|
"open" => $kline['Open'],
|
|
"close" => $kline['Close'],
|
|
"low" => $kline['Low'],
|
|
"high" => $kline['High'],
|
|
"vol" => $kline['Volume']
|
|
];
|
|
$item['price'] = $item['close'];
|
|
return $item;
|
|
})->toArray();
|
|
return $data;
|
|
}
|
|
}
|
|
|