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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
|
/*b
* Copyright (C) 2001,2002 Rick Richardson
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Author: Rick Richardson <rickr@mn.rr.com>
b*/
#define PROGNAMESTR "linuxtrade"
// #define SUCKURL "wget -q -O-"
#define SUCKURL "curl -s -m15 " \
"-A \"Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)\""
#define SYMLEN 15
/*
* Alert record
*/
typedef struct
{
char sym[SYMLEN+1];
int alstate;
#define ALERT_DIS 0
#define ALERT_EN 1
#define ALERT_TRIG 2
char var; // b=bid, a=ask, l=last, L=low, H=hi, v=vol
char op; // '<' '>' '='
float val; // trigger
int act; // action
#define ALERT_TERM 1
#define ALERT_EMAIL 2
#define ALERT_EXT 4
} ALERT;
#define NUMALERT 6
/*
* Format of a generic streamer quote record
*/
typedef struct
{
char sym[SYMLEN+1];
float bid;
float ask;
float last;
float close;
unsigned int bid_size;
unsigned int ask_size;
char bid_id;
char ask_id;
long volume;
unsigned int last_size;
long time; // Time in seconds since midnight
float high, low;
char bid_tick;
int delayed;
double scale; // needed by esignal.com
} QUOTE;
/*
* Format of a generic quick quote record
*/
typedef struct
{
char sym[SYMLEN+1];
float bid, ask, last, high, low;
int volume, timetrade, bid_size, ask_size;
char bid_id, ask_id;
float prev_close;
int last_size, last_tick;
char cusip[256];
char fullname[256];
char exchange;
int sharesout;
char description[256];
int annualdiv, divYY, divMM, divDD;
float high52, low52;
int last_eps, cur_eps, year_eps;
} QUICKQUOTE;
/*
* Format of a generic live quote record
*/
typedef struct
{
char sym[SYMLEN+1];
float last;
float close;
} LIVEQUOTE;
/*
* Format of a generic top10 record
*/
typedef struct
{
char sym[SYMLEN+1];
char market;
int type;
enum {
TOP_VOL = 1,
TOP_NETGAIN = 2,
TOP_NETLOSS = 3,
TOP_PCTGAIN = 4,
TOP_PCTLOSS = 5
} fodder_for_gcc_322_1;
int rank;
int volume;
double prev;
double curr;
double change;
} TOP10;
/*
* Format of a generic marketmovers record
*/
typedef struct
{
char sym[SYMLEN+1];
double last; // Last price
double change; // Price change
int time; // Time
int hilo;
enum {
HI_DAILY = 1,
LO_DAILY = 2,
HI_52 = 3,
LO_52 = 4,
NEAR_HI = 5,
NEAR_LO = 6,
NEAR_HI_52 = 7,
NEAR_LO_52 = 8,
} fodder_for_gcc_322_2;
char market; // Market
int count; // Daily count
} MKTMOVER;
/*
* Format of a generic option chain record
*/
typedef struct
{
char sym[SYMLEN+1];
int index;
int count;
char optsym[SYMLEN+1];
int type;
char date[256];
float price;
} OPTCHAIN;
/*
* Format of a generic chart record
*/
/*
* Housekeeping records for each stock
*/
#define COMLEN 128
typedef struct
{
char sym[SYMLEN+1];
int y;
QUOTE old;
QUOTE cur;
int nquotes;
// Time and Sales...
int tsdisplay;
WINDOW *tswin;
WINDOW *tssub;
PANEL *tspanel;
// Alerts...
ALERT *alert[NUMALERT];
int nalert;
int alerting;
// Holdings...
int nshares; // Number of shares
double cost; // Total cost
char comment[COMLEN+1];
// Pressure...
char press_pipe[30];
int press_in;
int press_buy;
int press_sell;
} STOCK;
/*
* This number MUST be kept at 128 or less. It is an abuse of the streamers
* to increase it.
*/
#define NUMSTOCK 128
extern STOCK Stock[NUMSTOCK];
extern int NumStock;
extern int StockCursor;
extern char StockListName[64];
extern char StockList0Name[64];
extern char List0[NUMSTOCK * (SYMLEN+1) + 1];
extern char List0Comments[NUMSTOCK * (COMLEN+1) + 1];
extern int ListNum;
extern RCFILE RcFile[];
extern int CursorX;
extern int Debug;
extern int Reverse;
extern attr_t RevOrBold;
extern int Ungetch; // There is an ungotten keystroke
extern int CursesInitted; // Curses is running
extern int NewStreamer;
extern int ToolMode;
#define TOOL_ONECONN 1
#define TOOL_PERSIST 2
#define TOOL_ROTATE 3
#define TOOL_ONEQUOTE 4
#define TOOL_NEWS 0x10
extern time_t DemoTime;
extern time_t StDemoTime;
extern FILE *WriteFile;
extern FILE *ReadFile;
/*
* Functions
*/
void qfmt_init(void);
char *volfmt6(long val);
char *volfmt6b(long val);
char *dolfmt9(double val);
char *dolfmt11(double val);
char *pctfmt7(double numer, double denom);
char *qfmt(double val);
char *qfmt_etime(time_t dt);
long int lrint(double x); // Should be in math.h, but isn't
void set_timezone(void);
STOCK *add_from_stocklist(char *symbols, int scroll);
STOCK *find_stock(char *sym);
int del_stock(char *sym);
void new_stocklist(STREAMER sr, int num, char *list, char *label);
void copy_quote(QUOTE *qs, QUOTE *qd, QUICKQUOTE *qq, LIVEQUOTE *lq);
void display_ts(void);
int TsDisplayed;
WINDOW *minmaxwin(int minh, int maxh, int anchorbot, int right);
WINDOW *bestwin(int lines);
WINDOW *bestrightwin(int lines, int anchorbot);
void display_title(void);
void display_alert(STOCK *sp, int on);
void display_msg(attr_t attr, char *fmt, ...);
void display_prompt(attr_t attr, char *fmt, ...);
void display_stock_cursor(STOCK *sp, int on);
void display_status(STREAMER sr, int online);
void set_color(int y, int x, int wid, double new, double old,
attr_t ahigh, attr_t aequal, attr_t alow);
void leave_cursor(void);
void external_msg(char *prog, char *sym, char *arg);
void launch_url(char *url_pref, char *sym);
void all_charts_from_list(char *options, char *list);
void all_charts_from_array(char *options);
void add_comments(char *comments);
/*
* Display a quote value
*
* tradetype:
* 0 = nosale
* 1 = regular sale
* 2 = offhours sale???
*/
void display_quote(QUOTE *q, int tradetype);
void display_top10(TOP10 *t10);
void display_mktmover(MKTMOVER *mm);
void display_scrollnews(char *sym, char *link, char *headline,
time_t tim, char *src, int insertat);
void display_livequote(LIVEQUOTE *lqp);
#ifndef max
#define max(A,B) ( ((A) > (B)) ? (A) : (B) )
#endif
#ifndef asizeof
#define asizeof(A) ( sizeof(A)/sizeof(A[0]) )
#endif
/*
* Colors
*/
#define GREENonBG 1 // Is green or blue, depending on BG
#define REDonBG 2
#define YELLOWonBLACK 3
#define GREENonRED 4
#define REDonGREEN 5
#define CYANonBLACK 6
#define REDonWHITE 7
#define BLUEonWHITE 8
#define REDonBLACK 9
#define BLACKonGREEN 10
#define BLACKonRED 11
#define BLACKonYELLOW 12
#define BLACKonCYAN 13
|