'Invalid input. Required: text, type']); exit; } $tickerData = readTickerData($tickerFile); // Add new item with timestamp $newItem = [ 'text' => $input['text'], 'type' => $input['type'], // 'buy' or 'sell' 'timestamp' => time() ]; // Add optional SNS fields if provided if (isset($input['fullAddress'])) { $newItem['fullAddress'] = $input['fullAddress']; } if (isset($input['snsName'])) { $newItem['snsName'] = $input['snsName']; } // Add to beginning of array (most recent first) array_unshift($tickerData, $newItem); // Keep only the last N items if (count($tickerData) > $maxItems) { $tickerData = array_slice($tickerData, 0, $maxItems); } // Save to file if (writeTickerData($tickerFile, $tickerData)) { echo json_encode(['success' => true, 'itemsCount' => count($tickerData)]); } else { http_response_code(500); echo json_encode(['error' => 'Failed to save ticker data']); } } else { http_response_code(405); echo json_encode(['error' => 'Method not allowed']); } ?>