Kline.php
1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
namespace trader\struct;
class Kline
{
public $time; //k线开始时间
public $open;
public $high;
public $low;
public $close;
public $vol;
public $volQuote;
public $uts; //k线更新时间
public function __construct($time, $open, $high, $low, $close, $vol, $volQuote, $uts)
{
$this->time = $time;
$this->open = $open;
$this->high = $high;
$this->low = $low;
$this->close = $close;
$this->vol = $vol;
$this->volQuote = $volQuote;
$this->uts = $uts;
}
public function toArray()
{
return [
'time' => $this->time,
'open' => $this->open,
'high' => $this->high,
'low' => $this->low,
'close' => $this->close,
'vol' => $this->vol,
'volQuote' => $this->volQuote,
];
}
public static function transferOkx($data)
{
$time = $data[0];
$open = $data[1];
$high = $data[2];
$low = $data[3];
$close = $data[4];
if (count($data) > 6) {
$vol = $data[6];
$volQuote = $data[7];
} else {
$vol = 0;
$volQuote = 0;
}
return new Kline($time, $open, $high, $low, $close, $vol, $volQuote, $time);
}
public static function transferBinance($data)
{
$kline = $data['k'];
$time = $kline['t'];
$open = $kline['o'];
$high = $kline['h'];
$low = $kline['l'];
$close = $kline['c'];
$vol = $kline['v'];
$volQuote = $kline['q'];
$uts = $data['E'];
return new Kline($time, $open, $high, $low, $close, $vol, $volQuote, $uts);
}
}