- [Fetch First Ohlcv Timestamp](./examples/php/) ```php market($symbol); $market_type = $exchange->safe_string($market, 'type'); $features = $exchange->safe_dict($exchange->features, $market_type, array()); if ($market['subType'] !== null) { $features = $exchange->safe_dict($features, $market['subType'], array()); } $ohlcv = $exchange->safe_dict($features, 'fetchOHLCV'); if ($ohlcv === null) { return null; } $limit = $exchange->safe_integer($ohlcv, 'limit'); $fetch_params = array( 'maxRetriesOnFailure' => 3, ); // start loop $current_since = $exchange->milliseconds() - $milliseconds_per_day * ($limit - 1); $found_start_time = 0; // eslint-disable-next-line while (true) { $current_since = max($current_since, $minimum_timestamp); $daily_bars = Async\await($exchange->fetch_ohlcv($symbol, '1d', $current_since, $limit, $fetch_params)); if (count($daily_bars) <= 0) { break; // if no days returned, then probably start date was passed } $first_ts = $daily_bars[0][0]; if ($first_ts === $found_start_time) { // if the first timestamp is equal to the last-fetched timestamp, then break here, because some exchanges still return initial bar even if since is much ahead to listing time break; } $found_start_time = $first_ts; $current_since = $found_start_time - $milliseconds_per_day * ($limit - 1); // shift 'since' one step back if (count($daily_bars) === 1) { // in some cases, some exchanges might still return first bar of chart when endtime overlaps previous day break; } } // if minute resolution needed if ($use_minute_timeframe) { $max_iteration = ((int) ceil($minutes_per_day / $limit)) * 2; $all_promises = []; for ($i = 0; $i < $max_iteration; $i++) { $current_since = $found_start_time - $milliseconds_per_day + $i * $limit * 60 * 1000; // shift one-duration back for more accuracy for different kind of exchanges, like OKX, where first daily bar is offset by one day, but minute bars present $all_promises[] = $exchange->fetch_ohlcv($symbol, '1m', $current_since, $limit, $fetch_params); } $all_responses = Async\await(Promise\all($all_promises)); // find earliest bar for ($i = 0; $i < count($all_responses); $i++) { $response = $all_responses[$i]; if (count($response) > 0) { $found_start_time = $response[0][0]; break; } } } return $found_start_time; }) (); } // ###### Usage ###### $run_example = false; // set to true to run example if ($run_example) { $my_ex = new \ccxt\async\binance(); Async\await($my_ex->load_markets()); $symbol = 'TRUMP/USDT'; $earliest_timestamp = Async\await(fetch_first_bar_timestamp($my_ex, $symbol, true)); var_dump('- Earliest bar timestamp:', $earliest_timestamp, ', readable: ', $my_ex->iso8601($earliest_timestamp)); var_dump('- market.created value:', $my_ex->market($symbol)['created']); } ```