1.
아주 우연히 눈에 들어왔습니다. “Island ECN의 소스코드를 공개했다”는 글이었습니다. 이천년대 초반 미국에서 대체거래소(ATS) 및 ECN을 설립하는 붐이 있었습니다. 이 때를 설명한 글입니다.
전자거래시스템의 급속한 성장내에서 ECN(Electronic Communications Network)의 성장은 최근 2-3년 동안 더욱 두드러지고 있다. 이런 완전히 자동화된 시스템을 통해 기관이나 다른 시장참여자들은 다양한 방법으로 전자적으로 거래를 체결시킬 수 있다.
수년간 Nasdaq과 관련한 시장의 증가를 보아온 Day-trading 회사들은 ECNs 설립에 뛰어들었다. Island ECN(대부분 온라인 중개회사인 Datek가 소유), Attain, Archipelago, 및 NexTrade등이 그 예이다. 예외없이, 중개 회사(brokerage firms)들과 다른 전통적인 players는 그들 자신의 그룹을 지지했다. REDIBook은 NYSE의 specialist인 Spear Leeds & Kellogg에 의해 발족되었으며 Strike는 Bear Stearns에 의해 시작되었다.
글 중에 등장한 Island ECN를 이후 Instinet가 2002년 인수하였고 역사속으로 사라졌습니다.
2.
2002년으로부터 10년이 흐른 2012년 Island ECN에 참여했던 분이 그 때 개발하였던 매매체결시스템의 소스코드를 공개하였습니다.
Island ECN 10th Birthday Source Code Release!
무엇보다 놀라운 점은 개발언어가 FoxPro이라는 점입니다. 제가 처음부터 끝까지 프로그램을 개발하여 사용하였던 유일한 언어가 Foxpro입니다. 저는 그저 자료관리 프로그램을 개발하였는데 어떤 이는 방대한 크기의 매매체결시스템을 개발하였습니다.
개발언어가 업무를 제한하는 것이 아니라 개발자의 능력이 개발언어를 제약한다는 생각이 듭니다. 참고로 C++로 개발한 매매체결시스템과 비교해보세요.
이천년대 초반 한국도 ECN이 있었습니다. 한국ECN입니다만 매출부진으로 문을 닫았습니다. 혹 이 때의 소스를 공개할 분이 있을까요? Exture나 Exture+이전에 사용하였던 코스콤 소스로 알고 있습니다만.
위의 사이트에서 소스코드를 확인하실 수 있지만 기록을 위해 저도 옮겨봅니다.
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 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 |
SET TALK OFF SET CURSOR OFF SET SAFETY OFF SET MEMOWIDTH TO 80 CLEAR ALL CLOSE ALL CLEAR CLEAR MACRO && Get rid of F keys typing commands SET HELP OFF && Needed to clear out F1 key too =rand(-1) #define COREDEST "FFFFFFFF0673" gstoredflag = .F. && Are there any messages buffered that could be flushed? #define VERSION "2.40" malertfile = "M:\logs\island2.err" mholdofffile = "M:\island2\holdoff.txt" blanknbuffer="R"+replicate( " " , 200 ) && get BRIGADEN message here #define CORELINELEN 124 #define COREMESSAGELEN 122 #define READPORT "067F" load int99 define window title from 0,0 to 0,scols()-1 COLOR "W/B" NONE define window output from 1,0 to 10,scols()-1 NONE COLOR "W+/N" define window ticker from 12,0 to srows()-1,scols()-1 NONE define window status from 11,0 to 11,scols()-1 COLOR "W+/R" NONE do title do initstatus activate window title activate window status activate window output activate window ticker s = fopen( "ISLAND2.TXT" ) if s <= 0 wait window "COULD NOT FIND ISLAND2.TXT IN CURRENT DIR. RUN RESET." quit endif x = fgets( s ) if "ISLAND2" # x wait window "ACCOUNT IN ISLAND2.TXT DOES NOT MATCH ACCOUNT ENV VAR. RUN RESET." =fclose( s ) quit endif tcount = 0 && For counting random stuff tseq = val( fgets( s ) ) && Next order number tmatch = val( fgets( s ) ) && Next match number tnextdead = val( fgets( s ) ) && Next dead order (zero=none) =fclose( s ) select select(1) use events set order to WHEN tnow = 0 ttoolate = 0 && Count the too late to cancel events gaccept = .F. && Let any orders in? Set by SOD, cleared by EOD gactaccept = .F. && Let ACT orders in? Set by SOD, cleared by EOA geom = .F. && Have we gotten EOM yet? gprinting = .F. && Print incoming messages? go top if eof("EVENTS") tnext = 99999.999 else tnext = WHEN && Time of next event endif select 0 use sources set order to SOURCE select select(1) use island gsx = alltrim( str( date() - {2/6/1996} ) ) gsession = left( "0000000000" , 9-len( gsx ) ) + gsx + "F" s="N"+gsession+"5050" && Open the islandfile for writing Mold on port 5050 call int99 with s if s # "n" && Valid open file? do alert with "InitMold filed with reason >"+s do case case s = "i" sm ="Error opening files in deney-write mode" case s = "j" sm = "a file had a partial line fragment" case s = "k" sm = "not all trailing files are empty" case s = "l" sm = "all files full" otherwise sm = "Unknown error" endcase do alert with sm wait window "Error on ISLAND.OUT or ISLAND2.OUT OPEN:"+s quit endif select island tecount = 0 && Assume worst case, just to make sure ecount is high enough txcount = 0 && Cancels x = "L"+READPORT+" " && Read Island2 requests call int99 with x if x # "l" do alert with "Could not open Command listen!" endif gstatdelay = 0.25 do showstatus gnextstats = seconds() + gstatdelay gmolddelay = 1 && Time between mold heartbeats gmoldheart = seconds() + gmolddelay && Time to send a MOLD heartbeat by doing a FLUSH gmessages = 0 && Number of messages written to the stream gpackets = 0 && Number of packets writtento the stream mdone = .F. do while !mdone tnow = seconds() do while tnow >= tnext if !EVENTS.PROCESSED do swrite with "G" , EVENTS.CODE select EVENTS replace PROCESSED with .T. select ISLAND else ? time()+" Event bypassed:"+ EVENTS.CODE endif do seteventflags with EVENTS.CODE skip 1 in EVENTS if eof("EVENTS") tnext = 99999.999 else tnext = EVENTS.WHEN endif enddo nbuffer = blanknbuffer call int99 with nbuffer if nbuffer = "r" tlenstr = substr( nbuffer , 2 , 5 ) tlen = val( tlenstr ) tmessage = substr( nbuffer , 43 , tlen ) if gprinting ? time()+" >"+tmessage+"<" endif if tmessage = "P" && PING REQUEST tsource = substr( nbuffer ,11 , 8) do pingreply with tsource , tmessage else do processtcpip with tmessage endif else && No pending commands... if gstoredflag do flush gstoredflag = .F. gmoldheart = seconds() + gmolddelay gpackets = gpackets + 1 else if gmoldheart < seconds() do flush gmoldheart = seconds() + gmolddelay endif endif endif if gnextstats <= seconds() do showstatus gnextstats = seconds() + gstatdelay endif lastkey=inkey() if lastkey # 0 activate window output do case case lastkey = asc("~") ? time()+" Quitting..." mdone = .T. case lastkey = asc("@") ? time()+" Copying to island2.dbf" set order to copy to m:\island2\island2 ?? "Done" case lastkey = asc("#") ? time()+" Suspending..." suspend case lastkey = asc("!") ? time()+" ACCEPT="+iif(gaccept,"T","F")+" ACT="+ iif(gactaccept,"T","F") + " EOM="+iif(geom,"T","F")+" NEXT="+str(tnext,9,3)+ " TOO-LATE="+str(ttoolate,6,0)+" COUNT="+str(tcount,9,0) s = "T"+space(60) call int99 with s if s = "t" tbuffered = val( substr(s,26,5) ) ? "MOLD INFO: SESSION="+substr(s,2,10)+" SEQ="+substr(s,12,10)+" SOCKET="+substr(s,22,4)+" BUFFERED="+str(tbuffered,5,0) else ? "Could not get mold info!" tbuffered = 0 endif if gpackets > 0 ? "MESSAGES:"+str(gmessages-tbuffered,12,0)+" PACKETS:"+str(gpackets,12,0)+" ("+str( (gmessages-tbuffered)/ gpackets , 5 , 3 )+")" gmessages = tbuffered gpackets =0 endif case lastkey = asc("%") ? time()+" Shutdown attempt..." do shutdown case lastkey = asc("(") ? time()+" toggled gaccept" gaccept = !gaccept case lastkey = asc("?") ? "@-Copy to island2.DBF ~-Quit !-Status #-Suspend %-ShutDown $-Print incoming" case lastkey = asc("$") if gprinting ? time()+" Printing off" gprinting = .F. else ? time()+" Printing on" gprinting = .T. endif endcase activate window ticker endif enddo && Main Loop activate window output && Final flush to mak sure everything is sent do flush && Close file s = "C" call int99 with s x = "H"+READPORT call int99 with x if x # "h" do alert with "Could not close PingPort!" endif use && Unuse Island && Create fresh waypoint file f = fcreate("ISLAND2.TXT") if f<=0 ? "Could not create ISLAND.TXT!" suspend endif =fputs( f , "ISLAND2" ) && ROLE =fputs( f , str( tseq , 9 , 0 ) ) && Order number =fputs( f , str( tmatch , 9 , 0 ) ) && Match number =fputs( f , str( tnextdead , 9 , 0 ) ) && Next dead order pointer =fclose(f) quit procedure title activate window title SAME clear @ 0,0 SAY " Island2 � Version "+VERSION+" (c)1996 Joshua Levine � Press [?] for help" activate window ticker SAME return proc werror param wcode do case case wcode = "w" return "Error on file write" case wcode = "s" return "Error on nework send" case wcode = "c" return "Invalid message length" case wcode = "d" return "all files full" endcase return "Unknown error" **** write actualy writes a string the the file, steam, and screen proc write parameter wstring wl = len( wstring ) ws="W"+chr(wl)+wstring call int99 with ws gmessages = gmessages + 1 if ws = 'b' gstoredflag = .T. else if ws = "f" gpackets = gpackets + 1 gstoredflag = .F. else activate window output ? time() +" !!!! ERROR ON WRITE!!!!!!" ? ws do alert with "Erorr on write:"+werror(ws) activate window ticker suspend endif endif return *** Write a message **** ACTIONS: **** A - Accept the order was accepted into Island **** B - Booked this order hit the book **** E - Execute the order was executed for this many shares at this price **** X - Cancel this many shares were canceled **** C - Break this order was executed, now broken **** G - Control stock is the control type **** R - Report trade done away but will report/clear through Island **** ON Cancel CONTRA = Reason for cancel ***** MINDICATE = on accept always "D" (legacy) ***** on execute "A"= added liquidity, "R"=Removed liquidity ***** on report "Y" trade report, "N" don't report, "S" step-out ****** mmatch = on accept or book is MINIMUM shares, in execution is match number ****** not defined on cancels, but 0 for now proc mwrite parameter maction,mseq,mshares,mprice,mcontra,mindicate,mmatch,mlocate mwhen = str( tnow , 9 , 3) w = left( mwhen , 5 ) + "," +maction+","+str(mseq,9,0)+","+PORT+","+USER+","+TOKEN+","+BUY_SELL+","+str(mshares,9,0)+","+str(mmatch,9,0)+","+STOCK+","+str(mprice,11,4)+"," +str(mlocate,8,0)+ ", 0,"+SHORT+","+MMID+","+PA+","+mcontra+","+mindicate+","+DISPLAY+","+right(mwhen,3)+","+CLEARING+",D" do write with w return ****** Swrite writes a status message that doesnot concern an order, Like G-Good morning proc swrite param maction , mcode mwhen = str( tnow , 9 , 3) xcode = left( padr( mcode , 3) , 3 ) w = left( mwhen , 5 ) +","+maction+","+" 0"+", , , , , 0, 0,*"+xcode+" , 0.0000,00000000, 0, , , , , , ,"+right( mwhen , 3 )+", , " do write with w return ****** Enter order adds the audit, tries for a match, and if it don't work, books it. ****** Enter order assumes ostock and obuy_sell are the right length. ****** Also assumes that buy_sell has aready been checked to be B or S. ****** Also assumes that the token is no already used proc enter2order parameter oport,ouser,otoken,obuy_sell,oshares,ostock,oprice,otif,oshort,ommid,opa,odisplay,omin,oclearing,oflags if odisplay = "P" obasefirm = ouser else obasefirm = "####" endif && Get the working record if tnextdead > 0 tlocate = tnextdead goto tnextdead tnextdead = SEQ else insert into ISLAND (LEAVES) values (0) && Keep it out of the indexes for now tlocate = recno() endif tseq = tseq + 1 awhen = str( tnow , 9 , 3) oleaves = oshares ofilled = 0 aflag = .f. && have we written the "A" message yet? if obuy_sell = "B" && Buy order... set order to SSEEK do case case omin > 1 && Minimum quantity specified? *** if the min is bigger than the size, set it to the size if omin > oshares mmin = oshares else mmin = omin endif *** First prescan to see if we have enough size to fill it if seek( ostock ) scan while mmin > 0 .and. ostock = STOCK .and. BUY_SELL = "S" .and. oprice >= PRICE mmin = mmin - LEAVES endscan endif if mmin <= 0 *** There were at least enough to fill the minimum quantity mmax = oshares else *** Not enough to fill the min, so fill none mmax = 0 endif case odisplay = "R" .or. odisplay = "P" && Is this a round-lot only order? mmax = 0 *** Prescan to find the number of a shares available if seek( ostock ) scan while mmax <= oshares .and. ostock = STOCK .and. BUY_SELL = "S" .and. oprice >= PRICE .and. obasefirm # MMID mmax = mmax + LEAVES endscan endif if mmax >= oshares *** Max out with the number of shares specified mmax = oshares endif *** Round down to nearest round lot wihtout using floating point mmax = val( substr( str( mmax , 6, 0 ) , 1 ,4 ) + "00" ) otherwise mmax = oshares endcase do while mmax > 0 .and. seek( ostock ) .and. oprice >= PRICE if !aflag w = left( awhen , 5 ) +",A," +str(tseq,9,0) +"," +oport+"," +ouser +"," +otoken +"," +obuy_sell +", " +str(oshares,6,0) +", " +str(omin,6,0) +"," +ostock +"," +str(oprice,11,4) +"," +str(tlocate,8,0) +"," +str(otif,5,0) +"," +oshort +"," +ommid +"," +opa+","+oflags+", ," +odisplay +"," +right(awhen,3) +"," +oclearing+",D" do write with w aflag = .T. endif tecount = tecount + 1 eshares = min( LEAVES , mmax ) oleaves = oleaves - eshares mmax = mmax - eshares ofilled = ofilled + eshares tmatch = tmatch + 1 w = left( awhen , 5 ) +",E," +str( SEQ ,9,0) +"," +PORT +"," +USER +"," +TOKEN +"," +BUY_SELL +", " +str(eshares,6,0) +"," +str(tmatch,9,0) +"," +ostock +"," +str(PRICE,11,4) +"," +str( recno() ,8,0)+ ", 0," +SHORT +"," +MMID +"," +PA+"," +ommid+",A," +DISPLAY +"," +right(awhen,3) +"," +CLEARING+",D" do write with w w = left( awhen , 5 ) +",E," +str(tseq,9,0) +"," +oport+"," +ouser +"," +otoken +"," +obuy_sell +", " +str(eshares,6,0) +"," +str(tmatch,9,0) +"," +ostock +"," +str(PRICE,11,4) +"," +str(tlocate,8,0)+", 0," +oshort +"," +ommid +"," +opa+","+MMID+",R," +odisplay +"," +right(awhen,3) +"," +oclearing+",D" do write with w dleaves = LEAVES - eshares if dleaves <= 0 && Dead record? replace LEAVES with 0 , SEQ with tnextdead tnextdead = recno() else replace LEAVES with dleaves , FILLED with FILLED + eshares endif enddo else && sell order.. set order to BSEEK do case case omin > 1 && Minimum quantity specified? *** if the min is bigger than the size, set it to the size if omin > oshares mmin = oshares else mmin = omin endif *** First prescan to see if we have enough size to fill it if seek( ostock ) scan while mmin > 0 .and. ostock = STOCK .and. BUY_SELL = "B" .and. oprice <= PRICE mmin = mmin - LEAVES endscan endif if mmin <= 0 mmax = oshares else mmax = 0 endif case odisplay = "R" .or. odisplay = "P" && Is this a round-lot only order? mmax = 0 *** Prescan to find the number of a shares available if seek( ostock ) scan while mmax <= oshares .and. ostock = STOCK .and. BUY_SELL = "B" .and. oprice <= PRICE .and. obasefirm # MMID mmax = mmax + LEAVES endscan endif if mmax >= oshares mmax = oshares endif *** Round down to nearest round lot wihtout using floating point mmax = val( substr( str( mmax , 6, 0 ) , 1 ,4 ) + "00" ) otherwise mmax = oshares endcase do while mmax > 0 .and. seek( ostock ) .and. oprice <= PRICE if !aflag w = left( awhen , 5 ) +",A," +str(tseq,9,0) +"," +oport+"," +ouser +"," +otoken +"," +obuy_sell +", " +str(oshares,6,0) +", " +str(omin,6,0) +"," +ostock +"," +str(oprice,11,4) +"," +str(tlocate,8,0) +","+str(otif,5,0) +"," +oshort +"," +ommid +"," +opa+","+oflags+", ," +odisplay +"," +right(awhen,3) +"," +oclearing+",D" do write with w aflag = .T. endif tecount = tecount + 1 eshares = min( LEAVES , mmax ) oleaves = oleaves - eshares mmax = mmax - eshares ofilled = ofilled + eshares tmatch = tmatch + 1 w = left( awhen , 5 ) +",E," +str( SEQ ,9,0) +"," +PORT +"," +USER +"," +TOKEN +"," +BUY_SELL +", " +str(eshares,6,0) +"," +str(tmatch,9,0) +"," +ostock +"," +str(PRICE,11,4) +"," +str( recno() ,8,0) +", 0," +SHORT +"," +MMID +"," +PA+"," +ommid+",A," +DISPLAY +"," +right(awhen,3) +"," +CLEARING+",D" do write with w w = left( awhen , 5 ) +",E," +str(tseq,9,0) +"," +oport+"," +ouser +"," +otoken +"," +obuy_sell +", " +str(eshares,6,0) +"," +str(tmatch,9,0) +"," +ostock +"," +str(PRICE,11,4) +"," +str(tlocate,8,0) +", 0," +oshort +"," +ommid +"," +opa+","+MMID+",R," +odisplay +"," +right(awhen,3) +"," +oclearing+",D" do write with w dleaves = LEAVES - eshares if dleaves <= 0 && Dead record? replace LEAVES with 0 , SEQ with tnextdead tnextdead = recno() else replace LEAVES with dleaves , FILLED with FILLED + eshares endif enddo endif if oleaves > 0 && any non-executed shares left? if otif = 0 && Fill or kill, so cancel leaves if !aflag && did we not make an A message yet? w = left( awhen , 5 ) +",A," +str(tseq,9,0) +"," +oport+"," +ouser +"," +otoken +"," +obuy_sell +", " +str(oshares,6,0) +", " +str(omin,6,0) +"," +ostock +"," +str(oprice,11,4) +"," +str(tlocate,8,0)+ "," +str(otif,5,0) +"," +oshort +"," +ommid +"," +opa+","+oflags+", ," +odisplay +"," +right(awhen,3) +"," +oclearing+",D" do write with w endif w = left( awhen , 5 ) +",X," +str(tseq,9,0) +"," +oport+"," +ouser +"," +otoken +"," +obuy_sell +", " +str(oleaves,6,0) +", 0," +ostock +"," +str(oprice,11,4) +"," +str(tlocate,8,0)+ ", 0," +oshort +"," +ommid +"," +opa+",#IOC, ," +odisplay +"," +right(awhen,3) +"," +oclearing+",D" do write with w oleaves = 0 else if !aflag && did we not make an A message yet? w = left( awhen , 5 ) +",A," +str(tseq,9,0) +"," +oport+"," +ouser +"," +otoken +"," +obuy_sell +", " +str(oshares,6,0) +", " +str(omin,6,0) +"," +ostock +"," +str(oprice,11,4) +"," +str(tlocate,8,0) +"," +str(otif,5,0) +"," +oshort +"," +ommid +"," +opa+","+oflags+",B," +odisplay +"," +right(awhen,3) +"," +oclearing+",D" else w = left( awhen , 5 ) +",B," +str(tseq,9,0) +"," +oport+"," +ouser +"," +otoken +"," +obuy_sell +", " +str(oleaves,6,0) +", 0," +ostock +"," +str(oprice,11,4) +"," +str(tlocate,8,0) +"," +str(otif,5,0) +"," +oshort +"," +ommid +"," +opa+", , ," +odisplay +"," +right(awhen,3) +"," +oclearing+",D" endif do write with w endif && otif == 0 endif && oleaves > 0 if oleaves > 0 && Still open? goto tlocate replace ; PORT with oport,; USER with ouser,; TOKEN with otoken,; BUY_SELL with obuy_sell,; LEAVES with oleaves,; STOCK with ostock,; PRICE with oprice,; SHORT with oshort,; MMID with ommid,; PA with opa,; DISPLAY with odisplay,; CLEARING with oclearing,; FILLED with ofilled,; SEQ with tseq else && leaves = 0 (add current order to deadlist) goto tlocate replace SEQ with tnextdead tnextdead = recno() endif && oleaves > 0 return ****** Enter Report adds a type R line to the file ****** Enter order assumes ostock and obuy_sell are the right length. proc enter2report parameter oport,ouser,otoken,obuy_sell,oshares,ostock,oprice,oshort,ommid,opa,oreport,oclearing,ocontra tseq = tseq + 1 tmatch = tmatch + 1 mwhen = str( tnow , 9 , 3) w = left( mwhen , 5 ) + ",R,"+str(tseq,9,0) +"," +oPORT+"," +oUSER+"," +oTOKEN+"," +oBUY_SELL +", "+str(oshares,6,0)+","+str(tmatch,9,0)+"," +oSTOCK+","+str(oprice,11,4)+",00000000, 0,"+oSHORT+","+oMMID+","+oPA+","+ocontra+","+oreport+",R,"+right(mwhen,3)+","+oCLEARING+",D" do write with w return ****** Enter Reject adds a type J line to the file proc enter2reject parameter oport,ouser,otoken,otype,oreason tseq = tseq + 1 *** Leaves MUST be 0 or it might be included in the match! mwhen = str( tnow , 9 , 3) w = left( mwhen , 5 ) + ",J," +str(tseq,9,0) +"," +oport+"," +ouser +"," +otoken+"," +otype+", 0, 0, , 0.0000,00000000, 0, , , , ," +oreason +",N,"+right(mwhen,3)+", ,D" do write with w return ****** Enter break adds a type C line to the file proc enterbreak parameter oseq, oport , ouser, otoken, obuy_sell, oshares, omatch, ostock, oprice, ommid, oreason, omisc, oclearing , oshort if oseq > tseq .or. oseq < 1 ? time()+" Bad SEQ in Break! OSEQ="+str(oseq,9,0)+" RECS="+str( tseq, 9,0) return endif if oshares <= 0 ? time()+" Jerk boy BREAK zero shares SEQ="+str(oseq,9,0) return endif if oprice <= 0 ? time()+" Jerk boy BREAK zero price SEQ="+str(oseq,9,0) return endif if ! omisc $ "AR" ? time()+" Invalid A/R BREAK MISC="+omisc+" SEQ="+str(oseq,9,0) return endif mwhen = str( tnow , 9 , 3) w = left( mwhen , 5 ) + ",C,"+str(oseq,9,0) +"," +oPORT+"," +oUSER+"," +oTOKEN+"," +oBUY_SELL +", "+str(oshares,6,0)+","+str(omatch,9,0)+"," +oSTOCK+","+str(oprice,11,4)+",00000000, 0,"+oshort+","+oMMID+", ,"+oreason +","+omisc+", ,"+right(mwhen,3)+","+oCLEARING+",D" do write with w return ****** Enter maint adds a type M line to the file *** SHORTTYPE ***** N - No short sale checks ***** B - Bidtick test ***** L - Lasttrade test *** BLOCKSUB - Block subscriber only orders? ***** B - Block ***** N - No block *** CENTER ***** Q - NASDAQ ***** L - LISTED proc entermaint parameter oport,ouser,otoken,ostock,oshorttype,oblocksub,ocenter,omisc if ! oshorttype $ "NBL" ? time()+" Bad SHORTTYPE="+oshorttype+" STOCK="+ostock return endif if !oblocksub $ "BN" ? time()+" Bad BLOCKSUB="+oblocksub+" STOCK="+ostock return endif if !ocenter $ "QL" ? time()+" Bad CENTER="+ocenter+" STOCK="+ostock return endif if len( omisc ) # 4 ? time()+" Bad omisc len!"+omisc return endif for eml = 1 to 4 emb = substr( omisc , eml , 1 ) if !isalpha( emb ) .and. emb # " " ? time()+" Bad omisc letter!"+omisc return endif endfor awhen = str( tnow , 9 , 3 ) w = left( awhen , 5 ) +",M, 0,"+oport+","+ouser+","+otoken+",S, 0, 0," +ostock +", 0.0000,00000000, 0,"+oshorttype+", , ,"+omisc+","+ocenter+","+oblocksub+"," +right(awhen,3) +", , " do write with w return *** STATE - Trading state ***** T - Trading ***** H - Halted proc enterstate parameter oport,ouser,otoken,ostock,ostate if !ostate $ "TH" ? time()+" Bad STATE="+ostate+" STOCK="+ostock return endif awhen = str( tnow , 9 , 3 ) w = left( awhen , 5 ) +",M, 0,"+oport+","+ouser+","+otoken+",T, 0, 0," +ostock +", 0.0000,00000000, 0, , , , ,"+ostate+", ," +right(awhen,3) +", , " do write with w return *** Enter account configures an OUCH account proc enteraccount parameter oaccount,opassword,otest,otrusted, othresh, osscheck,oiflag, odefault if !otest$"TN" ? time()+" Bad TEST flag in enteraccount:"+otest return endif if !otrusted$"TN" ? time()+" Bad TRUSTED flag in enteraccount:"+otrusted return endif if !osscheck$"YN" ? time()+" Bad SSCHECK flag in enteraccount:"+osscheck return endif if !oiflag$"IN" ? time()+" Bad IFLAG flag in enteraccount:"+oiflag return endif if len( opassword ) # 10 ? time()+" Bad opassword len!"+opassword return endif for eml = 1 to 10 emb = substr( opassword , eml , 1 ) if !isalpha( emb ) .and. !isdigit( emb) .and. emb # " " .and. emb # "!" .and. emb # "#" ? time()+" Bad opassword letter!"+opassword+":"+str(eml) return endif endfor if len( oaccount ) # 6 ? time()+" Bad oaccount len!"+oaccount return endif for eml = 1 to 6 emb = substr( oaccount , eml , 1 ) if !isalpha( emb ) .and. !isdigit( emb ) .and. emb # " " ? time()+" Bad oaccount letter!"+oaccount+":"+str(eml) return endif endfor if len( odefault ) # 4 ? time()+" Bad odefault len!"+odefault return endif for eml = 1 to 4 emb = substr( odefault , eml , 1 ) if !isalpha( emb ) .and. !isdigit( emb) .and. emb # " " ? time()+" Bad odefault letter!"+odefault +":"+str(eml) return endif endfor awhen = str( tnow , 9 , 3 ) w = left( awhen , 5 ) +",M, 0,"+oaccount+", ,"+opassword+",A,"+str(othresh,9,0)+", 0, , 0.0000,00000000, 0,"+osscheck+","+odefault +", ,"+otest+ " "+ otrusted +" ,"+oiflag+", ," +right(awhen,3) +", , " do write with w return *** Enter firm configures an OUCH account for clearing proc enterfirm parameter oaccount,ommid,oclearing if !oclearing$"AIQRN" ? time()+" Bad clearing in enterfirm:"+oclearing return endif if len( ommid ) # 4 ? time()+" Bad ommid len!"+ommid return endif for eml = 1 to 4 emb = substr( ommid , eml , 1 ) if !isalpha( emb ) .and. !isdigit( emb) .and. emb # " " ? time()+" Bad ommid letter!"+ommid+":"+str(eml) return endif endfor if len( oaccount ) # 6 ? time()+" Bad oaccount len!"+oaccount return endif for eml = 1 to 6 emb = substr( oaccount , eml , 1 ) if !isalpha( emb ) .and. !isdigit( emb ) .and. emb # " " ? time()+" Bad oaccount letter!"+oaccount+":"+str(eml) return endif endfor awhen = str( tnow , 9 , 3 ) w = left( awhen , 5 ) +",M, 0,"+oaccount+", , ,F, 0, 0, , 0.0000,00000000, 0, ,"+ ommid +", , , , ," +right(awhen,3) +","+oclearing+", " do write with w return proc new2cancel parameter olocate,oseq,oshares,ocontra && Contra indeicates reason for cancel if olocate <= 0 .or. olocate > reccount() ? time()+" CANCEL LOCATE OUT OF BOUNDS " +str( olocate , 8 , 0)+ " SEQ=" +str(oseq,8,0) return 0 endif goto olocate if oseq # SEQ *** ? time()+" CANCEL OUT OF DATE " +str( olocate , 8 , 0)+ " SEQ=" +str(oseq,8,0) ttoolate = ttoolate + 1 return 0 endif if LEAVES <= oshares ttoolate = ttoolate + 1 return endif xshares = LEAVES - oshares do mwrite with "X", SEQ , xshares , PRICE , ocontra , " " , 0 , recno() txcount = txcount + 1 dleaves = LEAVES - xshares if dleaves <=0 && Must set LEAVES to zero to pull order from indexes replace LEAVES with 0 , SEQ with tnextdead tnextdead = recno() else replace LEAVES with dleaves endif return ****** Cancel Order takes a locator and a SEQ number ****** passed shares in new intedned order size ****** returns number of shares canceled and leaves record pointer on order canceled. proc i2cancel parameter olocate,oseq,oshares,ocontra && Contra indeicates reason for cancel if olocate <= 0 .or. olocate > reccount() ? time()+" CANCEL LOCATE OUT OF BOUNDS " +str( olocate , 8 , 0)+ " SEQ=" +str(oseq,8,0) return 0 endif goto olocate if oseq # SEQ *** ? time()+" CANCEL OUT OF DATE " +str( olocate , 8 , 0)+ " SEQ=" +str(oseq,8,0) ttoolate = ttoolate + 1 return 0 endif msize = LEAVES + FILLED && Current size of order if oshares >= msize *** ? time()+" INTENEDED CANCEL BIGGER THAN ORDER SHARES="+str( oshares, 6 , 0 )+" REASON="+ocontra return 0 endif xshares = msize - oshares && HOwmany do we have to cancel to get from current size to new size? if xshares > LEAVES && Don't cancel more than are open xshares = LEAVES endif if xshares = 0 ttoolate = ttoolate + 1 return 0 endif do mwrite with "X", SEQ , xshares , PRICE , ocontra , " " , 0 , recno() txcount = txcount + 1 dleaves = LEAVES - xshares if dleaves <=0 && Must set LEAVES to zero to pull order from indexes replace LEAVES with 0 , SEQ with tnextdead tnextdead = recno() else replace LEAVES with dleaves endif return xshares proc initstatus activate window status @ 0,1 SAY "Orders:" @ 0,27 SAY "Executions:" @ 0,52 SAY "Cancels:" activate window ticker return proc showstatus activate window status @ 0,11 SAY tseq PICTURE "##,###,###" @ 0,38 SAY tmatch PICTURE "##,###,###" @ 0,60 SAY txcount PICTURE "##,###,###" activate window ticker return proc processtcpip param ptm tcommand = substr( ptm , 1 , 1 ) if geom ? time()+" Command recieved after EOM:"+tcommand return endif do case case tcommand = "H" tport = substr( ptm , 2 , 6 ) if !seek( tport , "SOURCES" ) insert into SOURCES values ( tport , 1 ) endif tinseq = val(substr( ptm , 73, 9 ) ) if tinseq # SOURCES.SEQ if tinseq < SOURCES.SEQ *** ? time()+" Duped inseq "+tport+" Expected:"+str( SOURCES.SEQ , 9, 0)+" Got:"+str( tinseq , 9 , 0 ) return endif do alert with "Gapped inseq "+tport+" Expected:"+str( SOURCES.SEQ , 9, 0)+" Got:"+str( tinseq , 9 , 0 ) endif tuser = substr( ptm , 8 , 4 ) ttoken = substr( ptm , 12 , 10 ) tbuy_sell = substr( ptm , 22 , 1 ) tshares = val( substr( ptm , 23 , 6 ) ) tmin = val( substr( ptm , 29 , 6 ) ) tstock = substr( ptm , 35 , 6 ) tprice = val( substr( ptm , 41 , 11 ) ) ttif = val( substr( ptm , 52 , 5 ) ) tdisplay = substr( ptm , 57 , 1 ) tshort = substr( ptm , 58 , 1 ) tpa = substr( ptm , 59 , 1 ) tmmid = substr( ptm , 60 , 4 ) tclearing = substr( ptm , 64 , 1 ) tflags = substr( ptm , 65 , 4 ) if tbuy_sell = "B" xshort = " " else if tbuy_sell # "S" ? time()+" Bad buy_sell "+tbuy_sell+" port="+tport return endif do case case tshort = "Y" xshort = "S" case tshort = "S" xshort = "S" case tshort = "N" xshort = "L" case tshort = "L" xshort = "L" case tshort = "E" xshort = "E" otherwise xshort = "?" endcase endif if tshares <= 0 ? time()+" Jerk boy zero shares TOKEN " +tport+"-" +tuser+"-" +ttoken return endif if tshares >= 1000000 ? time()+" Jerk boy million shares TOKEN " +tport+"-" +tuser+"-" +ttoken return endif if tprice <= 0 ? time()+" Jerk boy zero price TOKEN " +tport+"-" +tuser+"-" +ttoken return endif if tprice >= 1000000 ? time()+" Jerk boy million price TOKEN " +tport+"-" +tuser+"-" +ttoken return endif if ! tclearing $ "AIQOR" ? time()+" Jerk boy strange clearing >" +tclearing+"< TOKEN " +tport+"-" +tuser+"-" +ttoken return endif if ! tdisplay $ "YNLRP" ? time()+" Jerk boy strange display >" +tdisplay+"< TOKEN " +tport+"-" +tuser+"-" +ttoken return endif if (tdisplay = "R" .or. tdisplay = "P" ) .and. ttif > 0 ? time()+" Jerk boy R or P or Q display with nonzero tif >" +str(ttif,5,0)+"< TOKEN " +tport+"-"+tuser+"-"+ttoken return endif if !gaccept ? time()+" Trade ignored outside SOD-EOD time "+tport+"-" +tuser+"-" +ttoken return endif if tclearing = "A" if !gactaccept ? time()+" ACT trade ignored outside ACT time " +tport+"-" +tuser+"-" +ttoken return endif endif select SOURCES replace SEQ with tinseq + 1 select ISLAND do enter2order with tport , tuser , ttoken , tbuy_sell , tshares , tstock , tprice , ttif , xshort , tmmid , tpa , tdisplay , tmin , tclearing , tflags case tcommand = "L" tolocate = val( substr( ptm , 2 , 8 ) ) toseq = val( substr( ptm , 10 , 9 ) ) tshares = val( substr( ptm , 19 , 6 ) ) treason = substr( ptm , 25 , 1 ) do case case treason = "A" xreason = "#USR" case treason = "B" xreason = "#TME" case treason = "C" xreason = "#HLT" case treason = "D" xreason = "#SUP" case treason = "E" xreason = "#DNT" case treason = "F" xreason = "#MBL" otherwise xreason = "#USR" endcase do new2cancel with tolocate , toseq , tshares , xreason case tcommand = "I" tport = substr( ptm , 2 , 6 ) if !seek( tport , "SOURCES" ) insert into SOURCES values ( tport , 1 ) endif tinseq = val( substr( ptm , 24 , 9 ) ) if tinseq # SOURCES.SEQ if tinseq < SOURCES.SEQ *** ? time()+" Duped REJ inseq "+tport+" Expected:"+str( SOURCES.SEQ , 9, 0)+" Got:"+str( tinseq , 9 , 0 ) return endif do alert with "Gapped REJ inseq "+tport+" Expected:"+str( SOURCES.SEQ , 9, 0)+" Got:"+str( tinseq , 9 , 0 ) endif tuser = substr( ptm , 8 , 4 ) ttoken = substr( ptm , 12 , 10 ) ttype = substr( ptm , 22 , 1 ) treason = substr( ptm , 23 , 1 ) do enter2reject with tport , tuser , ttoken , ttype , treason select SOURCES replace SEQ with tinseq + 1 select ISLAND case tcommand = "Z" tolocate = val( substr( ptm , 2 , 8 ) ) toseq = val( substr( ptm , 10 , 9 ) ) tshares = val( substr( ptm , 19 , 6 ) ) treason = substr( ptm , 25 , 1 ) do case case treason = "A" xreason = "#USR" case treason = "B" xreason = "#TME" case treason = "C" xreason = "#HLT" case treason = "D" xreason = "#SUP" case treason = "E" xreason = "#DNT" case treason = "F" xreason = "#MBL" otherwise xreason = "#USR" endcase =i2cancel( tolocate , toseq , tshares , xreason ) case tcommand = "S" tport = substr( ptm , 2 , 6 ) if !seek( tport , "SOURCES" ) insert into SOURCES values ( tport , 1 ) endif tinseq = val(substr( ptm , 58 , 9 ) ) if tinseq # SOURCES.SEQ if tinseq < SOURCES.SEQ *** ? time()+" Duped REP inseq "+tport+" Expected:"+str( SOURCES.SEQ , 9, 0)+" Got:"+str( tinseq , 9 , 0 ) return endif do alert with "Gapped REP inseq "+tport+" Expected:"+str( SOURCES.SEQ , 9, 0)+" Got:"+str( tinseq , 9 , 0 ) endif tuser = substr( ptm , 8 , 4 ) ttoken = substr( ptm , 12 , 10 ) tbuy_sell = substr( ptm , 22 , 1 ) tshares = val( substr( ptm , 23 , 6 ) ) tstock = substr( ptm , 29 , 6 ) tprice = val( substr( ptm , 35 , 11 ) ) treport = substr( ptm , 46 , 1 ) tshort = substr( ptm , 47 , 1 ) tpa = substr( ptm , 48 , 1 ) tmmid = substr( ptm , 49 , 4 ) tclearing = substr( ptm , 53 , 1 ) tcontra = substr( ptm , 54 , 4 ) if ! treport $ "YNS" ? time()+" Jerk boy REPORT code TOKEN " +tport return endif if tshares <= 0 ? time()+" Jerk boy REPORT zero shares TOKEN "+tport+"-"+tuser+"-"+ttoken return endif if tshares >= 1000000 ? "Jerk boy REPORT million shares TOKEN "+tport+"-"+tuser+"-"+ttoken return endif if tprice <= 0 ? "Jerk boy REPORT zero price TOKEN "+tport+"-"+tuser+"-"+ttoken return endif if tprice >= 1000000 ? "Jerk boy REPORT million price TOKEN "+tport+"-"+tuser+"-"+ttoken return endif if ! tclearing $ "ABSIQORN" ? "Jerk boy REPORT strange clearing >"+tclearing+"< TOKEN "+tport+"-"+tuser+"-"+ttoken return endif if !gaccept ? "Report ignored outside SOD-EOD time "+tport+"-"+tuser+"-"+ttoken return endif if tclearing = "A" if !gactaccept ? "ACT trade REPORT ignored outside ACT time "+tport+"-"+tuser+"-"+ttoken return endif endif do enter2report with tport , tuser , ttoken , tbuy_sell , tshares , tstock , tprice , tshort , tmmid , tpa , treport , tclearing , tcontra select SOURCES replace SEQ with tinseq + 1 select ISLAND case tcommand = "D" tcseq = val( substr( ptm , 2 , 9 ) ) tcport = substr( ptm , 11 , 6 ) tcuser = substr( ptm , 17 , 4 ) tctoken = substr( ptm , 21 , 10 ) tcbuy_sell = substr( ptm , 31 , 1 ) tcshares = val( substr( ptm , 32 , 6 ) ) tcmatch = val( substr( ptm , 38 , 9 ) ) tcstock = substr( ptm , 47 , 6 ) tcprice = val( substr( ptm , 53 , 11 ) ) tcmmid = substr( ptm , 64 , 4 ) tcmisc = substr( ptm , 68 , 1 ) tcreason = substr( ptm , 69 , 1 ) tcclearing = substr( ptm , 70 , 1 ) do case case tcreason = "A" xreason = "#ERR" case tcreason = "B" xreason = "#CON" case tcreason = "C" xreason = "#SUP" case tcreason = "D" xreason = "#SYS" case tcreason = "E" xreason = "#EXT" otherwise ? time()+" Unvalid break reason = "+tcreason return endcase do case case tcbuy_sell = "B" xbuy_sell = "B" xshort = " " case tcbuy_sell = "S" xbuy_sell = "S" xshort = "L" case tcbuy_sell = "T" xbuy_sell = "S" xshort = "S" case tcbuy_sell = "E" xbuy_sell = "S" xshort = "E" otherwise ? time()+" Unvalid break buy_sell = "+tcbuy_sell return endcase do enterbreak with tcseq , tcport, tcuser, tctoken, xbuy_sell, tcshares , tcmatch ,tcstock , tcprice , tcmmid , xreason , tcmisc , tcclearing , xshort case tcommand = "M" tctype = substr( ptm , 2 , 1 ) do case case tctype = "S" && Stock maintence tport = substr( ptm , 3 , 6 ) tuser = substr( ptm , 9 , 4 ) ttoken = substr( ptm , 13 , 10 ) tcstock = substr( ptm , 23 , 6 ) tcshorttype = substr( ptm , 29 , 1 ) tcblocksub = substr( ptm , 30 , 1 ) tccenter = substr( ptm , 31 , 1 ) tcmisc = substr( ptm , 32 , 4 ) do entermaint with tport, tuser, ttoken, tcstock , tcshorttype , tcblocksub , tccenter , tcmisc case tctype = "A" && Account settings taccount = substr( ptm , 3 , 6 ) tpassword = substr( ptm , 9 , 10 ) ttest = substr( ptm , 19 , 1 ) ttrusted = substr( ptm , 20 , 1 ) tthresh = val( substr( ptm , 21 , 6 ) ) tsscheck = substr( ptm , 27 , 1 ) tiflag = substr( ptm , 28 , 1 ) tdefault = substr( ptm , 29 , 4 ) do enteraccount with taccount, tpassword, ttest , ttrusted , tthresh, tsscheck, tiflag, tdefault case tctype = "F" && Account settings taccount = substr( ptm , 3 , 6 ) tmmid = substr( ptm , 9 , 4 ) tclearing = substr( ptm , 13 , 1 ) do enterfirm with taccount, tmmid, tclearing case tctype = "T" && Stock state tport = substr( ptm , 3 , 6 ) tuser = substr( ptm , 9 , 4 ) ttoken = substr( ptm , 13 , 10 ) tcstock = substr( ptm , 23 , 6 ) tcstate = substr( ptm , 29 , 1 ) do enterstate with tport, tuser, ttoken, tcstock , tcstate otherwise ? time()+" Unvalid maint reason = "+tctype endcase otherwise do alert with "Unknown command"+ptm endcase return proc sendeos s = "E" call int99 with s if s # "f" .and. s # "b" activate window output ? time() +" !!!! ERROR ON EOS WRITE!!!!!!" ? ws activate window ticker suspend endif return proc flush s = "F" call int99 with s if s # "f" ? "!!!!ERROR ON FLUSH!!!!" do alert with "Error on flush:"+werror(s) suspend endif gstoredflag = .F. return proc shutdown do alert with "Shutdown initiated" if !geom && Shutting down too early? Just in case... wait window "Can't end day, EOM has not happened yet!" nowait do alert with "Ending day attempted before EOM time!" return endif sdk = chr( (rand() * 25) + asc("A") ) wait window "Initiate Shutdown by pressing ["+sdk+"] within 10 seconds" to sdh timeout 10 if upper( sdh ) # sdk wait window "Shutdown Aborted" nowait do alert with "Shutdown aborted" return endif wait window "Confirm Shutdown by pressing the magic key within 10 seconds" to sdh timeout 10 if upper( sdh ) # "M" wait window "Inccorect Shutdown confirmation" nowait do alert with "Incorrect shutdown magic key" return endif do alert with "Shutdown confirmed" if file( mholdofffile ) ? "Holdoff file exists! Escalate!" suspend else sdf = fcreate( mholdofffile ) =fputs( sdf , "Stop in the name of love!") =fclose( sdf ) endif if !file( mholdofffile ) wait window "No HOLDOFF file created, aborting Shutdown" nowait do alert with "No HOLDOFF file created, aborting shutdown" return endif wait window "Shutting down..." nowait do swrite with "N" , "" wait window "Shutting down... 3" timeout 1 do swrite with "N" , "" wait window "Shutting down... 2" timeout 1 do swrite with "N" , "" wait window "Shutting down... 1" timeout 1 do flush wait window "Flushing..." timeout 1 do sendeos do flush wait window "Sending End of Session... 3" timeout 1 do flush wait window "Sending End of Session... 2" timeout 1 do flush wait window "Sending End of Session... 1" timeout 1 do flush wait window "Sending End of Session... 0" timeout 1 do flush mdone = .T. zap return proc pingreply param preply , ptm ptoken = substr( ptm , 2 , 12 ) pport = substr( ptm , 14 , 4 ) x = "R"+ptoken+str( tseq ,9,0)+str( tmatch ,9,0)+str(0,9,0) s = "S"+chr(len(x))+ preply+pport+ x call int99 with s return proc seteventflags param secode do case case secode = "SOD" gaccept = .T. gactaccept = .T. case secode = "EOA" gactaccept = .F. case secode = "EOD" gaccept = .F. case secode = "EOM" geom = .T. endcase return proc alert parameter s xs = dtoc(date())+" "+time() +"-"+ s ? xs IF FILE( malertfile ) && Does file exist? errfile = FOPEN( malertfile ,12) && If so, open read/write ELSE errfile = FCREATE( malertfile ) && If not create it ENDIF IF errfile < 0 && Check for error opening file WAIT 'Cannot open or create output file' WINDOW NOWAIT ELSE && If no error, write to file =fseek( errfile, 0 , 2 ) =FWRITE(errfile, xs + chr(13) + chr(10) ) ENDIF =FCLOSE(errfile) && Close file * ? chr(07)+chr(07)+chr(07)+chr(07) return |