From c11ef161f4a5a5aaaa6b6a6fb2a8920b3c9c06c7 Mon Sep 17 00:00:00 2001 From: bangae1 Date: Fri, 22 Aug 2025 06:50:28 +0900 Subject: [PATCH] first --- __pycache__/models.cpython-313.pyc | Bin 0 -> 2404 bytes api.iml | 11 ++++++ models.py | 59 +++++++++++++++++++++++++++++ test.py | 23 +++++++++++ 4 files changed, 93 insertions(+) create mode 100644 __pycache__/models.cpython-313.pyc create mode 100644 api.iml create mode 100644 models.py create mode 100644 test.py diff --git a/__pycache__/models.cpython-313.pyc b/__pycache__/models.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f52ad52da877c40d8957cee723c94f066b7ef630 GIT binary patch literal 2404 zcmZuyTW=Fb6rQ!m>y7Wu#YvnCP6`BrnkXRwky3b?#NM*rHM5f- zr!SErwMcydA*3MskjM02^d}@*q?i#B5A-E(pggpXJ+rnqiN#9({GIvET+W%ZXOH9Y z2!iL n1zM(Cq3+Rs3X9RDXF^a>SGQM!)`5|s)88Yl#5uz)EpglMQBQ@IeP;etYy zobU_W?0HQ88GGJ;=7VIr%RILBpjGU}z5Z6i-nuhHnHt zMe&rbwlWuJdU#r-6h31|OZbc(>#*Y;cA~>hcG#(o_0t`8w|BOlFP^Qp!?&-)&UkbC zzc_c`Y&OosG}y6DwxqQ6xt?ZjXkq|CHixpPINa7~60$$m)K6n6SxU5h;1)-+h^EV< z`Ey6YDX;LjPKm~dO02SB5guC7R!qX>?`(6uYVq(ri;*&+TrM(dSY;ksFl~)-`HsCV z{FFN|cgd)de1I#IlnsZ`I*&QTaSYq4YLCTKX6WKy(QS)SO=m~Fu=P@2;?Wv4sv51U zk4c?}bW?NK(F|xjtyeUwOw<~oIj4{Q^WsqJsiN_n<=pMg)us@KzCp zO~(a%1@ISI%y)4`RV@vwK;;ott=g;WrrWwV4C*iwYTL3w4nl!)7}YEb z>WM*-Ixreq^Qt;%Sd90nsv{I#)fm+L$~q(9LPdnf@I!ohs$y5k)CyFnMy99ktrG1= zYX3rX=1l3fVNGc@!~4ORi0Mq$>huE4^FRdSr~tpCMk2laeIt_GzTe0Uxp=6N?A~5% zLT|r|`x|`&E*@xP23OJ z0?UE(C?8zhoUhpqD^ub;F|X8|x^CCXGxJmJtj@31R?VkXXZm)f>R6M8^?3g3-0amE zFTv0`@Cv-8`4APs@MKl1L8nmt{-ab0(^fU6@kpz?X{JeI;F}L}xz*{y#b%S@;a0bD z#A3Nzj(RO9S|&_wDfAmq#K+FL4zPv(iD&nResbeKZ!NsXJ%@Ps01qGHi32>bC%?s0 z?-SWw`5-Z|b@yGO?+;_^ZX?>gwdh^RV!oS4AY{$dE2LWY&QC>_X-EKks}U6mriuWO zO6ql!#L1jVn^tL5C?X&#jzzBl@L03Ys!VinuiAJDGNT$*NRHRf%(@qeSIf-`@j_K@ zHs79G^fs&`YQh-={1lWV=>vLnh#tA<(FZjBSw=lWFE4K;fu#BxIM!$f{|-l<&A-^# zS$Vm+#}4qUu&=*Z*qM1*aPc{?_M@Y_vWq8#aB~OBd+ZF`j}GsYU3}5=9NBr=^c0iA zF1{pOZ|z)j@wlg--(7R@*G<>g8@u|OUtN4f_}q97!iZq=&o^8=D%j1}nccvftc%YJ z>)Y2Cce~$QcJT#a`D;F#eGczh_IRQ<71)aXJDHZEpAo>POGru`qTB(>?Pm6d-=b^B KSeAOc)cp@wj6f6s literal 0 HcmV?d00001 diff --git a/api.iml b/api.iml new file mode 100644 index 0000000..63002b6 --- /dev/null +++ b/api.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/models.py b/models.py new file mode 100644 index 0000000..b47c7e8 --- /dev/null +++ b/models.py @@ -0,0 +1,59 @@ +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 \ No newline at end of file diff --git a/test.py b/test.py new file mode 100644 index 0000000..d120dff --- /dev/null +++ b/test.py @@ -0,0 +1,23 @@ +from sqlalchemy.orm import Session +from sqlalchemy import and_, or_, desc, asc + +from models import get_session, Ticker + + +def get_ticker(session: Session, contract: str): + return session.query(Ticker).filter(Ticker.contract == contract).limit(500).all() + +def get_ticker_count(session: Session, contract: str): + return session.query(Ticker).filter(Ticker.contract == contract).count() + +# 사용 예시 + +session = get_session() +try: + cnt = get_ticker_count(session, "BTC_USDT") + print(cnt) + tickers = get_ticker(session, "BTC_USDT") + for ticker in tickers: + print(ticker.clast) +finally: + session.close() \ No newline at end of file