• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

## Recommended Posts

Hello, I was wondering if there was a way that I can buy and sell stocks through some interface in say my C/C++ code? The only way I can think of so far is to connect to a brokerage componie''s website and pretend that your C/C++ code is the browser and it is buying/selling stock as if a human were interacting. This seems like it would be fairly complex and probobly not the easiest method. Do you guys know of a better way to do this? Thanks. Also, Is there an easy way to check prices of stocks (current prices is a must... say, somewhere around 5mins... 10mins max) It would be nice if there was a library that I could use that someone has writen where I can call a function, float GetStockPrice(string abrv), and get the current price. If anyone has writen such thing or know where I can get one, that would be sweet! Thanks again! Dwiel

##### Share on other sites
I don''t think you can just sell stocks with code, you need a broker (which may or may not be simulatable), and, more importantly, someone to buy it from you...

##### Share on other sites
There are firms that allow you to make transactions online. I was simply windering if there was an easy way to interface to one of these web broker''s websites. I would rather not have to emulate a person by ''pretending'' that my application is a web browser that fills in it''s own data into the fields such as which stock to buy/sell, for how much, etc. Everything that a person who was doing this online would type in and click. It would be nice if there was an easier, more robust way to do this. I don''t think that parsing a broker''s web page is going to be a very good way to do things. If they change the format, w/e everything would be messed up. It would be nice if I could access these brokerage firms in a more efficient, reliable way.

Thanks

Dwiel

##### Share on other sites
In essence you would be producing a browser of your own catered to the site. One thing that comes to mind is SSL. Those transactions are guaranteed to be encrypted you would need to layer your code over that. And then there is the consideration of the site changing their urls so you would have to keep track of that.

##### Share on other sites
quote:
Original post by Tazzel3D
There are firms that allow you to make transactions online. I was simply windering if there was an easy way to interface to one of these web broker''s websites. I would rather not have to emulate a person by ''pretending'' that my application is a web browser that fills in it''s own data into the fields such as which stock to buy/sell, for how much, etc. Everything that a person who was doing this online would type in and click. It would be nice if there was an easier, more robust way to do this. I don''t think that parsing a broker''s web page is going to be a very good way to do things. If they change the format, w/e everything would be messed up. It would be nice if I could access these brokerage firms in a more efficient, reliable way.

Bandwith theif

##### Share on other sites
if the only way to buy/sell your stock electronically is through HTML then the only way to buy/sell your stock electronically is through HTML.

the only way around it would be if the broker had a back end interface through which you could communicate more easily (typically some sort of XML data exchange). they would have to provide it and tell you the format for data exchange. AFAIK brokers DO have such systems, they are just exclusively for broker to broker dealings and without a doubt are either VPN'd or IP restricted to only known partner machines. the validation there is likewise undoubtably fairly secure and would most likely be illegal for you to interface through were you even to deciper the mechanism of information exchange.

basically you are limited to using the channels that the brokers have set up for individual clients which means phone and web. if you want to automate your process, you are stuck parsing HTML and submitting forms through HTTP connections. you are right that if they change the format you are screwed and have to rewrite your code.

it's also possible, i believe, with a good broker, to leave fairly complex instructions, like sell if price drops below X rises above Y for stock Z, or buy if price drops below X for stock Y. but that probably costs more

-me

[EDIT: ps. another thing you might want to consider if you REALLY want to automate your finances is to see if the brokerage will accept email orders. if so you can just automate the sending of emails which is easier than going through the whole parsing HTML deal. this is obviously WAY easier if you have access to your own web box running an email service. and perhaps easier still if that box is a *NIX box on which you can easily script cron jobs and the like.]

[edited by - Palidine on October 9, 2003 6:18:55 PM]

##### Share on other sites
ah, one more thing about the HTML parsing. a good deal of sites these days do authentication and session persistance through cookies. having sessionids on the URL line allow easy hijaking of sessions. so a further complication to the HTML deal is that you will have to implement cookies in your mock-browser app.

-me

##### Share on other sites
Hey,

Thanks for the comments. Although I am not to pleased to hear that I am going to be needing to parse the broker''s html pages (most likely), its at least good to know that I didn''t skip over something completely obvious. I doubt that an email system would work due to the lare number of transactions I would be making, but nonetheless, is an idea, I will look more into. I sadly agree that these brokers most likely have a very nice interface that would make what I am trying to do fairly trivial, but are most likely restricted to a small few and are very secure.

