-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathfetch_tokens.php
More file actions
44 lines (36 loc) · 1.27 KB
/
fetch_tokens.php
File metadata and controls
44 lines (36 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
function fetchLatestTokens() {
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'https://frontend-api.pump.fun/coins/latest',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => ['accept: */*'],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
return ['error' => 'cURL Error #:' . $err];
}
$data = json_decode($response, true);
$solana_price = 210; // Current SOL price in USD
return [
'name' => $data['name'],
'symbol' => $data['symbol'],
'createdAt' => date('Y-m-d H:i:s', $data['created_timestamp'] / 1000),
'marketCap' => '$' . number_format($data['market_cap'] * $solana_price, 2),
'image' => $data['image_uri'],
'mint' => $data['mint'],
'ticker' => $data['symbol'],
'replies' => $data['reply_count']
];
}
echo json_encode(fetchLatestTokens());
?>