Look up host and port from environment variables and add some short-hand imports for clients
This commit is contained in:
parent
71379aba8e
commit
ec4cca5869
@ -0,0 +1 @@
|
|||||||
|
from .iqfeed import get_daily_data, get_historical_data, hours, minutes, seconds
|
@ -2,8 +2,12 @@ import pandas as pd
|
|||||||
import socket
|
import socket
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
from os import getenv
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
def read_data_from_socket(sock, recv_buffer=4096):
|
def read_data_from_socket(sock, recv_buffer=4096):
|
||||||
buffer = b''
|
buffer = b''
|
||||||
data = b''
|
data = b''
|
||||||
@ -19,16 +23,13 @@ def read_data_from_socket(sock, recv_buffer=4096):
|
|||||||
return buffer.decode('utf-8')
|
return buffer.decode('utf-8')
|
||||||
|
|
||||||
def _get_daily_data(symbol: str, max_days: int) -> pd.DataFrame:
|
def _get_daily_data(symbol: str, max_days: int) -> pd.DataFrame:
|
||||||
host = '127.0.0.1'
|
|
||||||
port = 9100 # Historical data socket port
|
|
||||||
|
|
||||||
message = 'HDX,{symbol},{max_days},1\n'.format(
|
message = 'HDX,{symbol},{max_days},1\n'.format(
|
||||||
symbol=symbol,
|
symbol=symbol,
|
||||||
max_days=max_days
|
max_days=max_days
|
||||||
)
|
)
|
||||||
|
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
sock.connect((host, port))
|
sock.connect((getenv('IQFEED_HOST'), int(getenv('IQFEED_PORT'))))
|
||||||
|
|
||||||
sock.sendall(message.encode('utf-8'))
|
sock.sendall(message.encode('utf-8'))
|
||||||
data = read_data_from_socket(sock)
|
data = read_data_from_socket(sock)
|
||||||
@ -66,8 +67,6 @@ def get_historical_data(symbol: str, interval: int,
|
|||||||
start_date: datetime, end_date: datetime = None,
|
start_date: datetime, 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:
|
||||||
host = '127.0.0.1'
|
|
||||||
port = 9100 # Historical data socket port
|
|
||||||
|
|
||||||
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,
|
||||||
@ -79,7 +78,7 @@ def get_historical_data(symbol: str, interval: int,
|
|||||||
)
|
)
|
||||||
|
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
sock.connect((host, port))
|
sock.connect((getenv('IQFEED_HOST'), int(getenv('IQFEED_PORT'))))
|
||||||
|
|
||||||
sock.sendall(message.encode('utf-8'))
|
sock.sendall(message.encode('utf-8'))
|
||||||
data = read_data_from_socket(sock)
|
data = read_data_from_socket(sock)
|
||||||
|
@ -1 +1,2 @@
|
|||||||
pandas
|
pandas
|
||||||
|
python-dotenv
|
Loading…
Reference in New Issue
Block a user