mirror of
https://github.com/codez0mb1e/resistance.git
synced 2024-11-22 02:12:19 +00:00
Update FIGI parser
This commit is contained in:
parent
e1f86b7714
commit
0d5e961123
@ -1,23 +1,35 @@
|
|||||||
# %%
|
# %%
|
||||||
|
import os
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Optional
|
from typing import Literal, Union
|
||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
|
|
||||||
|
from sqlalchemy import types, sql
|
||||||
|
from azure import AzureDbConnection, ConnectionSettings
|
||||||
|
|
||||||
|
|
||||||
# %%
|
# %%
|
||||||
@dataclass
|
@dataclass
|
||||||
class AssetInfo:
|
class AssetInfo:
|
||||||
FIGI: str
|
FIGI: str
|
||||||
Ticker: str
|
Ticker: str
|
||||||
Title: str
|
Title: Union[str, None]
|
||||||
Description: Optional[str]
|
Description: Union[str, None]
|
||||||
AssetType: str = 'Cryptocurrency'
|
AssetType: Literal['Cryptocurrency']
|
||||||
SourceId: str = "OpenFigi API"
|
SourceId: Literal['OpenFigi API']
|
||||||
Version: str = "v202204"
|
Version: Literal['v202206']
|
||||||
|
|
||||||
|
|
||||||
def get_asset_info(pair: str) -> AssetInfo:
|
def get_figi(pair: str) -> Union[AssetInfo, None]:
|
||||||
|
"""Return FIGI for pair
|
||||||
|
|
||||||
|
References:
|
||||||
|
- https://www.openfigi.com/assets/local/figi-allocation-rules.pdf
|
||||||
|
- https://www.openfigi.com/search
|
||||||
|
"""
|
||||||
api_url = f'https://www.openfigi.com/search/query?facetQuery=MARKET_SECTOR_DES:%22Curncy%22&num_rows=100&simpleSearchString={pair}&start=0'
|
api_url = f'https://www.openfigi.com/search/query?facetQuery=MARKET_SECTOR_DES:%22Curncy%22&num_rows=100&simpleSearchString={pair}&start=0'
|
||||||
response = httpx.get(api_url)
|
response = httpx.get(api_url)
|
||||||
|
|
||||||
@ -43,17 +55,17 @@ expected_pairs = {
|
|||||||
'ETH-USD': 'BBG00J3NBWD7',
|
'ETH-USD': 'BBG00J3NBWD7',
|
||||||
'BTC-USD': 'BBG006FCL7J4',
|
'BTC-USD': 'BBG006FCL7J4',
|
||||||
'SOL-USD': 'BBG013WVY457',
|
'SOL-USD': 'BBG013WVY457',
|
||||||
'UNI-USD': 'BBG013TZFVW3'
|
'UNI-USD': 'BBG013TZFVW3',
|
||||||
|
'SUSHI-USD': 'KKG0000010W1'
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, v in expected_pairs.items():
|
for k, v in expected_pairs.items():
|
||||||
assert get_asset_info(k) == v
|
actual = get_figi(k)
|
||||||
|
print(actual)
|
||||||
|
assert actual == v
|
||||||
|
|
||||||
|
|
||||||
# %%
|
# %%
|
||||||
import os
|
|
||||||
import pandas as pd
|
|
||||||
|
|
||||||
pair_names = [x[:-4] for x in os.listdir("../data")]
|
pair_names = [x[:-4] for x in os.listdir("../data")]
|
||||||
|
|
||||||
def insert_dash(text: str, position: int) -> str:
|
def insert_dash(text: str, position: int) -> str:
|
||||||
@ -62,14 +74,44 @@ def insert_dash(text: str, position: int) -> str:
|
|||||||
else:
|
else:
|
||||||
return text
|
return text
|
||||||
|
|
||||||
usd_pairs = [insert_dash(s.upper(), 3) for s in pair_names if "usd" in s]
|
usd_pairs = [
|
||||||
|
insert_dash(s.upper(), 3)
|
||||||
|
for s in pair_names if "usd" in s
|
||||||
|
]
|
||||||
|
|
||||||
print(usd_pairs)
|
print(usd_pairs)
|
||||||
|
|
||||||
# %%
|
|
||||||
pair_figi_list = [get_asset_info(p) for p in usd_pairs]
|
|
||||||
|
|
||||||
for p in usd_pairs:
|
pair_figi_list = [get_figi(p) for p in usd_pairs]
|
||||||
print(p)
|
|
||||||
get_asset_info(p)
|
# %% ----
|
||||||
|
conn_settings = ConnectionSettings(server='***.database.windows.net', database='market-data-db', username='***', password='***')
|
||||||
|
db_conn = AzureDbConnection(conn_settings)
|
||||||
|
|
||||||
|
db_conn.connect()
|
||||||
|
for t in db_conn.get_tables():
|
||||||
|
print(t)
|
||||||
|
|
||||||
|
|
||||||
# %%
|
# %%
|
||||||
|
db_mapping = {
|
||||||
|
'FIGI': types.VARCHAR(length=12),
|
||||||
|
'open': types.DECIMAL(precision=19, scale=9),
|
||||||
|
'high': types.DECIMAL(precision=19, scale=9),
|
||||||
|
'close': types.DECIMAL(precision=19, scale=9),
|
||||||
|
'low': types.DECIMAL(precision=19, scale=9),
|
||||||
|
'volume': types.DECIMAL(precision=19, scale=9),
|
||||||
|
'time': types.DATETIME(),
|
||||||
|
'source_id': types.SMALLINT,
|
||||||
|
'version': types.VARCHAR(length=12),
|
||||||
|
'interval': types.CHAR(length=2)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
query = sql.text("select * from Cryptocurrency where figi = 'ustusd'")
|
||||||
|
result = db_conn._conn.execute(query).fetchall()
|
||||||
|
|
||||||
|
|
||||||
|
# %%
|
||||||
|
db_conn.dispose()
|
||||||
|
print('Completed')
|
||||||
|
Loading…
Reference in New Issue
Block a user