|
<html> |
|
|
|
<head> |
|
<title>Список акций для трейдинга</title> |
|
</head> |
|
<script src="https://unpkg.com/lightweight-charts/dist/lightweight-charts.standalone.production.js"></script> |
|
<style> |
|
table, |
|
th, |
|
td { |
|
border: 1px solid black; |
|
} |
|
|
|
.buy { |
|
background-color: #c7dcbf; |
|
} |
|
|
|
table { |
|
border-collapse: collapse; |
|
} |
|
</style> |
|
|
|
<body> |
|
<?php |
|
error_reporting(E_ERROR); |
|
include_once '../vendor/autoload.php'; |
|
|
|
use \jamesRUS52\TinkoffInvest\TIClient; |
|
use \jamesRUS52\TinkoffInvest\TISiteEnum; |
|
use \jamesRUS52\TinkoffInvest\TICurrencyEnum; |
|
use \jamesRUS52\TinkoffInvest\TIInstrument; |
|
use \jamesRUS52\TinkoffInvest\TIPortfolio; |
|
use \jamesRUS52\TinkoffInvest\TIOperationEnum; |
|
use \jamesRUS52\TinkoffInvest\TIIntervalEnum; |
|
use \jamesRUS52\TinkoffInvest\TICandleIntervalEnum; |
|
use \jamesRUS52\TinkoffInvest\TICandle; |
|
use \jamesRUS52\TinkoffInvest\TIOrderBook; |
|
use \jamesRUS52\TinkoffInvest\TIInstrumentInfo; |
|
|
|
|
|
$client = new TIClient("YOUR_API_KEY", TISiteEnum::EXCHANGE); |
|
|
|
$final_assets = []; |
|
$stockes = $client->getStocks(); |
|
$count_stocks = count($stockes); |
|
echo '<b>Кол-во акций:' . $count_stocks . '</b><br>'; |
|
echo '<table style=" |
|
font-family: monospace; |
|
text-align: left; |
|
margin-top: 2em;"> |
|
<tr> |
|
<td>TICKET</td> |
|
<td>LAST PRICE</td> |
|
<td>MAX 20</td> |
|
<td>GRAPH</td> |
|
</tr> |
|
'; |
|
|
|
try { |
|
foreach ($stockes as $stock) { |
|
$count_stocks--; |
|
$figi = $stock->getFigi(); |
|
$stock_name = $stock->getTicker(); |
|
|
|
$from = new \DateTime(); |
|
$from->sub(new \DateInterval("P99D")); |
|
$to = new \DateTime(); |
|
|
|
$candles = $client->getHistoryCandles($figi, $from, $to, TIIntervalEnum::DAY); |
|
$book = $client->getHistoryOrderBook($figi, 1); |
|
|
|
$array = []; |
|
$array_time = []; |
|
foreach ($candles as $candle) { |
|
$array[] = $candle->getClose(); |
|
$array_time[] = $candle->getTime(); |
|
} |
|
|
|
$count_array = count($array); |
|
|
|
$array_20 = array_slice($array, $count_array - 20, $count_array); |
|
$array_60 = array_slice($array, $count_array - 60, $count_array); |
|
$array_30 = array_slice($array, $count_array - 30, $count_array); |
|
|
|
$min_20 = min($array_20); |
|
$max_20 = max($array_20); |
|
|
|
|
|
|
|
$min_60 = min($array_60); |
|
$max_60 = max($array_60); |
|
|
|
$current = $book -> getLastPrice(); |
|
$max_20_percentage = ($current / $max_20) * 100 - 100; |
|
$max_60_percentage = ($current / $max_60) * 100 - 100; |
|
|
|
$percent_profit = 0.03; |
|
$take_profit = $current + ($current * $percent_profit); |
|
$stop_loss = min($array_30); |
|
|
|
if ( |
|
($max_20_percentage > -0.2 && $max_20_percentage < 0.4) |
|
) { |
|
|
|
$class_name = (($max_20_percentage > 0 && $max_20_percentage < 1)) ? 'buy' : ''; |
|
|
|
echo '<tr class=' . $class_name . '> |
|
<td> |
|
<a target="_blank" href="https://www.tinkoff.ru/invest/stocks/' . $stock_name . '">' . $stock_name . '</a> |
|
</td> |
|
<td>' . $current . ' |
|
<br><b>take profit</b> '.$take_profit.' |
|
<br><b>stop loss</b> '.$stop_loss.' |
|
</td> |
|
<td>' . $max_20 . '<br>' . $max_20_percentage . '%</td> |
|
<td> |
|
<div class="stock-container" id="' . $stock_name . '"> |
|
<div class="chart"> |
|
|
|
</div> |
|
</div> |
|
</td> |
|
</tr> |
|
<script> |
|
let labels_'.$stock_name.' = '.json_encode($array_time).' |
|
let stock_name_'.$stock_name.' = '.$stock_name.' |
|
let dataChart_'.$stock_name.' = '.json_encode($array).' |
|
let width_'.$stock_name.' = 600 |
|
let height_'.$stock_name.' = 200 |
|
let container_'.$stock_name.' = document.createElement("div") |
|
let chart_'.$stock_name.' = LightweightCharts.createChart(document.querySelector("#'.$stock_name.' .chart"), { |
|
width: width_'.$stock_name.', |
|
height: height_'.$stock_name.' |
|
}) |
|
document.querySelector("#'.$stock_name.' .chart").appendChild(container_'.$stock_name.'); |
|
|
|
let arrayTimeClosePrice_'.$stock_name.' = [] |
|
labels_'.$stock_name.'.map((l, i) => { |
|
arrayTimeClosePrice_'.$stock_name.'.push({ |
|
time: l.date, |
|
value: dataChart_'.$stock_name.'[i] |
|
}) |
|
}) |
|
|
|
let areaSeries_'.$stock_name.' = chart_'.$stock_name.'.addAreaSeries({ |
|
lineColor: "rgba(67, 83, 254, 1)", |
|
lineWidth: 1, |
|
}); |
|
|
|
areaSeries_'.$stock_name.'.setData(arrayTimeClosePrice_'.$stock_name.') |
|
chart_'.$stock_name.'.timeScale().fitContent() |
|
</script> |
|
|
|
'; |
|
} |
|
sleep(0.5); |
|
} |
|
} catch (Exception $e) { |
|
} |
|
|
|
?> |
|
|
|
</body> |
|
|
|
</html> |