-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunc_tradeview.php
86 lines (73 loc) · 2.46 KB
/
func_tradeview.php
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/**
* @author Ebo Eppenga
* @copyright 2022
*
* GoldStar Buy and Sell bot based on signals from for example TradeView
* or any other platform using PHP Bybit API from zhouaini528.
*
* func_tradeview.php
* Tradeview functions required for GoldStar to run properly.
*
**/
/** Get TradingView recommendation **/
// $period = 1m: 1, 5m: 5, 15m: 15, 30m: 30, 1h: 60, 2h: 120, 4h: 240, 1W: 1W, 1M: 1M, 1d: leave emtpy (default)
function getTradingView($symbol, $period) {
// Declare bot ID variable as global
global $id;
// Retrieve from TradingView
$curl = curl_init();
$postField = '{"symbols":{"tickers":["BYBIT:' . $symbol . '"],"query":{"types":[]}},"columns":["Recommend.All|' . $period . '"]}';
curl_setopt_array($curl, array(
CURLOPT_URL => "https://scanner.tradingview.com/crypto/scan",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $postField,
CURLOPT_HTTPHEADER => array(
"accept: */*",
"accept-language: en-GB,en-US;q=0.9,en;q=0.8",
"cache-control: no-cache",
"content-type: application/x-www-form-urlencoded",
"origin: https://www.tradingview.com",
"referer: https://www.tradingview.com/",
"user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36"
)
));
// Store result
try {
$result = curl_exec($curl);
if (isset($result) && !empty($result)) {
$j = json_decode($result, true);
if (isset($j['data'][0]['d'][0])) {
$j = $j['data'][0]['d'][0];
}
}
} catch (Exception $e) {
doError($e, $id, false);
}
// Set recommendation
$recommendation = "ERROR";
if (($j > -1) && ($j < 1)) {
$recommendation = $j;
}
return $recommendation;
}
/** Evaluate TradingView recommendation for array of periods **/
// STRONG_SELL: -1...-0.5, SELL: -0.5...-0.1, NEUTRAL: -0.1...0.1, BUY: 0.1...0.5, STRONG_BUY: 0.5...1
function evalTradingView($symbol, $periods, $tv_recomMin, $tv_recomMax) {
// Get recommendations for periods
foreach ($periods as $period) {
$recommendation = getTradingView($symbol, $period);
$recommendations[] = $recommendation;
echo " " . $period . "m:" . round($recommendation, 2). ",";
}
// Determine total recommendation
$evalTV = true;
foreach ($recommendations as $recommendation) {
if (($recommendation < $tv_recomMin) || ($recommendation > $tv_recomMax)) {
$evalTV = false;
}
}
return $evalTV;
}
?>