1

I was trying to implement the command to get the Chart data using PHP, below is the code:

<?PHP 
/**
     * Get last ticks
     * @param string $symbol - name symbol
     * @param array(MTTick) $ticks
     * @return MTRetCode
     */
    public function TickChart($symbol, &$ticks)
    {
        //--- send request
        $data = array(MTProtocolConsts::WEB_PARAM_SYMBOL => $symbol);
        $from = strtotime('2020-07-01');
        $to = strtotime('2020-07-02');
        //--- send request
        $data = array(MTProtocolConsts::WEB_PARAM_SYMBOL => $symbol, MTProtocolConsts::WEB_PARAM_FROM => $from, MTProtocolConsts::WEB_PARAM_TO => $to, MTProtocolConsts::WEB_PARAM_DATA => 'dohlc');
        if (!$this->m_connect->Send(MTProtocolConsts::WEB_CMD_TICK_HISTORY, $data))
        {
            if (MTLogger::getIsWriteLog()) MTLogger::write(MTLoggerType::ERROR, 'send tick last failed');
            return MTRetCode::MT_RET_ERR_NETWORK;
        }
        //--- get answer
        if (($answer = $this->m_connect->Read()) == null)
        {
            if (MTLogger::getIsWriteLog()) MTLogger::write(MTLoggerType::ERROR, 'answer tick last is empty');
            return MTRetCode::MT_RET_ERR_NETWORK;
        }
        //--- parse answer
        $tick_answer = null;

        if (($error_code = $this->Parse(MTProtocolConsts::WEB_CMD_TICK_HISTORY, $answer, $tick_answer)) != MTRetCode::MT_RET_OK)
        {
            if (MTLogger::getIsWriteLog()) MTLogger::write(MTLoggerType::ERROR, 'parse tick last failed: [' . $error_code . ']' . MTRetCode::GetError($error_code));
            return $error_code;
        }
        //--- get object from json
        $ticks = $tick_answer->GetArrayFromJson();
        //---
        return MTRetCode::MT_RET_OK;
    }
?>

The request was sent successfully to the server, but the response is always empty, can someone please help on this one. Thanks.

Ray A
  • 1,283
  • 2
  • 10
  • 22

0 Answers0