In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Dig yourself another hole.
What do I want to write?
One: you can browse the current relevant information, as well as the market index real-time update.
Second: add optional stock, you can view the trend chart of the stock, related information and basic data.
Third, through the definition of relevant indicators and common policies on the server side, you can directly add the defined technical indicators and policies to the phone for combination, and then get the results on the server side and view them on the phone side.
Project address: https://github.com/youerning/pstock
Technology used:
● nodejs:socket.io
● golang
● javascript:angularjs,chartjs
● css.
● Python:tushare,PyAlgoTrade,tornado,flask
● Packaging: ionic
Then preview the demo made in two days.
Article catalogue:
● 1: layout
● II: part of the details
● III: get data
● IV: drawing
● 5: write a strategy / / wait to fill the hole
● 6: optimize the details / / wait to fill the hole
● 7: beautify, finish / / wait to fill the hole
Note: in order to ensure that the article is not too lengthy, the code details may be deleted. For more information, please see the project source code:
(1)
1. Environment building reference: write an operation and maintenance APP from scratch (1)
two。 Create a project
Ionic start pstock blank
3. Write index.html.
4. Create the corresponding template file, which is roughly as follows
5. Create a rout
App.config (function ($stateProvider, $urlRouterProvider, $ionicConfigProvider) {$ionicConfigProvider.tabs.position ('bottom'); $stateProvider.state ("home", {url: "/ home", views: {"tab-home": {controller: "homeCtrl", templateUrl: "tpls/home.html"}}); slightly.
At this point, the basic structure is determined.
(2)
1. Pull up, pull down.
Hold down the screen and drag up and down to refresh and load data. It is already available in the JavaScript component of ionic, so you can directly bring it over and use it.
The code is as follows:
`n`.`title`
-`n`.`media _ name`
Then define the specified execution functions loadNewer (), loadOlder () in the corresponding controller.
two。 Save the data of the optional stock.
Since there is no plan to put the optional stock on the server side, the data should be saved locally, that is, in the localStorage
$scope.userCode = angular.fromJson (window.localStorage ["userCode"] | | "{}"); function persist () {window.localStorage ["userCode"] = angular.toJson ($scope.userCode)}
(III)
1. Get news data
In the domestic access to data time is very sad things, why sad not to say, of course, you can climb, but that is too inelegant.
Here are the news data of Jinri Toutiao (Jinri Toutiao has not released its own API? )
First of all, let's open the following website of Jinri Toutiao
Then the data appeared, it is so urinating, in fact, there are many websites are also like this, you can try it yourself.
Reference:
Https://github.com/iMeiji/Toutiao/wiki/%E4%BB%8A%E6%97%A5%E5%A4%B4%E6%9D%A1Api%E5%88%86%E6%9E%90
two。 Get stock data
Tushare is used here, but other API can be used, of course.
Reference: http://tushare.org/trading.html#id2
3. Strategy data (to be filled in.)
Run the PyAlgoTrade strategy.
In fact, direct use of tushare data will report errors, however, that is, the lack of an Adj Close, adding a field will not be so rare.
4. Server side code
# coding: utf8from flask import Flaskfrom flask import Response, request Abortimport urlparseimport requestsimport jsonimport tushare as tsfrom random import randintfrom bs4 import BeautifulSoupimport pandas as pd# import sys# reload (sys) # sys.setdefaultencoding ('utf-8') app = Flask (_ _ name__) # sinaApi = "http://hq.sinajs.cn/list="detailUrl =" http://stockpage.10jqka.com.cn/%s/company/"toutiao = "http://www.toutiao.com/api/article/recent/?source=2&category=%s&as=A105177907376A5&cp=5797C7865AD54E1&count=5&offset=0&_=%s "def getUserAgent (): userAgent = [" Mozilla/5.0 (compatible) MSIE 10.0, Windows NT, DigExt), Mozilla/4.0 (compatible, MSIE 7.0, Windows NT 5.1, 360SE), Mozilla/4.0 (compatible, MSIE 8.0, Windows NT 6.0, Trident/4.0), Mozilla/5.0 (compatible, MSIE 9.0, Windows NT 6.1, Trident/5.0, "Opera/9.80 (Windows NT 6.1, U, en) Presto/2.8.131 Version/11.11", "Mozilla/4.0 (compatible)" MSIE 7. 0, Windows NT 5. 1, TencentTraveler 4. 0), "Mozilla/5.0 (Windows, U, Windows NT 6. 1, en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50", "Mozilla/5.0 (Macintosh, Intel Mac OS X 10-7-0) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11", "Mozilla/5.0 (Macintosh, U, Intel Mac OS X 10-6-8) En-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50 "," Mozilla/5.0 (Linux, U, Android 3.0, en-us, Xoom Build/HRI39) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13 "," Mozilla/5.0 (iPad, U, CPU OS 4-3-3 like Mac OS X, en-us) AppleWebKit/533.17.9 (KHTML) Like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5 "," Mozilla/4.0 (compatible, MSIE 7.0,5.1, Trident/4.0, SE 2.x MetaSr 1.0, SE 2.x MetaSr 1.0, .NET CLR 2.0.50727, SE 2.x MetaSr 1.0) "," Mozilla/5.0 (iPhone, U, CPU iPhone OS 4 percent 3 like Mac OS X, en-us) AppleWebKit/533.17.9 (KHTML) Like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5 "," MQQBrowser/26 Mozilla/5.0 (Linux, U, Android 2.3.7, zh-cn, MB200 Build/GRJ22, CyanogenMod-7) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 "] return userAgent [randint (0Len (userAgent)-1)] @ app.route (" / ", methods= [" GET ") "POST"]) def index (app): headers = {"User-Agent": getUserAgent ()} code = request.args ["code"] data = {} error = "" if app = "now": # get the current price code = code.split (" ") df = ts.get_realtime_quotes (code) ret = df.to_json () elif app = =" stock ": # get stock history data df = ts.get_hist_data (code) df = df.sort_index () df [" date "] = df.indexdf.index = range (len (df.index)) ret = df.to_json () elif app =" detail ": # get stock basic data # company name # place Domain # Company profile # Business scope ret = {} url = detailUrl% codepage = requests.get (url Headers=headers) soup = BeautifulSoup (page.content "html.parser") name = soup.select ("td span") [0] .textbussines = soup.select ("td span") [3] .textregion = soup.select ("td span") [1] .textintro = soup.select ("p.tip.lh34") [- 2] .text [:-3] ret ["name"] = nameret ["bussines"] = bussinesret ["region"] = regionret ["intro"] = introelif app = "bt": ret = [{"status": "ok"}] elif app = = "news": # reverse agent Jinri Toutiao catelog = request.args ["catelog"] time = request.args ["now"] url = toutiao% (catelog Time) page = requests.get (url, headers=headers) ret = [{"status": "ok"}] else:ret = "" error = "incorrect url" try:data ["data"] = json.loads (ret) except Exception as e:data ["data"] = retdata ["error"] = error# print dataresp = Response (json.dumps (data) if error:abort (500) resp.headers ["Content-Type"] = "application/json" Charset=UTF-8 "resp.headers [" access-control-allow-origin "] =" * "return respif _ _ name__ = =" _ _ main__ ": app.run (port=80,debug=True, host=" 0.0.0.0 ")
5. Client side code
$http.get (surl) .success (function (resp) {$scope.labelsline = Object.values (resp.data.date); $scope.seriesline = ["ma5", "ma10", "ma20", "close"]; $scope.dataline = [Object.values (resp.data.ma5), Object.values (resp.data.ma10), Object.values (resp.data.ma20), Object.values (resp.data.close)] $scope.optionsline = {title: {display:true,text: "trend"}, elements: {point: {radius: 0}}, xAxis: {display:true,axisLabel:'X Axis',rotateLabels: 90}}
(4)
Use echarts or chartjs, in fact, there is no technical content. Mainly check API.
However, it seems that there is a problem with the mobile phone, and the amount of data may be too large or incompatible, which need to be checked.
5, 6, 7, to be filled
Ask and answer:
Q: obviously did not use golang,socket.io,tornado, why Mao wrote it in the technology used.
A: I've got the idea, but I haven't finished it yet.
Q: it would be nice to write a web.
A: when you finish app, you will naturally write web.
Postscript: it seems that what is worth talking about is not as simple as expected. I expected to finish it in three days. Before the next article, I should first write pyalgotrade source code interpretation.
If you feel good and get something, buy me a cup of tea.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.