SymbolInfo.php 2.6 KB
<?php

namespace trader\struct;

require_once __DIR__ . '/../../jytools/func.php';

use function jytools\getPrecision;

class SymbolInfo
{
    public string $symbolOri; // 原始交易对
    public string $symbol; // 标准交易对
    public string $ctVal; // 合约面值
    public string $pricePrec;
    public string $qtyPrec;
    public string $lotPrec;
    public string $minLot; // 最小下单张数
    public string $minQty; // 最小下单数量

    public function __construct($symbolOri, $symbol, $ctVal, $pricePrec, $qtyPrec, $lotPrec, $minLot, $minQty)
    {
        $this->symbolOri = $symbolOri;
        $this->symbol = $symbol;
        $this->ctVal = $ctVal;
        $this->pricePrec = $pricePrec;
        $this->qtyPrec = $qtyPrec;
        $this->lotPrec = $lotPrec;
        $this->minLot = $minLot;
        $this->minQty = $minQty;
    }
    public function toArray()
    {
        return [
            'symbolOri' => $this->symbolOri,
            'symbol' => $this->symbol,
            'ctVal' => $this->ctVal,
            'pricePrec' => $this->pricePrec,
            'qtyPrec' => $this->qtyPrec,
            'lotPrec' => $this->lotPrec,
            'minLot' => $this->minLot,
            'minQty' => $this->minQty,
        ];
    }
    public static function transferOkx($data, callable $getSymbolSt): SymbolInfo
    {
        $symbolSt = $getSymbolSt($data["instId"]); //转换为标准交易对
        $pricePrec = getPrecision($data['tickSz']);
        $ctVal = $data['ctVal'];
        $minLot = $data['minSz'];
        $minQty = $minLot * $ctVal;
        $qtyPrec = getPrecision($minQty);
        $lotPrec = getPrecision($minLot);
        $info = new SymbolInfo($data["instId"], $symbolSt, $ctVal, $pricePrec, $qtyPrec, $lotPrec, $minLot, $minQty);
        return $info;
    }
    public static function transferBinance($data, callable $getSymbolSt): SymbolInfo
    {
        $symbolOri = $data['symbol'];
        $symbolSt = $getSymbolSt($symbolOri); //转换为标准交易对
        $ctVal = 1;
        $pricePrec = 0;
        $qtyPrec = 0;
        $lotPrec = 0;
        $minLot = 0;
        foreach ($data['filters'] as $v) {
            if ($v['filterType'] == 'PRICE_FILTER') {
                $pricePrec = getPrecision($v['tickSize']);
            }
            if ($v['filterType'] == 'LOT_SIZE') {
                $minLot = $v['minQty'];
                $minQty = $minLot * $ctVal;
                $qtyPrec = getPrecision($minLot);
                $lotPrec = getPrecision($minLot);
            }
        }
        $info = new SymbolInfo($symbolOri, $symbolSt, $ctVal, $pricePrec, $qtyPrec, $lotPrec, $minLot, $minQty);
        return $info;
    }
}