Add support for querying a single day's worth of historical OHLC data
This commit is contained in:
parent
9fed98b37d
commit
8bf31cde1d
@ -1,7 +1,7 @@
|
|||||||
import pandas as pd
|
import pandas as pd
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime, time
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from os import getenv
|
from os import getenv
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
@ -63,11 +63,15 @@ def minutes(value):
|
|||||||
def hours(value):
|
def hours(value):
|
||||||
return value * 3600
|
return value * 3600
|
||||||
|
|
||||||
def get_historical_data(symbol: str, interval: int,
|
def get_historical_data(symbol: str, interval: int, date: datetime = None,
|
||||||
start_date: datetime, end_date: datetime = None,
|
start_date: datetime = None, end_date: datetime = None,
|
||||||
start_filter_time: datetime = datetime.strptime('093000', '%H%M%S').time(),
|
start_filter_time: datetime = datetime.strptime('093000', '%H%M%S').time(),
|
||||||
end_filter_time: datetime = datetime.strptime('160000', '%H%M%S').time()) -> pd.DataFrame:
|
end_filter_time: datetime = datetime.strptime('160000', '%H%M%S').time()) -> pd.DataFrame:
|
||||||
|
|
||||||
|
if date:
|
||||||
|
start_date = date
|
||||||
|
end_date = datetime.combine(date, time.max)
|
||||||
|
|
||||||
message = 'HIT,{symbol},{interval},{begin},{end},,{begin_filter},{end_filter},1\n'.format(
|
message = 'HIT,{symbol},{interval},{begin},{end},,{begin_filter},{end_filter},1\n'.format(
|
||||||
symbol = symbol,
|
symbol = symbol,
|
||||||
interval = interval,
|
interval = interval,
|
||||||
@ -94,8 +98,7 @@ def get_historical_data(symbol: str, interval: int,
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
symbols = ['SPY']
|
symbols = ['SPY']
|
||||||
start_date = datetime(2023, 1, 1, 7, 50)
|
date = datetime(2024, 3, 28)
|
||||||
end_date = datetime(2023, 1, 31, 16, 0)
|
|
||||||
for symbol in symbols:
|
for symbol in symbols:
|
||||||
data = get_historical_data(symbol, minutes(5), start_date, end_date)
|
data = get_historical_data(symbol, minutes(5), date)
|
||||||
print(data)
|
print(data)
|
||||||
|
Loading…
Reference in New Issue
Block a user