-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aa9e9ff
commit 7f12028
Showing
10 changed files
with
82 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# TradingView Indicator | ||
|
||
- Cloned from [https://github.com/reg2005/tradingview-ta-docker](https://github.com/reg2005/tradingview-ta-docker) | ||
- Based on [https://github.com/reg2005/tradingview-ta-docker](https://github.com/reg2005/tradingview-ta-docker) | ||
- Based on [https://github.com/brian-the-dev/python-tradingview-ta](https://github.com/brian-the-dev/python-tradingview-ta) | ||
|
||
Since `tradingview-ta-docker` does not provide ARM docker image, I had to build in this project. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,53 @@ | ||
from http.server import BaseHTTPRequestHandler, HTTPServer | ||
from tradingview_ta import TA_Handler, get_multiple_analysis | ||
from urllib.parse import urlparse, parse_qs | ||
import json | ||
|
||
hostName = "0.0.0.0" | ||
serverPort = 8080 | ||
|
||
|
||
class MyServer(BaseHTTPRequestHandler): | ||
def _set_headers(self, statusCode): | ||
self.send_response(statusCode) | ||
self.send_header('Content-type', 'application/json') | ||
self.end_headers() | ||
|
||
def _handle_symbol(self, qParsed): | ||
print('Process _handle_symbol') | ||
|
||
symbol = qParsed['symbol'][0] | ||
screener = qParsed['screener'][0] | ||
exchange = qParsed['exchange'][0] | ||
interval = qParsed['interval'][0] | ||
tv = TA_Handler( | ||
symbol=symbol, | ||
screener=screener, | ||
exchange=exchange, | ||
interval=interval | ||
) | ||
analyse = tv.get_analysis() | ||
|
||
print({symbol, screener, exchange, interval}, vars(analyse)) | ||
self._set_headers(200) | ||
self.wfile.write(bytes(json.dumps({'request': {'symbol': symbol, 'screener': screener, 'exchange': exchange, 'interval': interval}, 'result': { | ||
'summary': analyse.summary, 'time': analyse.time.isoformat(), 'oscillators': analyse.oscillators, 'moving_averages': analyse.moving_averages, 'indicators': analyse.indicators}}), "utf-8")) | ||
|
||
def _handle_symbols(self, qParsed): | ||
print('Process _handle_symbols') | ||
|
||
symbols = qParsed['symbols'] | ||
screener = qParsed['screener'][0] | ||
interval = qParsed['interval'][0] | ||
|
||
analyse = get_multiple_analysis( | ||
screener, interval, symbols | ||
) | ||
|
||
result = {} | ||
for symbol in symbols: | ||
symbolAnalyse = analyse[symbol] | ||
import logging | ||
import sys | ||
import colorlog | ||
|
||
from flask import Flask, jsonify, request | ||
from tradingview_ta import get_multiple_analysis | ||
|
||
app = Flask(__name__) | ||
|
||
logger = logging.getLogger('') | ||
logger.setLevel(logging.DEBUG) | ||
sh = logging.StreamHandler(sys.stdout) | ||
sh.setFormatter(colorlog.ColoredFormatter( | ||
'%(log_color)s [%(asctime)s] %(levelname)s [%(filename)s.%(funcName)s:%(lineno)d] %(message)s', datefmt='%a, %d %b %Y %H:%M:%S')) | ||
logger.addHandler(sh) | ||
|
||
|
||
@app.route('/', methods=['GET']) | ||
def index(): | ||
logger.info("Request: "+str(request.args)) | ||
symbols = request.args.getlist('symbols') | ||
screener = request.args.get('screener') | ||
interval = request.args.get('interval') | ||
|
||
analyse = get_multiple_analysis( | ||
screener, interval, symbols | ||
) | ||
|
||
result = {} | ||
for symbol in symbols: | ||
symbolAnalyse = analyse[symbol] | ||
if not (symbolAnalyse is None): | ||
result[symbol] = { | ||
'summary': symbolAnalyse.summary, 'time': symbolAnalyse.time.isoformat(), 'oscillators': symbolAnalyse.oscillators, 'moving_averages': symbolAnalyse.moving_averages, 'indicators': symbolAnalyse.indicators} | ||
|
||
print({tuple(symbols), screener, interval}, result) | ||
|
||
self._set_headers(200) | ||
self.wfile.write(bytes(json.dumps({'request': { | ||
'symbols': symbols, 'screener': screener, 'interval': interval}, 'result': result}), "utf-8")) | ||
|
||
def do_HEAD(self): | ||
self._set_headers() | ||
|
||
def do_GET(self): | ||
o = urlparse(self.path) | ||
qParsed = parse_qs(o.query) | ||
|
||
symbolExists = 'symbol' in qParsed | ||
symbolsExists = 'symbols' in qParsed | ||
|
||
if symbolExists == True: | ||
self._handle_symbol(qParsed) | ||
elif symbolsExists == True: | ||
self._handle_symbols(qParsed) | ||
else: | ||
self._set_headers(500) | ||
self.wfile.write(bytes(json.dumps( | ||
{'request': qParsed, 'message': 'symbol or symbols must be provided.'}))) | ||
|
||
result[symbol] = {} | ||
# logger.info('Processed '+symbol) | ||
|
||
if __name__ == "__main__": | ||
webServer = HTTPServer((hostName, serverPort), MyServer) | ||
print("Server started http://%s:%s" % (hostName, serverPort)) | ||
response = { | ||
'request': { | ||
'symbols': symbols, | ||
'screener': screener, | ||
'interval': interval | ||
}, | ||
'result': result | ||
} | ||
logger.info("Response: "+str(response)) | ||
return jsonify(response) | ||
|
||
try: | ||
webServer.serve_forever() | ||
except KeyboardInterrupt: | ||
pass | ||
|
||
webServer.server_close() | ||
print("Server stopped.") | ||
if __name__ == "__main__": | ||
from waitress import serve | ||
serve(app, host="0.0.0.0", port=8080) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
certifi==2021.10.8 | ||
chardet==4.0.0 | ||
idna==3.3 | ||
protobuf==3.19.0 | ||
pybind11==2.8.0 | ||
requests==2.26.0 | ||
six==1.16.0 | ||
tradingview-ta==3.2.9 | ||
Flask==2.0.2 | ||
waitress==2.0.0 | ||
urllib3==1.26.7 | ||
paste==3.5.0 | ||
colorlog==6.5.0 |