How to Use Python to write a program for automatic stock trading? (Excluding trading algorithms )?

Source: Internet
Author: User
How to connect python with trading software? How do I set the position for warehouse creation and liquidation? Thank you very much! How to connect python with trading software? How do I set the position for warehouse creation and liquidation?
Thank you very much! Reply: I understand what you mean. You just want to find a software or brokerage interface to upload transaction instructions. You may have prepared python for data capture and analysis in the early stage, therefore, this is the last step of the transaction instruction interface. For retail investors in stocks, the formal method is Huabao, guoxin, and xingye, who are willing to give the interface to the brokers, but it seems that the account opening fee is very high to give this right, and only lts, c ++ interfaces such as ctp need to be encapsulated by yourself without the python version. There is also a direct interface for software such as wind to support some brokers, but it is also expensive. In case of a few years, the third method is the wild path and the mouse and keyboard simulation method, it is very complicated to simulate the keyboard and mouse to operate some software, such as brokerage version trading software and big intelligence. Another way is to find and change the underlying code of these software about the transaction commands. I don't know if it is actually feasible .. In this way, retail investors have to rely on technology if they don't have any funds. However, I think that the accuracy of prediction is higher than the timeliness of transactions under the T + 1 rule. It is good to spend time analyzing data, the transaction can be done manually .. For futures, you can use the ctp interface to support various Futures Exchanges in China and python open source pyctp.
For stocks, Huabao securities has a stock ctp, but it may not have a ready-made python interface. Http://quantopian.com I do not know whether there is a probability of stock-selling by the wall:

The following methods do not buy up or fall, while avoiding quilt covers, disadvantages, and handling fees are relatively high, but the entire bull market can be completely completed, and the bear market will not be covered.

Use python to get the stock price, such as tushare. If you find that the stock rose above the dashboard on the current day (determined by to), buy and hold for one day. If the stock falls, do not buy it on the current day, you can use the probability theory method to hold 5, 10, or 20 funds at the same time, so that you can theoretically win the market without fear of the impact of disk suspension. Benefits: avoiding human impulse and high service fees

Another method is to operate the etf, such as the 50 etf, etf300, Small and Medium board etf, And the gem etf. On the same day, the etf will be bought at 2.30 points, with the largest increase in the price, don't buy anything without going up. Hold it for one day and judge the next morning. If it falls by more than 2%, sell it. Advantage: I don't need to step on mines. disadvantage: I recommend this method as the market goes up. The external risks are relatively small.

I have specific python programs that are more complex than above, including stop-loss position, fund management, and monitoring management. I have used them in real disks, and the automated ordering has been solved.

I think the success or failure of a program is not a one-day success, but a long-term stable earning of money, such as running for ten years, too much data analysis is meaningless, because predicting the future will always be a probability problem, not a hundred percent definite, if your program can beat the market for a long time, your program will be able to tend to the theorem of big numbers.

Otherwise, the instant rollback will stop the program from automatically executing, and it will not tend to the probability of stability in the big number theorem.

If there is a program that can be identified by 99 percent, it will basically be an analysis of the internal transaction data. Like Xu x, every time a stock is retained, this method should be an inside story, no program is required for transaction.

Buffett's transaction model is essentially a kind of insider trading, because he relies on external analysis and on-the-spot checks. It is estimated that this is a means of finding the inside story. Now it is bigger, and this effect will not work, the income has also declined, and the U.S. economy has declined. Therefore, Buffett's future must be gloomy, because the pool of insider trading is limited and it is difficult to operate on large amounts of funds.

If Buffett was born in the Soviet Union, India, Japan, and other countries, he may have a meal on the street. After the Second World War, the economic environment of the United States became more inclined to have an inside story, instead of having many gods on stock trading technology. Therefore, Buffett chose procedural transactions.

Buffett and many American stock gods are actually caused by the deviation of survivors. Where do you think the Soviet stock gods are? Why not? ("Silent data" and "dead will not talk ")

In my opinion, in the future, it must be a program, not a human being, because a good program strategy can be used for a lifetime to achieve long-term stable growth. Of course, the premise is that the social and economic environment is stable, there will be no turmoil like the Soviet Union, nor a vicious inflation like Japan (a little worried about the currency m2 ).


Too many stocks make the stockholders immersed in stock-selecting games every day. Stock-selecting creates brokerage market software. In fact, a lot of data is useless, The key to all is to always execute according to the operation method to stabilize the probability.Otherwise, we will change the method for tomorrow. Today we will press kdj, tomorrow we will press macd, the day after tomorrow we will press boll, and the day after tomorrow we will press ddx, and the day after tomorrow we will select stocks based on our own indicators and multiple conditions, the final payment of the service fee or stop loss is delayed. At this time, the purpose of brokerage commission is achieved, the annual Commission received by the brokerage is higher than the stock market dividends. No matter what the market conditions are, as long as you invite a few more stock reviewers, there is always a right direction. Playing a probability game allows you to trade frequently, and the brokerage revenue will only increase and not decrease. Therefore, do not trust the stock evaluation. It is a probability game. Just like predicting the positive and negative sides of a coin, please have ten stock reviewers who can predict three correct stock reviews. If you believe in this stock evaluation, you may not be able to make it three times later. Therefore, brokers and market software always bring up various messages or comments at the close or lunch break. To be honest, this kind of thing has no value for a penny. It may have been written that the rise was module a. The decline was about template B. The comment of ping City was about template c. It was just to fill in the data of the day. It was all about eight shares, all of which were post-mortem, the same event is said to be the reason for the increase in the morning and the reason for the decline in the afternoon.

After the program's strategy is tested, the key lies in stable execution, long-term stable execution, long-term stable and stable execution, and the important thing is to say three times.

In addition, using a certain method to reduce the service fee can also make your funds live longer, such as changing the previous daily model to the weekly or monthly model. Connectivity code, which is generally java, is rare in c/c ++ code. Python. In fact, from the perspective of efficiency, python is not the best choice for writing connectivity code. It mainly depends on what you want to do. It is not the direct broker client, but the broker's automated transaction command gateway, generally, the most common fix is used. Currently, the Chinese guoxin version seems to be the highest and supports margin lending.
The futures end uses CTP or Pegasus
Of course, the spot price first requires the level2 market access, which is simple.
If you are pursuing speed, use C ++. If it is just a simple algorithm and signal recognition, python or R has a relatively simple library. Stocks generally require brokers to provide interfaces, making it difficult for individuals to obtain accounts.
Futures are more convenient and can be used directly with CTP.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.