Files
ttools/tests/alpaca_loader.ipynb
David Brazda b23a772836 remote fetch
2024-11-10 14:08:41 +01:00

16 KiB
Raw Blame History

In [1]:
from ttools.external_loaders import load_history_bars
from ttools.config import zoneNY
from datetime import datetime, time
from alpaca.data.timeframe import TimeFrame, TimeFrameUnit

symbol = "AAPL"
start_date = zoneNY.localize(datetime(2023, 2, 27, 18, 51, 38))
end_date = zoneNY.localize(datetime(2023, 4, 27, 21, 51, 39))
timeframe = TimeFrame(amount=1,unit=TimeFrameUnit.Minute)

df = load_history_bars(symbol, start_date, end_date, timeframe, True)
df.loc[('AAPL',)]
TTOOLS: Loaded env variables from file /Users/davidbrazda/Documents/Development/python/.env
In [5]:
df.loc[('AAPL',)]
Out[5]:
<style scoped=""> .dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; } </style>
open high low close volume trade_count vwap
timestamp
2023-02-28 09:30:00-05:00 147.050 147.380 146.830 147.2700 1554100.0 6447.0 146.914560
2023-02-28 09:31:00-05:00 147.250 147.320 147.180 147.2942 159387.0 6855.0 147.252171
2023-02-28 09:32:00-05:00 147.305 147.330 147.090 147.1600 214536.0 7435.0 147.210128
2023-02-28 09:33:00-05:00 147.140 147.230 147.090 147.1500 171487.0 7235.0 147.154832
2023-02-28 09:34:00-05:00 147.160 147.160 146.880 146.9850 235915.0 4965.0 147.001762
... ... ... ... ... ... ... ...
2023-04-27 15:26:00-04:00 168.400 168.415 168.340 168.3601 163973.0 1398.0 168.368809
2023-04-27 15:27:00-04:00 168.360 168.400 168.330 168.3800 130968.0 1420.0 168.364799
2023-04-27 15:28:00-04:00 168.380 168.430 168.320 168.3285 152193.0 1361.0 168.372671
2023-04-27 15:29:00-04:00 168.325 168.330 168.260 168.2850 208426.0 1736.0 168.297379
2023-04-27 15:30:00-04:00 168.280 168.350 168.255 168.3450 218077.0 1694.0 168.308873

15162 rows × 7 columns

In [3]:
df
Out[3]:
<style scoped=""> .dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; } </style>
open high low close volume trade_count vwap
symbol timestamp
AAPL 2023-02-27 18:52:00-05:00 148.0200 148.02 148.0200 148.02 112.0 7.0 148.020000
2023-02-27 18:56:00-05:00 148.0200 148.02 148.0200 148.02 175.0 10.0 148.020000
2023-02-27 19:00:00-05:00 148.0299 148.03 148.0299 148.03 1957.0 10.0 148.029993
2023-02-27 19:06:00-05:00 148.0600 148.06 148.0600 148.06 122.0 7.0 148.060000
2023-02-27 19:09:00-05:00 148.0500 148.10 148.0500 148.10 1604.0 33.0 148.075109
... ... ... ... ... ... ... ...
2023-04-27 19:54:00-04:00 167.8000 167.80 167.8000 167.80 534.0 15.0 167.800000
2023-04-27 19:56:00-04:00 167.8800 167.88 167.8800 167.88 1386.0 28.0 167.880000
2023-04-27 19:57:00-04:00 167.8000 167.80 167.8000 167.80 912.0 60.0 167.800000
2023-04-27 19:58:00-04:00 167.8000 167.88 167.8000 167.88 3311.0 22.0 167.877333
2023-04-27 19:59:00-04:00 167.9000 167.94 167.9000 167.94 1969.0 64.0 167.918150

31217 rows × 7 columns