/* libstocks - Library to get current stock quotes from Yahoo Finance * * Copyright (C) 2000 Eric Laeuffer * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ #define __STOCKS_C__ #include #include #include #include #ifdef __WINDOWS__ #include #endif #include "http.h" #include "csv.h" #include "stocks.h" /* s = symbol n = name l1 = last trade d1 = date t1 = time c1 = variation o = open h = higher price g = lower price v = volume */ const char yahoo_us_stocks_server[]="finance.yahoo.com"; const char yahoo_eu_stocks_server[]="finance.yahoo.com"; //const char yahoo_eu_stocks_server[]="fr.finance.yahoo.com"; const char yahoo_url_beg[]="/d/quotes.csv?s="; const char yahoo_url_end[]="&f=snl1d1t1c1ohgv&e=.csv"; typedef enum { YAHOO_EUROPE, YAHOO_US } yahoo_source; #define YAHOO_US_EXT_NB 11 const char *yahoo_us_ext[YAHOO_US_EXT_NB] = { ".US", /* United States */ ".TO", /* Canada */ ".M", /* Canada */ ".V", /* Canada */ ".AL", /* Canada */ ".MX", /* Mexico */ ".SA", /* Brasil */ ".BA", /* Argentina */ ".CR", /* Venezuela */ ".SN", /* Chili */ ".AX" /* Australia */ }; /*****************************************************************************/ /* Finds, according to the symbol extension, the http source of the quotes. */ /* Actually just finance.yahoo.com and fr.finance.yahoo.com are supported. */ /* The function returns the country source (US or EUROPE). */ /*****************************************************************************/ yahoo_source find_yahoo_source(char *symbol) { char *ptr; int i; int test; ptr = strrchr(symbol, '.'); /* If no extension we suppose it is a US stock */ if (!ptr) return YAHOO_US; /* extension is found */ /* Test if it is canadian stock */ for (i=0; iNextStock = stocks_getted; stocks_getted->PreviousStock = last_stock; } else (stocks_tmp = stocks_getted); } *stock_datas = stocks_tmp; return(0); }