mirror of
https://git.hmsn.ink/coin/api.git
synced 2026-03-19 15:54:59 +09:00
59 lines
1.7 KiB
Python
59 lines
1.7 KiB
Python
from sqlalchemy import create_engine, Table, Column, Integer, String, Float, Double, DateTime
|
|
from sqlalchemy.orm import registry, sessionmaker
|
|
|
|
# 메타데이터 객체 관리
|
|
mapper_registry = registry()
|
|
|
|
# DB 유저 테이블
|
|
ticker_table = Table(
|
|
"ticker",
|
|
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),
|
|
)
|
|
|
|
# Python 유저 객체
|
|
class Ticker:
|
|
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
|
|
|
|
# 테이블과 클래스의 매핑 설정
|
|
mapper_registry.map_imperatively(Ticker, ticker_table)
|
|
|
|
def get_session():
|
|
# 데이터베이스 설정
|
|
engine = create_engine('postgresql+psycopg2://bangae1:fpdlwms1@hmsn.ink:35432/coin')
|
|
mapper_registry.metadata.create_all(engine) # 테이블 생성
|
|
Session = sessionmaker(bind=engine)
|
|
session = Session()
|
|
return session |