diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/bbg_cds_quotes.py | 7 | ||||
| -rw-r--r-- | python/bbg_index_quotes.py | 6 | ||||
| -rw-r--r-- | python/remote.py | 94 |
3 files changed, 6 insertions, 101 deletions
diff --git a/python/bbg_cds_quotes.py b/python/bbg_cds_quotes.py index 5d1ac2f8..c0863708 100644 --- a/python/bbg_cds_quotes.py +++ b/python/bbg_cds_quotes.py @@ -1,11 +1,10 @@ import datetime import logging -import os -from bbg_helpers import BBG_IP, init_bbg_session, retrieve_data +from serenitas.analytics.bbg_helpers import BBG_IP, init_bbg_session, retrieve_data from markit.import_quotes import get_basketids, get_bbg_tickers -from utils import SerenitasFileHandler -from utils.db import dbconn +from serenitas.utils import SerenitasFileHandler +from serenitas.utils.db import dbconn logger = logging.getLogger("bbg_quotes") fh = SerenitasFileHandler("bbg_quotes.log") diff --git a/python/bbg_index_quotes.py b/python/bbg_index_quotes.py index ba81739a..bc25c9f5 100644 --- a/python/bbg_index_quotes.py +++ b/python/bbg_index_quotes.py @@ -1,9 +1,9 @@ -from serenitas.utils.bbg_helpers import init_bbg_session, BBG_IP, retrieve_data +from serenitas.analytics.bbg_helpers import init_bbg_session, BBG_IP, retrieve_data import datetime from serenitas.utils.db import dbconn securities = {} -for series in range(9, 34): +for series in range(11, 36): for index_type in ["IG", "HY"]: for t in [3, 5, 7, 10]: securities[f"CDX {index_type} CDSI S{series} {t}Y Corp"] = ( @@ -11,7 +11,7 @@ for series in range(9, 34): index_type, f"{t}yr", ) -for series in range(10, 33): +for series in range(12, 35): for index_type in ["EUR", "XOVER"]: for t in [3, 5, 7, 10]: securities[f"ITRX {index_type} CDSI S{series} {t}Y Corp"] = ( diff --git a/python/remote.py b/python/remote.py deleted file mode 100644 index 23513587..00000000 --- a/python/remote.py +++ /dev/null @@ -1,94 +0,0 @@ -import json -import pathlib -import socket - -from ftplib import FTP -from io import BytesIO -from paramiko import Transport, SFTPClient, RSAKey -from pathlib import Path -from ssh2.session import Session -from ssh2.sftp import LIBSSH2_FXF_READ, LIBSSH2_SFTP_S_IRUSR, LIBSSH2_SFTP_S_IFREG -from typing import Union - - -def load_credentials(name: str): - return json.load((Path(".credentials") / f"{name}.json").open()) - - -class Client: - @classmethod - def from_creds(cls, name: str): - args = json.load((Path(".credentials") / f"{name}.json").open()) - return cls(**args) - - -class FtpClient(Client): - def __init__(self, host, username, password, folder=None): - self.client = FTP(host, username, password) - if folder is not None: - self.client.cwd(folder) - - def put(self, src: Union[pathlib.Path, bytes], dst: str = None): - if isinstance(src, pathlib.Path): - if dst is None: - dst = src.name - with src.open("rb") as fh: - self.client.storbinary(f"STOR {dst}", fh) - else: - self.client.storbinary(f"STOR {dst}", BytesIO(src)) - - -class SftpClient(Client): - def __init__(self, host, port, username, password=None, key=None, folder=None): - transport = Transport((host, port)) - if key is not None: - pkey = RSAKey.from_private_key_file(Path.home() / ".ssh" / key) - else: - pkey = None - if host.endswith("gs.com"): - so = transport.get_security_options() - so.key_types += ("ssh-dss",) - transport.connect(username=username, password=password, pkey=pkey) - self.client = SFTPClient.from_transport(transport) - if folder is not None: - self.client.chdir(folder) - - def download_files(self, src: str, dst: pathlib.Path, *args): - for f in self.client.listdir(src): - local_file = dst / f - if not local_file.exists(): - self.client.get(f"{src}/{f}", localpath=local_file) - - def put(self, src: Union[pathlib.Path, bytes], dst: str = None, confirm=True): - if isinstance(src, pathlib.Path): - if dst is None: - dst = src.name - with src.open("rb") as fh: - self.client.putfo(fh, dst, confirm=confirm) - else: - self.client.putfo(BytesIO(src), dst, confirm=confirm) - - -class SftpClient2(Client): - def __init__(self, host, port, username, password): - sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - sock.connect((host, port)) - session = Session() - session.handshake(sock) - session.userauth_password(username, password) - self.client = session.sftp_init() - - def download_files(self, src: str, dst: pathlib.Path, *args): - files = [] - with self.client.opendir(src) as fh: - for size, buf, attrs in fh.readdir(): - if attrs.permissions & LIBSSH2_SFTP_S_IFREG: - files.append(buf.decode()) - for f in files: - local_file = dst / f - if not local_file.exists(): - with self.client.open( - f"{src}/{f}", LIBSSH2_FXF_READ, LIBSSH2_SFTP_S_IRUSR - ) as remote_handle, local_file.open("wb") as local_handle: - for size, data in remote_handle: - local_handle.write(data) |
