This commit is contained in:
2025-08-23 13:08:58 +09:00
parent c11ef161f4
commit 7c48d61edd
4 changed files with 241 additions and 62 deletions

View File

@@ -4,56 +4,42 @@ from sqlalchemy.orm import registry, sessionmaker
# 메타데이터 객체 관리
mapper_registry = registry()
# DB 유저 테이블
ticker_table = Table(
"ticker",
candle_table = Table(
'candle',
mapper_registry.metadata,
Column("contract", String(20), primary_key=True),
Column("clast", String(50)),
Column("change_percentage", Double),
Column("total_size", Integer),
Column("volume_24h", Integer),
Column("volume_24h_base", Integer),
Column("volume_24h_quote", Integer),
Column("volume_24h_settle", Integer),
Column("funding_rate", Double),
Column("funding_rate_indicative", Double),
Column("quanto_base_rate", String(100)),
Column("low_24h", Double),
Column("high_24h", Double),
Column("price_type", String(10)),
Column("change_from", String(20)),
Column("change_price", Double),
Column("ts", DateTime, primary_key=True),
Column("open", String(50)),
Column("close", String(50)),
Column("high", String(50)),
Column("low", String(50)),
Column("volume", Integer),
Column("amount", String(50)),
Column("time", Integer, primary_key=True),
)
# Python 유저 객체
class Ticker:
class Candle:
contract: str
clast:float
change_percentage:float
total_size:int
volume_24h:int
volume_24h_base:int
volume_24h_quote:int
volume_24h_settle:int
funding_rate:float
funding_rate_indicative:float
quanto_base_rate:str
low_24h:float
high_24h:float
price_type:str
change_from:str
change_price:float
ts:str
open:str
close:str
high:str
low:str
volume:int
amount:str
time:int
# 테이블과 클래스의 매핑 설정
mapper_registry.map_imperatively(Ticker, ticker_table)
mapper_registry.map_imperatively(Candle, candle_table)
def get_session():
# 데이터베이스 설정
engine = create_engine('postgresql+psycopg2://bangae1:fpdlwms1@hmsn.ink:35432/coin')
engine = get_engine()
mapper_registry.metadata.create_all(engine) # 테이블 생성
Session = sessionmaker(bind=engine)
session = Session()
return session
return session
def get_engine() :
return create_engine('postgresql+psycopg2://bangae1:fpdlwms1@hmsn.ink:35432/coin')