software automatically buying/selling stock

Started by
31 comments, last by Dwiel 20 years ago
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
Advertisement
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...
-~-The Cow of Darkness-~-
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
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.
Well, R2D22U2..
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
-~-The Cow of Darkness-~-
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.

the only other option would be to contact your broker and ask them if they provide any back-end access to clients.

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]
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
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.
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.

4. Buy/Sell whatever...
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?

This topic is closed to new replies.

Advertisement