What is probobly the easiest way to do the parsing of the pages? I was thinking maybe just using a perl script or something that could be used as a command line program... Just give it a couple of arguments for the transaction and let it do the rest. Perl seems to be a very easy way to do pasing and web stuff like this. What do you think?

thanks for the replies!

Dwiel

P.S. I think I have a way to retrieve quotes... if I download the ''page'' returned by the url:

http://finance.yahoo.com/d/quotes.csv?s=Symbol&f=sl1d1t1c1ohgv&e=.csv

I get the data I need which is seperated by commas. Probobly another perl script job.

##### Share on other sites
I actually had this idea too. But never got into it to deeply.

anyways this is how I would do it.

1. make a very simple browser that just goes to which site you want and then downloads the HTML version of that webpage.

2. tokenize and parse the HTML page and make sure syntax match with how the site shows their stock rates, eh cost whatever. Extract them.

3. Compare the numbers you''ve extracted and do some addition multiplication divition and subtraction.

##### Share on other sites
Websites that display stock tickers usually have a 15-20 minutes delay, and the delay will increase if you are requesting prices in a too rapid succession. Most if not all brokerage firms will require a phone call or an email confirmation before proceeding with your internet orders.

''Daytrading'' is surrounded with bylaws that prevents anyone without proper background and registration to venture into. Once you get the license, there are tons of software and providers that can link you up with a brokerage firm and get real-time data, including analyst reports and financial news. The investment course is around $750 and the software + link is around$1500/year; more sophisticated systems that include modeling, technical analysis, and portfolio backtracking will cost you around $5000 and up. I don''t think you could build yourself something equivalent ''on-the-cheap'', given the constraints on the data sources and trading checks. BTW, what does it have to do with games programming? #### Share this post ##### Link to post ##### Share on other sites I wrote a Java program for a friend of mine which allowed him to log onto to a trading website and download tables of historical stock prices, P/E ratios, earnings reports, for hundreds of companies at once and save them into an Excel file. Bandwidth wasn''t really an issue because he only did it once in a long while, and since it wasn''t up-to-the-minute price reports, there was no SSL. Parsing the pages wasn''t too bad in practice, just searched for certain HTML tags in a certain order... I''m not sure how SSL would be handled, but it''s definately doable so long as the website format is consistent across pages and over time. Whether your brokerage would allow it if they caught on is another thing altogether. Of course I don''t trust my computer with my money :b I would rather look over its recommendations before I actually bought/sold stock. Tom #### Share this post ##### Link to post ##### Share on other sites I will only allow the computer to make these kinds of transactions once that it has proved that it can make ''smart'' discisions by only doing it virtually at first. I will make sure that all of the bugs are out before I actually let it buy/sell stocks with real money. One thing that troubles me, is your comment that infers that the brokerage compony would care about me automating the trasaction process. I was curious why they would dislike this. If anything it a good thing as it allows my account to make many more transactions per time than it would otherwise would be able to. Normally, these places are payed per transaction. Thanks for the comments/suggestions Dwiel #### Share this post ##### Link to post ##### Share on other sites There are plenty of companies that offer C/Java interfaces to buying/selling stock and checking the price in near real time. Most financial firms use these services all the time. Do your research, you''re going to find plenty of such services. #### Share this post ##### Link to post ##### Share on other sites its encouraging to hear that what I was hoping for is available! I have been doing a considerable amount of searching and have yet to find one of these systems available. do you think you could either tell me of one or tell me what a good search would be? I have tried: C interface Stock trading java interface stock trading C interface stock transactions C interface stock buy sell C library stock trading What would you suggest because I am obviously not looking in the right places. Thanks Dwiel #### Share this post ##### Link to post ##### Share on other sites I couldn''t tell you the names. I just tried to do a quick search but didn''t find anything. I remember spending about two-three hours a year ago or so before I actually found something. Search for something along the lines of direct access to stock market. I am 100% sure these interfaces exist (if they didn''t, how would online trading sites operate?). After all Nasdaq is entirely computerized and doesn''t require human brokers. #### Share this post ##### Link to post ##### Share on other sites I would recommend getting in touch with a few brokerage firms, I''m sure they can point you in the right direction. #### Share this post ##### Link to post ##### Share on other sites > I just tried to do a quick search but didn''t find anything A quick search revealed the following links: http://www.comstock-interactivedata.com/ http://www.mechtrading.com/ http://www.quotetracker.com/ http://www.realtick.com/ http://www.money.net/ http://www.bullsession.com/ http://www.investools.com/ With ComStock being pretty much the ''standard'' onto which others piggyback their system on. > the brokerage compony would care about me automating the trasaction process. Agreed, they make money on the commissions but as AP pointed out above, some states & provinces have strong regulations that restrict access to a stock exchange only to those who know how it works. In Canada, you need a CSC permit (Canadian Securities Course) to trade without a broker; you need yet another permit to trade options and do short selling. Some trading firms will not allow daytraders to have uncovered margin accounts; ''shorting'' a stock can''t be done unless you have 200% equivalent in cash on hand or something the like). > I was curious why they would dislike this. There are legal consequences for a daytrading firm to let *uneducated* traders ruin themselves; daytrading is perceived to be akin to gambling in some states, hence the strong regulations, trading permits and stiff penalties. It''s not that you can''t trade when and how you want, but there are laws and regulations you need to abide by in order to do it. -cb #### Share this post ##### Link to post ##### Share on other sites AFAIK, trading with computers is OK in the US, but there is a special barrier to prevent chain reactions. Once the market has dropped below x points for a day, computer trading becomes illegal. You might want to confirm that, though. Cédric #### Share this post ##### Link to post ##### Share on other sites I have also heard that it is illegal to trade with computers after the market drops by a certain percent... I think the crash of ''87 was due to computer chain reactions... cbenoi1: I have looked at those sites and none of them let you actually buy/sell stocks for inside your application, which is what I am looking for. These only allow you to check the prices, which is definately something I need to be able to do, but I also need to be able to make transactions. Thats a very good point about nasdaq, how it is completely computerized. I will definately look into that Dwiel #### Share this post ##### Link to post ##### Share on other sites If you need realtime stock info you''re looking to pay a lot of money to get access to that information and you''re not going to be able to get it into your own app easily if at all. If you don''t mind 15 minute delayed info you can simply use Winsock and make HTTP calls to finance.yahoo.com and then parse the resulting page for the stock info. Having a computer handle all your financial transactions is an excellent way to lose money. You''re better off at the most, using a computer to track and analyze stock and then spit out recommendations based on what you''re looking for. finance.yahoo.com has a very handy stock screener that does just that. If you''re looking to seriously invest you either need to study companies before buying their stock or tape up the stocks section of the paper and throw darts at it, buying the stocks that get hit. Both methods yield similar results. Ben #### Share this post ##### Link to post ##### Share on other sites NASDAQ and NYSE have computerized their exchanges. Thresholds safeguards the markets and it has nothing to do with the traders'' manual or computerized orders. BTW, you''ll need to make multibillion$ transactions to affect the market this way; only George Soros was able to do this and only once. So don''t worry about it.

