-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase_read.py
More file actions
30 lines (23 loc) · 774 Bytes
/
database_read.py
File metadata and controls
30 lines (23 loc) · 774 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import pandas as pd
from sqlalchemy import create_engine
import matplotlib.pyplot as plt
from datetime import datetime, timedelta
# Database connection info
DATABASE_URL = "postgresql://postgres:123456789@localhost/trader_master"
engine = create_engine(DATABASE_URL)
# Load table
df = pd.read_sql("SELECT * FROM candle_a_minute;", engine)
# Convert timestamp
df['time'] = pd.to_datetime(df['ts'], unit='s')
# Filter last day (last 24 hours)
end = df['time'].max()
start = end - timedelta(days=1)
last_day = df[(df['time'] >= start) & (df['time'] <= end)]
# Plot close prices
plt.figure(figsize=(12, 5))
plt.plot(last_day['time'], last_day['c'])
plt.title('Close Price - Last 24 Hours (1-minute)')
plt.xlabel('Time')
plt.ylabel('Close Price')
plt.grid(True)
plt.show()