diff --git a/backend/__pycache__/function.cpython-38.pyc b/backend/__pycache__/function.cpython-38.pyc index e0789c6..30111a6 100644 Binary files a/backend/__pycache__/function.cpython-38.pyc and b/backend/__pycache__/function.cpython-38.pyc differ diff --git a/backend/__pycache__/home.cpython-38.pyc b/backend/__pycache__/home.cpython-38.pyc index 9e2455e..ce184c5 100644 Binary files a/backend/__pycache__/home.cpython-38.pyc and b/backend/__pycache__/home.cpython-38.pyc differ diff --git a/backend/__pycache__/init.cpython-38.pyc b/backend/__pycache__/init.cpython-38.pyc index f39e32a..e9c3d9c 100644 Binary files a/backend/__pycache__/init.cpython-38.pyc and b/backend/__pycache__/init.cpython-38.pyc differ diff --git a/backend/__pycache__/position.cpython-38.pyc b/backend/__pycache__/position.cpython-38.pyc index 5e9887e..23288bf 100644 Binary files a/backend/__pycache__/position.cpython-38.pyc and b/backend/__pycache__/position.cpython-38.pyc differ diff --git a/backend/__pycache__/strategy.cpython-38.pyc b/backend/__pycache__/strategy.cpython-38.pyc new file mode 100644 index 0000000..a6fab68 Binary files /dev/null and b/backend/__pycache__/strategy.cpython-38.pyc differ diff --git a/backend/home.py b/backend/home.py index ddbd871..863da55 100644 --- a/backend/home.py +++ b/backend/home.py @@ -7,8 +7,8 @@ from strategys.position import enter_position, exit_position from strategys.function import get_cur_price, get_balance, dataFrame, calAmount, VolatilityBreakout, get_symbol_info from strategys.env import profit_percent, loss_percent, purchase_percent, con_diffma40_4, timeframe, symbols, k -from strategys.strategy import strategy_1 - +from strategys.strategy import strategy_1, strategy_2, strategy_3 +import subprocess import time app = FastAPI() @@ -37,29 +37,34 @@ async def init(request: Request): return templates.TemplateResponse("home.html", {"request": request}) -@app.post("/home", response_class=HTMLResponse) -async def home(request: Request, symbol : str = Form(...), perchase_percent : str = Form(...), leverage : str = Form(...)): - print(symbol) - print(perchase_percent) - print(leverage) - return templates.TemplateResponse("home.html", {"request": request, "symbol":symbol, "perchase_percent":perchase_percent, "leverage":leverage}) - - -@app.get("/ETC") -def ETC(): - return {"message":"ETC"} +@app.get("/home", response_class=HTMLResponse) +async def home(request: Request): + return templates.TemplateResponse("home.html", {"request": request}) -@app.get("/symbols") -def symbols(): - return {"message":"symbols"} +@app.post("/enter_position", response_class=HTMLResponse) +async def enter_position(request: Request, symbol: str = Form(...), purchase_percent: float = Form(...), leverage: int = Form(...), strategys:str = Form(...)): + if strategys == "strategy_1": + strategy_1(symbol, purchase_percent, leverage) + elif strategys == "strategy_2": + strategy_2(symbol, purchase_percent, leverage) + elif strategys == "strategy_3": + strategy_3(symbol, purchase_percent, leverage) + + return templates.TemplateResponse("home.html", {"request": request}) -@app.get("/receipt") -def receipt(): - return {"message":"receipt"} +@app.get("/goto", response_class=HTMLResponse) +async def goto(request: Request): + return templates.TemplateResponse("goto.html", {"request": request}) -@app.get("/mypage") -def mypage(): - return {"message":"mypage"} +@app.get("/symbols_info", response_class=HTMLResponse) +async def symbols_info(request: Request): + return templates.TemplateResponse("symbols_info.html", {"request": request}) +@app.get("/history", response_class=HTMLResponse) +def history(request: Request): + return templates.TemplateResponse("history.html", {"request": request}) +@app.get("/mypage", response_class=HTMLResponse) +def mypage(request: Request): + return templates.TemplateResponse("mypage.html", {"request": request}) diff --git a/backend/static/goto.css b/backend/static/goto.css index 4d0e3fe..85800c5 100644 --- a/backend/static/goto.css +++ b/backend/static/goto.css @@ -9,6 +9,7 @@ header { padding-left: 40px; padding-bottom: 5px; } + #img_setting { float: right; width: 35px; diff --git a/backend/static/home.css b/backend/static/home.css index 3033f35..7ea069e 100644 --- a/backend/static/home.css +++ b/backend/static/home.css @@ -43,7 +43,7 @@ main { margin-left: 15px; } -#section_input input { +#section_input .input_info { width: 130px; height: 30px; border-radius: 10px; @@ -73,8 +73,6 @@ main { text-align: center; } - - #enter:hover { box-shadow: 3px 4px 11px 0px #00000040; } @@ -91,6 +89,7 @@ main { overflow: hidden; background: rgba(0,0,0,0.5); } + .modal #detail_popup { /*팝업*/ position: absolute; @@ -101,7 +100,7 @@ main { background: #ffffff; border-radius: 20px; } -.modal_btn_container { +.modal_btn_container form { display: flex; flex-direction: row; justify-content: space-around; diff --git a/backend/static/home.js b/backend/static/home.js index be2fafe..b332884 100644 --- a/backend/static/home.js +++ b/backend/static/home.js @@ -7,7 +7,7 @@ document.addEventListener("DOMContentLoaded", function() { function update_description() { const symbol = document.getElementById('symbol').value; - const purchase_percent = document.getElementById('perchase_percent').value; + const purchase_percent = document.getElementById('purchase_percent').value; const leverage = document.getElementById('leverage').value; const strategy = document.getElementById('strategy').value; @@ -59,7 +59,7 @@ document.getElementById('strategy').addEventListener('change', update_descriptio document.addEventListener("DOMContentLoaded", function() { const modal = document.querySelector('.modal'); const modalOpen = document.querySelector('#enter'); - const modalClose = document.querySelector('#close_detail'); + const modalClose = document.querySelector('#no_detail'); // Open modal when the button is clicked modalOpen.addEventListener('click', function(){ diff --git a/backend/static/img/history.png b/backend/static/img/history.png new file mode 100644 index 0000000..6006da4 Binary files /dev/null and b/backend/static/img/history.png differ diff --git a/backend/static/img/history2.png b/backend/static/img/history2.png new file mode 100644 index 0000000..a396cb5 Binary files /dev/null and b/backend/static/img/history2.png differ diff --git a/backend/strategys/__pycache__/env.cpython-38.pyc b/backend/strategys/__pycache__/env.cpython-38.pyc index 0909b63..6f19bf6 100644 Binary files a/backend/strategys/__pycache__/env.cpython-38.pyc and b/backend/strategys/__pycache__/env.cpython-38.pyc differ diff --git a/backend/strategys/__pycache__/function.cpython-38.pyc b/backend/strategys/__pycache__/function.cpython-38.pyc index 3e4ffd4..0e83867 100644 Binary files a/backend/strategys/__pycache__/function.cpython-38.pyc and b/backend/strategys/__pycache__/function.cpython-38.pyc differ diff --git a/backend/strategys/__pycache__/init.cpython-38.pyc b/backend/strategys/__pycache__/init.cpython-38.pyc index cf05ed5..cdcb7dd 100644 Binary files a/backend/strategys/__pycache__/init.cpython-38.pyc and b/backend/strategys/__pycache__/init.cpython-38.pyc differ diff --git a/backend/strategys/__pycache__/strategy.cpython-38.pyc b/backend/strategys/__pycache__/strategy.cpython-38.pyc index 46a7244..dbae911 100644 Binary files a/backend/strategys/__pycache__/strategy.cpython-38.pyc and b/backend/strategys/__pycache__/strategy.cpython-38.pyc differ diff --git a/backend/strategys/env.py b/backend/strategys/env.py index a0e20e7..5a5d004 100644 --- a/backend/strategys/env.py +++ b/backend/strategys/env.py @@ -9,7 +9,7 @@ purchase_percent = 0.5 # 50% con_diffma40_4 = 7 # 횡보 조건 timeframe = "15m" -symbols = ["ETH/USDT"] # 이더리움 +symbols = "ETH/USDT" # 이더리움 k = 0.5 # VB K 값 ################################ diff --git a/backend/strategys/strategy.py b/backend/strategys/strategy.py index 7a19ef1..77a470e 100644 --- a/backend/strategys/strategy.py +++ b/backend/strategys/strategy.py @@ -4,6 +4,8 @@ from .function import get_cur_price, get_balance, dataFrame, calAmount, VolatilityBreakout from .env import profit_percent, loss_percent, purchase_percent, con_diffma40_4, timeframe, symbols, k + + def print_info(df, long_target, short_target, cur_price, diffma40_4, position, entry_price): print("=================================ETH/USDT=============================================") print("----BASE----") @@ -25,29 +27,169 @@ def print_info(df, long_target, short_target, cur_price, diffma40_4, position, e print(f"short profit end : {entry_price - entry_price * profit_percent} /// {cur_price} => {entry_price - entry_price * profit_percent > cur_price}") print(f"short loss end : {entry_price + entry_price * loss_percent} /// {cur_price} => {entry_price + entry_price * loss_percent < cur_price}") +def set_leverage(symbol, leverage=1): + # leverage 설정 + markets = binance.load_markets() + market = binance.market(symbol) + resp = binance.fapiprivate_post_leverage({ + "symbol":market["id"], + "leverage":leverage + }) + +def strategy_1(symbol = symbols, purchase_percent=purchase_percent, leverage=1): + # while(True): + entry_price = 0 + position = { + "type":None, + "amount":0 + } + set_leverage(symbol, leverage) + for _ in range(5): + # 현재가 + cur_price = get_cur_price(symbol) + + # 잔고 + balance = get_balance() + + # dataFrame + df = dataFrame(symbol) + + # 구매 수량 + amount = calAmount(balance, cur_price, purchase_percent) # 50% + + # 변동성 돌파전략 + long_target, short_target = VolatilityBreakout(dataFrame(symbol)) + + # sma 설정 + sma4 = df["sma4"].iloc[-1] + sma8 = df["sma8"].iloc[-1] + sma30 = df["sma30"].iloc[-1] + sma40 = df["sma40"].iloc[-1] + diffma40_4 = df["diffMa40_4"].iloc[-1] + + # long position 진입 조건 + is_long = ((sma4 > sma30) & (cur_price > long_target) & (diffma40_4 > con_diffma40_4) & (position["type"] == None)) + # short position 진입 조건 + is_short = ((sma4 < sma30) & (cur_price < short_target) & (diffma40_4 > con_diffma40_4) & (position["type"] == None)) + + # long position 청산 조건 + is_long_end = (((entry_price + entry_price * profit_percent < cur_price) and position["type"] == "long") or ((entry_price - entry_price * loss_percent > cur_price) and position["type"] == "long") ) + # short position 청산 조건 + is_short_end = (((entry_price - entry_price * profit_percent > cur_price) and position["type"] == "short") or ((entry_price + entry_price * loss_percent < cur_price) and position["type"] =="short")) + # print(df) + # position 진입 + if is_long: + entry_price = cur_price + print_info(df, long_target, short_target, cur_price, diffma40_4, position, entry_price) + enter_position(binance, symbol=symbol, cur_price = cur_price, amount=amount, target=1, position=position) + + if is_long_end: + print_info(df, long_target, short_target, cur_price, diffma40_4, position, entry_price) + exit_position(binance, symbol=symbol, cur_price=cur_price, amount = position["amount"], position=position) + + + if is_short: + entry_price = cur_price + print_info(df, long_target, short_target, cur_price, diffma40_4, position, entry_price) + enter_position(binance, symbol=symbol, cur_price = cur_price, amount=amount, target=-1, position=position) + + if is_short_end: + print_info(df, long_target, short_target, cur_price, diffma40_4, position, entry_price) + exit_position(binance, symbol=symbol, cur_price=cur_price, amount = position["amount"], position=position) + + else: + print_info(df, long_target, short_target, cur_price, diffma40_4, position, entry_price) + time.sleep(1) + +def strategy_2(symbol = symbols, purchase_percent=purchase_percent, leverage=1): + # while(True): + entry_price = 0 + position = { + "type":None, + "amount":0 + } + set_leverage(symbol, leverage) + for _ in range(5): + # 현재가 + cur_price = get_cur_price(symbol) + + # 잔고 + balance = get_balance() + + # dataFrame + df = dataFrame(symbol) + + # 구매 수량 + amount = calAmount(balance, cur_price, purchase_percent) # 50% + + # 변동성 돌파전략 + long_target, short_target = VolatilityBreakout(dataFrame(symbol)) + + # sma 설정 + sma4 = df["sma4"].iloc[-1] + sma8 = df["sma8"].iloc[-1] + sma30 = df["sma30"].iloc[-1] + sma40 = df["sma40"].iloc[-1] + diffma40_4 = df["diffMa40_4"].iloc[-1] + + # long position 진입 조건 + is_long = ((sma4 > sma30) & (cur_price > long_target) & (diffma40_4 > con_diffma40_4) & (position["type"] == None)) + # short position 진입 조건 + is_short = ((sma4 < sma30) & (cur_price < short_target) & (diffma40_4 > con_diffma40_4) & (position["type"] == None)) + + # long position 청산 조건 + is_long_end = (((entry_price + entry_price * profit_percent < cur_price) and position["type"] == "long") or ((entry_price - entry_price * loss_percent > cur_price) and position["type"] == "long") ) + # short position 청산 조건 + is_short_end = (((entry_price - entry_price * profit_percent > cur_price) and position["type"] == "short") or ((entry_price + entry_price * loss_percent < cur_price) and position["type"] =="short")) + # print(df) + # position 진입 + if is_long: + entry_price = cur_price + print_info(df, long_target, short_target, cur_price, diffma40_4, position, entry_price) + enter_position(binance, symbol=symbol, cur_price = cur_price, amount=amount, target=1, position=position) + + if is_long_end: + print_info(df, long_target, short_target, cur_price, diffma40_4, position, entry_price) + exit_position(binance, symbol=symbol, cur_price=cur_price, amount = position["amount"], position=position) + + + if is_short: + entry_price = cur_price + print_info(df, long_target, short_target, cur_price, diffma40_4, position, entry_price) + enter_position(binance, symbol=symbol, cur_price = cur_price, amount=amount, target=-1, position=position) + + if is_short_end: + print_info(df, long_target, short_target, cur_price, diffma40_4, position, entry_price) + exit_position(binance, symbol=symbol, cur_price=cur_price, amount = position["amount"], position=position) + + else: + print_info(df, long_target, short_target, cur_price, diffma40_4, position, entry_price) + time.sleep(1) + -def strategy_1(): +def strategy_3(symbol = symbols, purchase_percent=purchase_percent, leverage=1): # while(True): entry_price = 0 position = { "type":None, "amount":0 } + set_leverage(symbol, leverage) for _ in range(5): # 현재가 - cur_price = get_cur_price(symbols[0]) + cur_price = get_cur_price(symbol) # 잔고 balance = get_balance() # dataFrame - df = dataFrame(symbols[0]) + df = dataFrame(symbol) # 구매 수량 amount = calAmount(balance, cur_price, purchase_percent) # 50% # 변동성 돌파전략 - long_target, short_target = VolatilityBreakout(dataFrame(symbols[0])) + long_target, short_target = VolatilityBreakout(dataFrame(symbol)) # sma 설정 sma4 = df["sma4"].iloc[-1] @@ -70,22 +212,22 @@ def strategy_1(): if is_long: entry_price = cur_price print_info(df, long_target, short_target, cur_price, diffma40_4, position, entry_price) - enter_position(binance, symbol=symbols[0], cur_price = cur_price, amount=amount, target=1, position=position) + enter_position(binance, symbol=symbol, cur_price = cur_price, amount=amount, target=1, position=position) if is_long_end: print_info(df, long_target, short_target, cur_price, diffma40_4, position, entry_price) - exit_position(binance, symbol=symbols[0], cur_price=cur_price, amount = position["amount"], position=position) + exit_position(binance, symbol=symbol, cur_price=cur_price, amount = position["amount"], position=position) if is_short: entry_price = cur_price print_info(df, long_target, short_target, cur_price, diffma40_4, position, entry_price) - enter_position(binance, symbol=symbols[0], cur_price = cur_price, amount=amount, target=-1, position=position) + enter_position(binance, symbol=symbol, cur_price = cur_price, amount=amount, target=-1, position=position) if is_short_end: print_info(df, long_target, short_target, cur_price, diffma40_4, position, entry_price) - exit_position(binance, symbol=symbols[0], cur_price=cur_price, amount = position["amount"], position=position) + exit_position(binance, symbol=symbol, cur_price=cur_price, amount = position["amount"], position=position) else: print_info(df, long_target, short_target, cur_price, diffma40_4, position, entry_price) - time.sleep(1) \ No newline at end of file + time.sleep(1) diff --git a/backend/templates/goto.html b/backend/templates/goto.html index cc7de6f..a90f240 100644 --- a/backend/templates/goto.html +++ b/backend/templates/goto.html @@ -2,31 +2,98 @@ 코인 전략 선택 - + - + + -
- Bit4Coin - -
-
- - - - -
- - - - +
+ Bit4Coin + +
+
+
+
+ + + +
Binance
+
+
+ + + +
TradingView
+
+
+ +
History
+
+
+ + + +
GitHub
+
+
+
+ - diff --git a/backend/templates/history.html b/backend/templates/history.html new file mode 100644 index 0000000..3b7c967 --- /dev/null +++ b/backend/templates/history.html @@ -0,0 +1,30 @@ + + + + 코인 전략 선택 + + + + + +
+ Bit4Coin + +
+
+ + +
+ + + + + + + diff --git a/backend/templates/home.html b/backend/templates/home.html index 6a8545e..38c3bf3 100644 --- a/backend/templates/home.html +++ b/backend/templates/home.html @@ -3,8 +3,86 @@ 코인 전략 선택 - + +
@@ -20,14 +98,14 @@ -
- -
-
- - - - +
+
+ +
+ + + +
- +
- -
+
+ -
-
-
- -
- - - - + + diff --git a/backend/templates/mypage.html b/backend/templates/mypage.html new file mode 100644 index 0000000..3b7c967 --- /dev/null +++ b/backend/templates/mypage.html @@ -0,0 +1,30 @@ + + + + 코인 전략 선택 + + + + + +
+ Bit4Coin + +
+
+ + +
+ + + + + + + diff --git a/backend/templates/symbols_info.html b/backend/templates/symbols_info.html new file mode 100644 index 0000000..3b7c967 --- /dev/null +++ b/backend/templates/symbols_info.html @@ -0,0 +1,30 @@ + + + + 코인 전략 선택 + + + + + +
+ Bit4Coin + +
+
+ + +
+ + + + + + +