Spaces:
Sleeping
Sleeping
talib issue
Browse files
helper.py
CHANGED
@@ -1,7 +1,49 @@
|
|
1 |
import pandas as pd
|
2 |
-
import talib as ta
|
3 |
import numpy as np
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
def format_date(df):
|
6 |
format = '%Y-%m-%d %H:%M:%S'
|
7 |
df['Datetime'] = pd.to_datetime(df['date'] + ' ' + df['time'], format=format)
|
|
|
1 |
import pandas as pd
|
|
|
2 |
import numpy as np
|
3 |
|
4 |
+
# check if the library folder already exists, to avoid building everytime you load the pahe
|
5 |
+
# import streamlit as st
|
6 |
+
import requests
|
7 |
+
import os
|
8 |
+
import sys
|
9 |
+
import subprocess
|
10 |
+
if not os.path.isdir("/tmp/ta-lib"):
|
11 |
+
|
12 |
+
# Download ta-lib to disk
|
13 |
+
with open("/tmp/ta-lib-0.4.0-src.tar.gz", "wb") as file:
|
14 |
+
response = requests.get(
|
15 |
+
"http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz"
|
16 |
+
)
|
17 |
+
file.write(response.content)
|
18 |
+
# get our current dir, to configure it back again. Just house keeping
|
19 |
+
default_cwd = os.getcwd()
|
20 |
+
os.chdir("/tmp")
|
21 |
+
# untar
|
22 |
+
os.system("tar -zxvf ta-lib-0.4.0-src.tar.gz")
|
23 |
+
os.chdir("/tmp/ta-lib")
|
24 |
+
os.system("ls -la /app/equity/")
|
25 |
+
# build
|
26 |
+
os.system("./configure --prefix=/home/appuser")
|
27 |
+
os.system("make")
|
28 |
+
# install
|
29 |
+
os.system("make install")
|
30 |
+
# back to the cwd
|
31 |
+
os.chdir(default_cwd)
|
32 |
+
sys.stdout.flush()
|
33 |
+
|
34 |
+
# add the library to our current environment
|
35 |
+
from ctypes import *
|
36 |
+
|
37 |
+
lib = CDLL("/home/appuser/lib/libta_lib.so.0.0.0")
|
38 |
+
# import library
|
39 |
+
try:
|
40 |
+
import talib as ta
|
41 |
+
except ImportError:
|
42 |
+
subprocess.check_call([sys.executable, "-m", "pip", "install", "--global-option=build_ext", "--global-option=-L/home/appuser/lib/", "--global-option=-I/home/appuser/include/", "ta-lib"])
|
43 |
+
finally:
|
44 |
+
import talib as ta
|
45 |
+
|
46 |
+
|
47 |
def format_date(df):
|
48 |
format = '%Y-%m-%d %H:%M:%S'
|
49 |
df['Datetime'] = pd.to_datetime(df['date'] + ' ' + df['time'], format=format)
|