IndexTicker.php 1.0 KB
<?php

namespace trader\struct;

class IndexTicker
{
    public string $symbol = "";
    public float $price = 0.0;
    public float $high24 = 0.0;
    public float $low24 = 0.0;
    public float $open24 = 0.0;

    public function __construct($symbol, $price, $high24, $low24, $open24)
    {
        $this->symbol = $symbol;
        $this->price = $price;
        $this->high24 = $high24;
        $this->low24 = $low24;
        $this->open24 = $open24;
    }
    public function toArray()
    {
        return [
            'symbol' => $this->symbol,
            'price' => $this->price,
            'high24' => $this->high24,
            'low24' => $this->low24,
            'open24' => $this->open24,
        ];
    }
    public static function transferOkxData($data): array
    {
        $res = [];
        foreach ($data as $item) {
            $symbol = str_replace('-', '', $item['instId']);
            $res[] = new IndexTicker($symbol, $item['idxPx'], $item['high24h'], $item['low24h'], $item['open24h']);
        }
        return $res;
    }
}