J'utilise Perl et les packages j'ai été les chercher sur
https://metacpan.org/release/stockmonkeyhttps://metacpan.org/pod/Finance::TAVoici une partie de mon code
#!/usr/bin/env perl
# A STOCK MARKET Analyser
# MediaxCreation - 2021
# LOOK AT NYSE NASDAQ AMEX & EURONEXT
# with magic formulas
# last update 20210131 Version 2.2
use lib '/home/pi/perl5/lib/perl5'; #Module Library Path for RaspberryPi
use Acme::Tools qw(between);
use warnings;
use DBI;
use Finance::QuoteHist;
use List::Util qw(min max);
#use Data::Dumper;
use Net::FTP;
use Time::Local;
use Email::Send::SMTP::Gmail;
use Tie::File;
#Analyse ADx (DMI)
use Math::Business::ADX;
use Math::Business::RSI;
use Math::Business::SM::Stochastic;
use LWP::Simple;
use Math::Business::SMA;
use Finance::TA;
use Scalar::Util qw(looks_like_number);
my $adx = Math::Business::ADX->recommended;
my $rsi = Math::Business::RSI->recommended;
my $sto = Math::Business::SM::Stochastic->recommended;
....
########################################################
$debug=1;
$dbuser = "xxx";
$dbpass = "xxx";
$datestring = localtime();
$file = "nasdaqlisted.txt";
$file2 = "otherlisted.txt";
$filenext = "euronextlisted.txt";
$fileout = "listedsymbols.txt";
$outputfile="output.txt";
$tradingview = "https://fr.tradingview.com/chart/?symbol=";
$finvizview = "https://finviz.com/quote.ashx?t=";
...
unlink $outputfile;
# IF File too old (24h) delete old
my $mtime=(stat($file))[9];
my ($day, $month, $year)=(localtime())[3,4,5];
my $midnight=timelocal(0,0,0,$day,$month,$year);
unlink ($file) if ($mtime<$midnight);
unlink ($file2) if ($mtime<$midnight);
if (! -f $file) {
# Connect to the Nasdaq® FTP
print "Looking for ListedStocks on Nasdaq® FTP Server\n";
$ftp = Net::FTP->new("nasdaqtrader.com", Debug => 0)
or die "Cannot connect to some.host.name: $@";
# As Anonymous
$ftp->login("anonymous",'-anonymous@')
or die "Cannot login ", $ftp->message;
# Browse directory
$ftp->cwd("/SymbolDirectory")
or die "Cannot change working directory ", $ftp->message;
# Get the File of all Nasdaq Symbol listed
$ftp->get($file)
or die "get failed ", $ftp->message;
$ftp->get($file2)
or die "get failed ", $ftp->message;
$ftp->quit;
}
tie my @ry1,"Tie::File",$file or die "$file:$!";
tie my @ry2,"Tie::File",$file2 or die "$file2:$!";
tie my @ry3,"Tie::File",$filenext or die "$filenext:$!"; #Euronext special file (to be generated time to time)
tie my @out,"Tie::File",$fileout or die "$fileout:$!";
@out=(@ry1,@ry2,@ry3);
untie @out;
untie @ry3;
untie @ry2;
untie @ry1;
....
open(A, $fileout);
open(B, "> $outputfile") || die "create $outputfile : $!";
print "Opening $fileout...\n" if $debug==1;
$task = "curl -s --cookie-jar cookie.txt
https://finance.yahoo.com/quote/AAPL/?p=AAPL > goog.html";
`$task`;
my $crumbfile="goog.html";
open (my $fh, "<", $crumbfile);
while(my $line = <$fh>){
for ($line =~/CrumbStore\":\{\"crumb\":\"(?<crumb>.+?)\"\}/){
$crumb = $1;
}
}
print "Here is the crumb man!: $crumb\n" if $debug == 1; #The Crumb is mandatory now on Yahoo to grab CSV file from a ticker
unlink $crumbfile;
while(<A>) {
chop;
next if !(/Common Stock/|/Ordinary Shares/);
@l=split(/[|]/);
$symbol=$l[0];
if (index($symbol, ".") != -1) { # some tricky brol to be discard
next
}else {
if (index($symbol, ",") != -1) {
$symbol =~ tr{,}{.};
}
}
$name=$l[1];
$exch=$l[2]; #Wich Exchange is it?
if ($exch eq "N") {
$exch = "NYSE";
}else {
if ($exch eq "A" ){
$exch = "AMEX";
}else {
if ($exch eq "Euronext") {
$exch = "EURONEXT";
} else {
$exch = "NASDAQ";
}
}
}
##########################################################################
######## NEW METHOD TO GRAB QUOTE FROM YAHOO //FASTER THAN OLD// #########
#$P1 = (time() - 5384000); #60days before epoch time till now
$P1 = (time() - 31536000); #1year before epoch time till now
#$P1 = (time() - 259200); #3days before epoch time till now TEST
$P2 = time();
$task = "https://query1.finance.yahoo.com/v7/finance/download/$symbol?period1=$P1&period2=$P2&interval=1d&events=history&crumb=$crumb";
$thesymbol = "$directory$symbol.csv";
getstore($task, $thesymbol);
my $n_secs = 2;
my $start = time;
$yahoo_symbol = 0;
while ( !(-e $thesymbol) ) {
sleep 1;
getstore($task, $thesymbol); # We try again
if (time-$start >= $n_secs){
print "probleme avec le symbol $symbol on passe par l'autre methode plus lente\n";
$yahoo_symbol = 1;
}
last if time-$start >= $n_secs;
}
###############################################################################################
if ($yahoo_symbol eq 0){
open(Z,$thesymbol);
$average=0;
$count=0;
$volume = 0;
@array = ();
@data_points = ();
@gap_points = ();
@bottom = ();
@mfhigh = ();
@mflow = ();
@mfclose = ();
@mfvolume = ();
@MFI = ();
while(<Z>) {
chop;
next if (/Date/);
$count++;
@row=split(/[,]/);
$date=$row[0];
$open=$row[1];
$high=$row[2];
$low=$row[3];
$close=$row[4];
$volume=$row[6];
if (not defined $volume) { # certains symbols ont des volumes nuls ou inexistants/ pour éviter des divisions par zero on remplace l'average et le volume par 100
$average += 100;
$volume = 100;
}else {
if ($volume ne "null"){
$average += $volume;
}else{
$average += 100;
$volume = 100;
}
}
push(@array, $close);
push(@bottom, $low);
push(@data_points,[ $high, $low, $close ]);
push(@MFI,[ $high, $low, $close, $volume ]);
push(@gap_points,[ $date, $open, $high, $low, $close, $volume ]);
push(@mfhigh,$high);
push(@mflow,$low);
push(@mfclose,$close);
push(@mfvolume,$volume);
}
}else{ # Older Method super lente
$q = Finance::QuoteHist->new
(
symbols => [$symbol],
start_date => '1 year ago', # or '1 year ago', see Date::Manip
end_date => 'today',
);
$average=0;
$count=0;
$volume = 0;
@array = ();
@data_points = ();
@gap_points = ();
@bottom = ();
@mfhigh = ();
@mflow = ();
@mfclose = ();
@mfvolume = ();
@MFI = ();
# Quotes
foreach $row ($q->quotes()) {
eval {
# stuff that might die
};
#print "@$row\n";
$count++;
($symbol, $date, $open, $high, $low, $close, $volume) = @$row;
if (not defined $volume) {
$average += 100;
$volume = 100;
}else {
if ($volume ne "null"){
$average += $volume;
}else{
$average += 100;
$volume = 100;
}
}
push(@array, $close);
push(@bottom,$low);
push(@data_points,[ $high, $low, $close]);
push(@MFI,[ $high, $low, $close, $volume ]);
push(@gap_points,[ $date, $open, $high, $low, $close, $volume ]);
push(@mfhigh,$high);
push(@mflow,$low);
push(@mfclose,$close);
push(@mfvolume,$volume);
}
}
close(Z);
unlink $thesymbol;
Voilà amuses-toi bien
Mon script fait plus de 800 lignes c'est un beau bébé