Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified backend/__pycache__/function.cpython-38.pyc
Binary file not shown.
Binary file modified backend/__pycache__/home.cpython-38.pyc
Binary file not shown.
Binary file modified backend/__pycache__/init.cpython-38.pyc
Binary file not shown.
Binary file modified backend/__pycache__/position.cpython-38.pyc
Binary file not shown.
Binary file added backend/__pycache__/strategy.cpython-38.pyc
Binary file not shown.
49 changes: 27 additions & 22 deletions backend/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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})

1 change: 1 addition & 0 deletions backend/static/goto.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ header {
padding-left: 40px;
padding-bottom: 5px;
}

#img_setting {
float: right;
width: 35px;
Expand Down
7 changes: 3 additions & 4 deletions backend/static/home.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ main {
margin-left: 15px;
}

#section_input input {
#section_input .input_info {
width: 130px;
height: 30px;
border-radius: 10px;
Expand Down Expand Up @@ -73,8 +73,6 @@ main {
text-align: center;
}



#enter:hover {
box-shadow: 3px 4px 11px 0px #00000040;
}
Expand All @@ -91,6 +89,7 @@ main {
overflow: hidden;
background: rgba(0,0,0,0.5);
}

.modal #detail_popup {
/*팝업*/
position: absolute;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions backend/static/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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(){
Expand Down
Binary file added backend/static/img/history.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/static/img/history2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified backend/strategys/__pycache__/env.cpython-38.pyc
Binary file not shown.
Binary file modified backend/strategys/__pycache__/function.cpython-38.pyc
Binary file not shown.
Binary file modified backend/strategys/__pycache__/init.cpython-38.pyc
Binary file not shown.
Binary file modified backend/strategys/__pycache__/strategy.cpython-38.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion backend/strategys/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 값
################################
Expand Down
160 changes: 151 additions & 9 deletions backend/strategys/strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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----")
Expand All @@ -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]
Expand All @@ -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)
time.sleep(1)
Loading