-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMomentumScanner_techindicator.py
143 lines (117 loc) · 4.29 KB
/
MomentumScanner_techindicator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import sys
import time
import gecko
import metrics
import MomentumScanner
def token_technical_indicator_rsi(token):
df = gecko.market_chart(token, days=100)
prdiff = df["price"].diff().dropna()
prdiffpos = prdiff[prdiff >= 0]
prdiffneg = prdiff[prdiff < 0]
if len(prdiffpos) > 0:
gain_ema = prdiffpos.ewm(span=12, adjust=False).mean().iloc[-1]
else:
gain_ema = 0
if len(prdiffneg) > 0:
loss_ema = prdiffneg.ewm(span=12, adjust=False).mean().iloc[-1]
else:
loss_ema = 1
rs = gain_ema / loss_ema
rsi = 100 - (100 / (1 + rs))
return rsi
def get_sma(prices, length):
return prices.rolling(length).mean()
def get_bollinger_bands_last(prices, length):
sma = get_sma(prices, length)
std = prices.rolling(length).std()
bollinger_up = sma + std * 2 # Calculate top band
bollinger_down = sma - std * 2 # Calculate bottom band
return bollinger_up.iloc[-1], bollinger_down.iloc[-1]
def token_technical_indicator_bollingerband_updiff(token):
df = gecko.market_chart(token, days=100)
bollinger_up, bollinger_down = get_bollinger_bands_last(df["price"], length=7)
bb_updiff = df["price"].iloc[-1] - bollinger_down
bb_updiff = bb_updiff / df["price"].iloc[-1]
return bb_updiff
def add_technical_indicators(df, col_name):
# col_name = 'MACD_ratio'
df[col_name] = None
for i in df.index:
if col_name == "MACD_ratio":
indicator = metrics.token_technical_indicator_macd(i)
elif col_name == "RSI":
indicator = token_technical_indicator_rsi(i)
elif col_name == "BB_updiff":
indicator = token_technical_indicator_bollingerband_updiff(i)
df.loc[i, col_name] = indicator
# time.sleep(0.01)
return df
def getriskquery(token, stoploss=0.05, profittaking=0.05):
re = gecko.simple_price_1d([token])
price = re.json()[token]["usd"]
slprice = price * (1 - stoploss)
ptprice = price * (1 + profittaking)
print("enter at:", price, "stop-loss:", slprice, "profit-taking:", ptprice)
return slprice, ptprice
def findbestreturn(dex, stoploss, profittaking, col_name):
vols = gecko.exchanges(dex)
if len(vols) != 0:
vols = metrics.filter_pairs(vols, volume=150000)
if len(vols) == 0:
print("No pair found with enough volume")
return
else:
vols1 = vols # .iloc[1:]
else:
print("Endpoint issues, query did not get any returned values")
return
if vols.empty:
print("Currently no token satisfies the filtering conditions")
return
df = metrics.find_rets_24h(vols1)
techindicator_col = col_name
df = add_technical_indicators(df, col_name)
df = df[df[techindicator_col] > 0]
df = df.sort_values(by=techindicator_col, ascending=False)
hottoken = df.index[0]
time.sleep(1)
enterprice, sl, pt = metrics.get_trades(str(hottoken), stoploss, profittaking)
print(dex, " top winners: ", flush=True)
print(df[[techindicator_col]], flush=True)
print("* * * * *", flush=True)
print("Hottest token: ", flush=True)
print(hottoken, flush=True)
if enterprice != 0:
print("Enter at: ", enterprice, flush=True)
print(
"Stop-loss at: ", sl, " (stop loss percentage: ", stoploss, ")", flush=True
)
print(
"Profit-taking at: ",
pt,
" (profit taking percentage: ",
profittaking,
")",
flush=True,
)
else:
print(
"Enter price, stop-loss and profit-taking calculation failed due to endpoint issue",
flush=True,
)
print("* * * * *", flush=True)
print("liquidity profile: ", flush=True)
MomentumScanner.findliquidity(hottoken, dex)
print("----------------------------------------------", flush=True)
if __name__ == "__main__":
# findbestreturn(dex='pancakeswap_new', stoploss=0.05, profittaking=0.05,lag=6)
args = sys.argv
col_name = args[-1]
if len(args) == 2:
findbestreturn(
dex="pancakeswap_new", stoploss=0.05, profittaking=0.05, col_name=col_name
)
elif len(args) == 3:
findbestreturn(
dex=str(sys.argv[1]), stoploss=0.05, profittaking=0.05, col_name=col_name
)