98_STOCKQUOTES.pm 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. # $Id: 98_STOCKQUOTES.pm 12272 2016-10-04 16:15:45Z vbs2 $
  2. package main;
  3. use strict;
  4. use warnings;
  5. use Blocking;
  6. use Finance::Quote;
  7. use Encode qw(decode encode);
  8. sub STOCKQUOTES_Initialize($)
  9. {
  10. my ($hash) = @_;
  11. $hash->{DefFn} = "STOCKQUOTES_Define";
  12. $hash->{UndefFn} = "STOCKQUOTES_Undefine";
  13. $hash->{SetFn} = "STOCKQUOTES_Set";
  14. $hash->{GetFn} = "STOCKQUOTES_Get";
  15. $hash->{AttrFn} = "STOCKQUOTES_Attr";
  16. $hash->{AttrList} = "pollInterval queryTimeout defaultSource sources stocks currency $main::readingFnAttributes";
  17. }
  18. sub STOCKQUOTES_Define($$)
  19. {
  20. my ($hash, $def) = @_;
  21. my @a = split("[ \t][ \t]*", $def);
  22. if (scalar(@a) != 2) {
  23. return "Invalid arguments! Define as 'define <name> STOCKQUOTES'";
  24. }
  25. $attr{$hash->{NAME}}{"pollInterval"} = 300;
  26. $attr{$hash->{NAME}}{"queryTimeout"} = 120;
  27. $attr{$hash->{NAME}}{"defaultSource"} = "europe";
  28. $attr{$hash->{NAME}}{"currency"} = "EUR";
  29. $hash->{QUOTER} = Finance::Quote->new;
  30. $hash->{QUOTER}->timeout(300); # Cancel fetch operation if it takes
  31. readingsSingleUpdate($hash, "state", "Initialized",1);
  32. STOCKQUOTES_UpdateCurrency($hash);
  33. STOCKQUOTES_QueueTimer($hash, 5);
  34. return undef;
  35. }
  36. sub STOCKQUOTES_Attr(@)
  37. {
  38. my ($cmd,$name,$aName,$aVal) = @_;
  39. my $hash = $defs{$name};
  40. if($aName eq "currency") {
  41. return STOCKQUOTES_UpdateCurrency($hash, $aVal);
  42. }
  43. elsif($aName eq "sources") {
  44. return STOCKQUOTES_ClearReadings($hash);
  45. }
  46. return undef;
  47. }
  48. sub STOCKQUOTES_UpdateCurrency($;$)
  49. {
  50. my ($hash, $cur) = @_;
  51. $cur = AttrVal($hash->{NAME}, "currency", "") if not defined $cur;
  52. Log3 $hash->{NAME}, 4, "STOCKQUOTES_UpdateCurrency to $cur";
  53. $hash->{QUOTER}->set_currency($cur);
  54. # delete all readings for the previous currency
  55. STOCKQUOTES_DeleteReadings($hash, undef);
  56. return undef;
  57. }
  58. sub STOCKQUOTES_Undefine($$)
  59. {
  60. my ($hash, $arg) = @_;
  61. RemoveInternalTimer($hash);
  62. BlockingKill($hash->{helper}{RUNNING_PID}) if(defined($hash->{helper}{RUNNING_PID}));
  63. return undef;
  64. }
  65. sub STOCKQUOTES_SetStockHashes($$)
  66. {
  67. my ($hash, $stocks) = @_;
  68. my $str = "";
  69. my $first = 1;
  70. foreach my $ex (keys %{ $stocks }) {
  71. $str .= "," unless $first;
  72. $first = 0;
  73. Log3 $hash->{NAME}, 4, "KEY: $ex";
  74. $str .= $ex . ":" . $stocks->{$ex}[0] . ":" . $stocks->{$ex}[1];
  75. }
  76. Log3 $hash->{NAME}, 5, "STOCKQUOTES_SetStockHashes: $str";
  77. $attr{$hash->{NAME}}{"stocks"} = $str;
  78. return undef;
  79. }
  80. sub STOCKQUOTES_GetStockHashes($)
  81. {
  82. my ($hash) = @_;
  83. my $name = $hash->{NAME};
  84. my @stocks = split ',', AttrVal($name, "stocks", "");
  85. my %stockHash = ();
  86. foreach my $stock (@stocks) {
  87. my @toks = split ":", $stock;
  88. $stockHash{$toks[0]} = [$toks[1], $toks[2]];
  89. }
  90. return \%stockHash;
  91. }
  92. sub STOCKQUOTES_ClearReadings($)
  93. {
  94. my ($hash, $stockName) = @_;
  95. delete $hash->{READINGS};
  96. return undef;
  97. }
  98. sub STOCKQUOTES_DeleteReadings($$)
  99. {
  100. my ($hash, $prefix) = @_;
  101. my $delStr = defined($prefix) ? ".*" . $prefix . "_.*" : ".*";
  102. fhem("deletereading $hash->{NAME} $delStr", 1);
  103. return undef;
  104. }
  105. sub STOCKQUOTES_RemoveStock($$)
  106. {
  107. my ($hash, $stockName) = @_;
  108. my $stocks = STOCKQUOTES_GetStockHashes($hash);
  109. if (not exists $stocks->{$stockName}) {
  110. return "There is no stock named '$stockName' to delete!";
  111. }
  112. Log3 $hash->{NAME}, 3, "STOCKQUOTES_RemoveStock: Removing $stockName";
  113. delete $stocks->{$stockName};
  114. if (not exists $stocks->{$stockName}) {
  115. Log3 $hash->{NAME}, 3, "DELETED";
  116. }
  117. STOCKQUOTES_SetStockHashes($hash, $stocks);
  118. STOCKQUOTES_DeleteReadings($hash, $stockName);
  119. return undef;
  120. }
  121. sub STOCKQUOTES_ChangeAmount($$$$)
  122. {
  123. my ($hash, $stockName, $amount, $price) = @_;
  124. my $stocks = STOCKQUOTES_GetStockHashes($hash);
  125. if (exists $stocks->{$stockName}) {
  126. $stocks->{$stockName}->[0] += $amount;
  127. $stocks->{$stockName}->[0] = 0 if ($stocks->{$stockName}[0] < 0);
  128. $stocks->{$stockName}->[1] += $price;
  129. if ($stocks->{$stockName}->[0] == 0)
  130. {
  131. Log3 $hash->{NAME}, 3, "STOCKQUOTES_ChangeAmount: Amount set to 0. Removing stock: $stockName";
  132. delete $stocks->{$stockName};
  133. STOCKQUOTES_DeleteReadings($hash, $stockName);
  134. }
  135. }
  136. else {
  137. $stocks->{$stockName}->[0] = $amount;
  138. $stocks->{$stockName}->[1] = $price;
  139. }
  140. STOCKQUOTES_SetStockHashes($hash, $stocks);
  141. STOCKQUOTES_QueueTimer($hash, 0);
  142. return undef;
  143. }
  144. sub STOCKQUOTES_Set($@)
  145. {
  146. my ($hash, $name, $cmd, @args) = @_;
  147. if($cmd eq "buy" or $cmd eq "sell") {
  148. if (scalar(@args) != 3) {
  149. return "Invalid arguments! Usage 'set $name $cmd <stockname> <count> <price total>";
  150. }
  151. my $stockName = $args[0];
  152. my $amount = $args[1];
  153. my $price = $args[2];
  154. my $fac = ($cmd eq "buy") ? 1 : -1;
  155. my $str = STOCKQUOTES_ChangeAmount($hash, $stockName, $fac * $amount, $fac * $price);
  156. STOCKQUOTES_QueueTimer($hash, 0);
  157. return $str;
  158. }
  159. elsif($cmd eq "add") {
  160. if (scalar(@args) != 1) {
  161. return "Invalid arguments! Usage 'set $name add <stockname>";
  162. }
  163. return STOCKQUOTES_ChangeAmount($hash, $args[0], 0 ,0);
  164. }
  165. elsif($cmd eq "remove") {
  166. if (scalar(@args) != 1) {
  167. return "Invalid arguments! Usage 'set $name remove <stockname>";
  168. }
  169. return STOCKQUOTES_RemoveStock($hash, $args[0]);
  170. }
  171. elsif($cmd eq "update") {
  172. return STOCKQUOTES_QueueTimer($hash, 0);
  173. }
  174. elsif($cmd eq "clearReadings") {
  175. return STOCKQUOTES_ClearReadings($hash);
  176. }
  177. my $res = "Unknown argument " . $cmd . ", choose one of " .
  178. "update buy sell add remove clearReadings";
  179. return $res ;
  180. }
  181. sub STOCKQUOTES_Get($@)
  182. {
  183. my ($hash, $name, $cmd, @args) = @_;
  184. if($cmd eq "sources") {
  185. if (scalar(@args) != 0) {
  186. return "Invalid arguments! Usage 'get $name $cmd'";
  187. }
  188. return "Available sources: " . join("\n", $hash->{QUOTER}->sources());
  189. }
  190. elsif($cmd eq "currency") {
  191. if (scalar(@args) != 1) {
  192. return "Invalid arguments! Usage 'get $name $cmd <case-sensitive search name>'";
  193. }
  194. my $currs = $hash->{QUOTER}->currency_lookup( name => $args[0] );
  195. return "Found currencies: " . join(",", keys %{ $currs });
  196. }
  197. my $res = "Unknown argument " . $cmd . ", choose one of " .
  198. "sources currency";
  199. return $res ;
  200. }
  201. sub STOCKQUOTES_QueueTimer($$)
  202. {
  203. my ($hash, $pollInt) = @_;
  204. Log3 $hash->{NAME}, 4, "STOCKQUOTES_QueueTimer: $pollInt seconds";
  205. RemoveInternalTimer($hash);
  206. delete($hash->{helper}{RUNNING_PID});
  207. InternalTimer(time() + $pollInt, "STOCKQUOTES_QueryQuotes", $hash, 0);
  208. return undef;
  209. }
  210. sub STOCKQUOTES_QueryQuotes($)
  211. {
  212. my ($hash) = @_;
  213. my $name = $hash->{NAME};
  214. if (not exists($hash->{helper}{RUNNING_PID})) {
  215. Log3 $hash->{NAME}, 4, 'STOCKQUOTES: Start blocking query';
  216. readingsSingleUpdate($hash, "state", "Updating",1);
  217. $hash->{helper}{RUNNING_PID} = BlockingCall("STOCKQUOTES_QueryQuotesBlocking",
  218. $hash,
  219. "STOCKQUOTES_QueryQuotesFinished",
  220. AttrVal($hash, "queryTimeout", 120),
  221. "STOCKQUOTES_QueryQuotesAbort",
  222. $hash);
  223. }
  224. else {
  225. Log3 $hash->{NAME}, 4, 'STOCKQUOTES_QueryQuotes: Blocking not started because still one running';
  226. }
  227. return undef;
  228. }
  229. # return the source that should be used for a stock
  230. sub STOCKQUOTES_GetSource($$)
  231. {
  232. my ($hash, $stock) = @_;
  233. my $name = $hash->{NAME};
  234. my @exs = split ",", AttrVal($name, "sources", "");
  235. my %exHash = ();
  236. foreach my $ex (@exs) {
  237. my @tok = split ":", $ex;
  238. $exHash{$tok[0]} = $tok[1];
  239. }
  240. if (exists($exHash{$stock})) {
  241. return $exHash{$stock};
  242. }
  243. return AttrVal($name, "defaultSource", "europe");
  244. }
  245. sub STOCKQUOTES_QueryQuotesBlocking($)
  246. {
  247. my ($hash) = @_;
  248. my $name = $hash->{NAME};
  249. Log3 $name, 4, 'STOCKQUOTES_QueryQuotesBlocking';
  250. my $stocks = STOCKQUOTES_GetStockHashes($hash);
  251. my %sources = ();
  252. foreach my $symbol (keys %{ $stocks }) {
  253. my @toks = split ':', $symbol;
  254. my $symbName = $toks[0];
  255. my $targetSource = STOCKQUOTES_GetSource($hash, $symbName);
  256. if (not exists $sources{$targetSource}) {
  257. $sources{$targetSource} = ();
  258. }
  259. push(@{$sources{$targetSource}}, $symbName);
  260. Log3 $name, 4, "STOCKQUOTES_QueryQuotesBlocking: Query stockname: $symbName from source $targetSource";
  261. }
  262. my $ret = $hash->{NAME};
  263. foreach my $srcKey (keys %sources) {
  264. Log3 $name, 4, "STOCKQUOTES_QueryQuotesBlocking: Fetching from source: $srcKey";
  265. my %quotes = $hash->{QUOTER}->fetch($srcKey, @{$sources{$srcKey}});
  266. foreach my $tag (keys %quotes) {
  267. my @keys = split($;, $tag);
  268. next if $quotes{$keys[0], 'success'} != 1;
  269. my $val = $quotes{$keys[0], $keys[1]};
  270. next if (not defined $val);
  271. $ret .= "|" . join("&", @keys) . "&";
  272. $val = encode('UTF-8', $val, Encode::FB_CROAK) if ($keys[1] eq "name");
  273. $ret .= $val;
  274. }
  275. }
  276. Log3 $name, 4, 'STOCKQUOTES_QueryQuotesBlocking Return value: ' . $ret;
  277. #$ret = "myC|A0M16S&currency&EUR|A0M16S&last&125.94|A0M16S&errormsg&|A0M16S&symbol&LU0321021155|A0M16S&time&17:52|A0M16S&isodate&2015-02-16|A0M16S&name&VERMöGENSMANAGEMENT BALANCE A€|A0M16S&source&VWD|A0M16S&price&125.94|A0M16S&date&02/16/2015|A0M16S&success&1";
  278. return $ret;
  279. }
  280. sub STOCKQUOTES_QueryQuotesAbort($$$)
  281. {
  282. my ($hash) = @_;
  283. my $name = $hash->{NAME};
  284. Log3 $name, 3, 'STOCKQUOTES_QueryQuotesAbort: Blocking call aborted due to timeout!';
  285. readingsSingleUpdate($hash, "state", "Update aborted",1);
  286. delete($hash->{helper}{RUNNING_PID});
  287. STOCKQUOTES_QueueTimer($hash, AttrVal($name, "pollInterval", 300));
  288. return undef;
  289. }
  290. sub STOCKQUOTES_QueryQuotesFinished($)
  291. {
  292. my ($string) = @_;
  293. return unless(defined($string));
  294. my @a = split("\\|",$string);
  295. my $name = $a[0];
  296. my $hash = $defs{$name};
  297. Log3 $name, 4, 'STOCKQUOTES_QueryQuotesFinished';
  298. delete($hash->{helper}{RUNNING_PID});
  299. my $stocks = STOCKQUOTES_GetStockHashes($hash);
  300. my %stockState = ();
  301. readingsBeginUpdate($hash);
  302. for my $i (1 .. $#a)
  303. {
  304. my @toks = split '&',$a[$i];
  305. # HACK: replace "3.2%" with "3.2" since we dont want units
  306. chop $toks[2] if ($toks[1] eq "p_change" and $toks[2] =~ /%$/);
  307. readingsBulkUpdate($hash, $toks[0] . "_" . $toks[1], $toks[2]);
  308. # build a hash filled with current values
  309. $stockState{$toks[0]}{$toks[1]} = $toks[2];
  310. }
  311. readingsEndUpdate($hash, 1);
  312. # build depot status
  313. readingsBeginUpdate($hash);
  314. foreach my $i (keys %stockState) {
  315. # we assume that every stockname is also in our stocks-hash. Otherwise something went terribly wrong
  316. my $stockCount = $stocks->{$i}->[0];
  317. my $stockBuyPrice = $stocks->{$i}->[1];
  318. my $last = (exists $stockState{$i}{"last"}) ? $stockState{$i}{"last"} : undef;
  319. my $previous = (exists $stockState{$i}{"previous"}) ? $stockState{$i}{"previous"} : undef;
  320. my $stockValue = (defined $last) ? $stockCount * $last : undef;
  321. my $stockValuePrev = (defined $previous) ? $stockCount * $previous : undef;
  322. # statics
  323. readingsBulkUpdate($hash, $i . "_d_stockcount", $stockCount);
  324. readingsBulkUpdate($hash, $i . "_d_buy_value_total", $stockBuyPrice);
  325. readingsBulkUpdate($hash, $i . "_d_buy_quote", ($stockCount == 0) ? 0 : sprintf("%.2f", $stockBuyPrice / $stockCount));
  326. # end
  327. if (defined($stockValue))
  328. {
  329. readingsBulkUpdate($hash, $i . "_d_cur_value_total", sprintf("%.2f", $stockValue));
  330. readingsBulkUpdate($hash, $i . "_d_value_diff_total", sprintf("%.2f", $stockValue - $stockBuyPrice));
  331. readingsBulkUpdate($hash, $i . "_d_p_change_total", ($stockBuyPrice == 0) ? 0 : sprintf("%.2f", 100.0 * (($stockValue / $stockBuyPrice) - 1 )));
  332. my $valueDiff = (defined $previous and defined $last) ? $stockCount * ($last - $previous) : undef;
  333. readingsBulkUpdate($hash, $i . "_d_value_diff", sprintf("%.2f", $valueDiff)) if defined $valueDiff;
  334. }
  335. if (defined($stockValuePrev))
  336. {
  337. readingsBulkUpdate($hash, $i . "_d_prev_value_total", sprintf("%.2f", $stockValuePrev));
  338. }
  339. }
  340. # update depot data
  341. my %depotSummary = ();
  342. $depotSummary{"depot_cur_value_total"} = 0;
  343. $depotSummary{"depot_prev_value_total"} = 0;
  344. $depotSummary{"depot_value_diff"} = 0;
  345. $depotSummary{"depot_buy_value_total"} = 0;
  346. foreach my $i (keys %stockState) {
  347. $depotSummary{"depot_buy_value_total"} += ReadingsVal($name, $i . "_d_buy_value_total", 0);
  348. $depotSummary{"depot_cur_value_total"} += ReadingsVal($name, $i . "_d_cur_value_total", 0);
  349. $depotSummary{"depot_prev_value_total"} += ReadingsVal($name, $i . "_d_prev_value_total", 0);
  350. $depotSummary{"depot_value_diff"} += ReadingsVal($name, $i . "_d_value_diff", 0);
  351. }
  352. readingsBulkUpdate($hash, "depot_buy_value_total", $depotSummary{"depot_buy_value_total"});
  353. readingsBulkUpdate($hash, "depot_cur_value_total", $depotSummary{"depot_cur_value_total"});
  354. readingsBulkUpdate($hash, "depot_value_diff_total", sprintf("%.2f", $depotSummary{"depot_cur_value_total"} - $depotSummary{"depot_buy_value_total"}));
  355. readingsBulkUpdate($hash, "depot_value_diff", sprintf("%.2f", $depotSummary{"depot_value_diff"}));
  356. my $depot_p_change = 0.0;
  357. if ($depotSummary{"depot_prev_value_total"} > 0.0) {
  358. $depot_p_change = sprintf("%.2f", 100.0 * (($depotSummary{"depot_cur_value_total"} / $depotSummary{"depot_prev_value_total"}) - 1 ));
  359. }
  360. readingsBulkUpdate($hash, "depot_p_change", $depot_p_change);
  361. my $depot_p_change_total = 0.0;
  362. if ($depotSummary{"depot_buy_value_total"} > 0.0) {
  363. $depot_p_change_total = sprintf("%.2f", 100.0 * (($depotSummary{"depot_cur_value_total"} / $depotSummary{"depot_buy_value_total"}) - 1 ));
  364. }
  365. readingsBulkUpdate($hash, "depot_p_change_total", $depot_p_change_total);
  366. my $now = gettimeofday();
  367. my $fmtDateTime = FmtDateTime($now);
  368. readingsBulkUpdate($hash, "state", $fmtDateTime);
  369. readingsEndUpdate($hash, 1);
  370. STOCKQUOTES_QueueTimer($hash, AttrVal($name, "pollInterval", 300));
  371. return undef;
  372. }
  373. 1;
  374. =pod
  375. =item device
  376. =item summary fetches stock quotes from data sources
  377. =item summary_DE Kursdaten von Wertpapieren
  378. =begin html
  379. <a name="STOCKQUOTES"></a>
  380. <h3>STOCKQUOTES</h3>
  381. (en | <a href="commandref_DE.html#STOCKQUOTES">de</a>)
  382. <ul>
  383. <a name="STOCKQUOTES"></a>
  384. Fetching actual stock quotes from various sources<br>
  385. <b>Preliminary</b><br>
  386. Perl module Finance::Quote must be installed:<br>
  387. <code>cpan install Finance::Quote</code> or <code>sudo apt-get install libfinance-quote-perl</code><br><br>
  388. <b>Define</b>
  389. <ul>
  390. <code>define Depot STOCKQUOTES</code><br><br>
  391. </ul>
  392. <a name="STOCKQUOTESset"></a>
  393. <b>Set</b>
  394. <ul>
  395. &lt;Symbol&gt; depends on source. May also an WKN.<br><br>
  396. <li><code>set &lt;name&gt; buy &lt;Symbol&gt; &lt;Amount&gt; &lt;Value of amount&gt;</code><br>
  397. Add a stock exchange security. If stock exchange security already exists, new values will be added to old values.<br><br>
  398. </li>
  399. <li><code>set &lt;name&gt; sell &lt;Symbol&gt; &lt;Amount&gt; &lt;Value of amount&gt;</code><br>
  400. Remove a stock exchange security (or an part of it).<br><br>
  401. </li>
  402. <li><code>set &lt;name&gt; add &lt;Symbol&gt;</code><br>
  403. Watch only<br><br>
  404. </li>
  405. <li><code>set &lt;name&gt; remove &lt;Symbol&gt;</code><br>
  406. Remove watched stock exchange security.<br><br>
  407. </li>
  408. <li><code>set &lt;name&gt; clearReadings</code><br>
  409. Clears all readings.<br><br>
  410. </li>
  411. <li><code>set &lt;name&gt; update</code><br>
  412. Refresh all readings.<br><br>
  413. </li>
  414. </ul>
  415. <a name="STOCKQUOTESget"></a>
  416. <b>Get</b>
  417. <ul>
  418. <li><code>get &lt;name&gt; sources</code><br>
  419. Lists all avaiable data sources.<br><br>
  420. </li>
  421. <li><code>get &lt;name&gt; currency &lt;Symbol&gt;</code><br>
  422. Get currency of stock exchange securities<br><br>
  423. </li>
  424. </ul>
  425. <a name="STOCKQUOTESattr"></a>
  426. <b>Attributes</b>
  427. <ul>
  428. <li>currency<br>
  429. All stock exchange securities will shown in this currency.<br>
  430. Default: EUR<br><br>
  431. </li>
  432. <li>defaultSource<br>
  433. Default source for stock exchange securities values.<br>
  434. Default: europe, valid values: from <code>get &lt;name&gt; sources</code><br><br>
  435. </li>
  436. <li>queryTimeout<br>
  437. Fetching timeout in seconds.<br>
  438. Standard: 120, valid values: Number<br><br>
  439. </li>
  440. <li>pollInterval<br>
  441. Refresh interval in seconds.<br>
  442. Standard: 300, valid values: Number<br><br>
  443. </li>
  444. <li>sources<br>
  445. An individual data source can be set for every single stock exchange securities.<br>
  446. Data sources can be fetched with: <code>get &lt;name&gt; sources</code>.<br>
  447. Format: &lt;Symbol&gt;:&lt;Source&gt;[,&lt;Symbol&gt;:&lt;Source&gt;...]<br>
  448. Example: <code>A0M16S:vwd,532669:unionfunds,849104:unionfunds</code><br>
  449. Stock exchange securities not listed in sources will be updated from defaultSource.<br><br>
  450. </li>
  451. <li>stocks<br>
  452. Will be created/modified via buy/sell/add/remove<br>
  453. Contains stock exchange securities informations in format: &lt;Symbol&gt;:&lt;Anzahl&gt;:&lt;Einstandswert&gt;[,&lt;Symbol&gt;:&lt;Anzahl&gt;:&lt;Einstandswert&gt;...]<br><br>
  454. </li>
  455. </ul><br>
  456. </ul>
  457. =end html
  458. =begin html_DE
  459. <a name="STOCKQUOTES"></a>
  460. <h3>STOCKQUOTES</h3>
  461. (<a href="commandref.html#STOCKQUOTES">en</a> | de)
  462. <ul>
  463. <a name="STOCKQUOTES"></a>
  464. Wertpapierdaten von verschiedenen Quellen holen<br>
  465. <b>Vorbereitung</b><br>
  466. Perl Modul Finance::Quote muss installiert werden:<br>
  467. <code>cpan install Finance::Quote</code> oder <code>sudo apt-get install libfinance-quote-perl</code><br><br>
  468. <b>Define</b>
  469. <ul>
  470. <code>define &lt;name&gt; STOCKQUOTES</code><br><br>
  471. </ul>
  472. <a name="STOCKQUOTESset"></a>
  473. <b>Set</b>
  474. <ul>
  475. &lt;Symbol&gt; h&auml;ngt von den jeweiligen Quellen ab. Kann auch eine WKN sein. Hier muss ggf. experimentiert werden.<br><br>
  476. <li><code>set &lt;name&gt; buy &lt;Symbol&gt; &lt;Menge&gt; &lt;Gesamtpreis&gt;</code><br>
  477. Wertpapier in Depot einbuchen. Wenn dieses Wertpapier bereits vorhanden ist, werden die Neuen einfach dazuaddiert.<br><br>
  478. </li>
  479. <li><code>set &lt;name&gt; sell &lt;Symbol&gt; &lt;Menge&gt; &lt;Gesamtpreis&gt;</code><br>
  480. Wertpapier (auch Teilmenge) wieder ausbuchen.<br><br>
  481. </li>
  482. <li><code>set &lt;name&gt; add &lt;Symbol&gt;</code><br>
  483. Wertpapier nur beobachten<br><br>
  484. </li>
  485. <li><code>set &lt;name&gt; remove &lt;Symbol&gt;</code><br>
  486. Entferne Wertpapier das nur beobachtet wird.<br><br>
  487. </li>
  488. <li><code>set &lt;name&gt; clearReadings</code><br>
  489. Alle Readings l&ouml;schen.<br><br>
  490. </li>
  491. <li><code>set &lt;name&gt; update</code><br>
  492. Alle Readings aktualisieren.<br><br>
  493. </li>
  494. </ul>
  495. <a name="STOCKQUOTESget"></a>
  496. <b>Get</b>
  497. <ul>
  498. <li><code>get &lt;name&gt; sources</code><br>
  499. Verf&uuml;gbare Datenquellen auflisten. Diese werden f&uuml;r die Attribute defaultSource und sources ben&ouml;tigt<br><br>
  500. </li>
  501. <li><code>get &lt;name&gt; currency &lt;Symbol&gt;</code><br>
  502. Wertpapierw&auml;hrung ermitteln<br><br>
  503. </li>
  504. </ul>
  505. <a name="STOCKQUOTESattr"></a>
  506. <b>Attribute</b>
  507. <ul>
  508. <li>currency<br>
  509. W&auml;hrung, in der die Wertpapiere angezeigt werden.<br>
  510. Default: EUR, g&uuml;ltige Werte: W&auml;hrungsk&uuml;rzel<br><br>
  511. </li>
  512. <li>defaultSource<br>
  513. Standardquelle f&uuml;r die Wertpapierdaten.<br>
  514. Default: europe, g&uuml;ltige Werte: alles was <code>get &lt;name&gt; sources</code> ausgibt.<br><br>
  515. </li>
  516. <li>queryTimeout<br>
  517. Timeout beim holen der Daten in Sekunden.<br>
  518. Standard: 120, g&uuml;ltige Werte: Zahl<br><br>
  519. </li>
  520. <li>pollInterval<br>
  521. Aktualisierungsintervall in Sekunden.<br>
  522. Standard: 300, g&uuml;ltige Werte: Zahl<br><br>
  523. </li>
  524. <li>sources<br>
  525. F&uuml;r jedes Wertpapier kann eine eigene Datenquelle definiert werden.<br>
  526. Die Datenquellen k&ouml;nnen &uuml;ber <code>get &lt;name&gt; sources</code> angefragt werden.<br>
  527. Format: &lt;Symbol&gt;:&lt;Source&gt;[,&lt;Symbol&gt;:&lt;Source&gt;...]<br>
  528. Beispiel: <code>A0M16S:vwd,532669:unionfunds,849104:unionfunds</code><br>
  529. Alle nicht aufgef&uuml;hrten Werpapiere werden &uuml;ber die defaultSource abgefragt.<br><br>
  530. </li>
  531. <li>stocks<br>
  532. Wird &uuml;ber buy/sell/add/remove angelegt/modifiziert<br>
  533. Enth&auml;lt die Werpapiere im Format &lt;Symbol&gt;:&lt;Anzahl&gt;:&lt;Einstandswert&gt;[,&lt;Symbol&gt;:&lt;Anzahl&gt;:&lt;Einstandswert&gt;...]<br><br>
  534. </li>
  535. </ul><br>
  536. </ul>
  537. =end html_DE
  538. =cut