For selling and buying stocks you''ll need a broker or become a full-fledged floor trader. There''s nothing in between.

##### Share on other sites
It looks it might be easier to set up/download one of these applications that can make transactions and then hook it so you can allow your applications to make the transactions automattically.

For those of you trying to convince me not to do this, I will tell you that I will definately test my program a lot and put it many safe checks before I give it acess to the real stuff.

I''v emailed some of the componies that have programs that you can run on your computer and make trades to see if there is an interface that I can use, I''ll see what they say.

Dwiel

##### Share on other sites
quote:
Original post by Tazzel3D
For those of you trying to convince me not to do this, I will tell you that I will definately test my program a lot and put it many safe checks before I give it acess to the real stuff.

That''s basically what one of the space shuttle engineer told his boss: "Don''t worry, I''ve tested this stuff a lot".

##### Share on other sites
Hm... this is giving me the idea to create some sort of app to spot patterns in market activity. Basically it would just sit in system tray all day and gather info from Yahoo stocks or wherever. If patterns did emerge, I might then try to create what Tazzel is working at.

##### Share on other sites
I didn''t read the whole thread, but I would check VERY hard over any laws dealing with the trade of stock and such.

Having a computer trade for you might not be bad in itself,... but they might get pissed at you if many people start using that for an unfair advantage in trading,...

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627681
• Total Posts
2978611

• 13
• 12
• 10
• 12
• 22