-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrpy.py
More file actions
55 lines (54 loc) · 2.78 KB
/
crpy.py
File metadata and controls
55 lines (54 loc) · 2.78 KB
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
import time, random, re, os
import pandas as pd
from datetime import datetime, timedelta, timezone
from javascript import require
lCh=[]; lSt=[]; sFile='c, s, d, dt\n'
tv=require('@mathieuc/tradingview')
tkn=os.environ.get('TV_TKN'); sig=os.environ.get('TV_SG')
print(f'____________tkn={tkn}')
tkn='k52ysq6gal51s6sn49cuztekseq06hyb'; sig='v3:nZQsJn1kRRGzrJ+V7U6bxxVIs/NNOjQkLqD/3XQCJas='
# print(tv)
c=tv.Client({'token': tkn, 'signature': sig}); time.sleep(1)
ch = c.Session.Chart()
# print(ch)
lCh.append(ch)
ch.setMarket('BINANCE:BTCUSDT', { 'timeframe': '15' }); time.sleep(1)
arCo=['BINANCE:BTCUSDT', 'BINANCE:ETHUSDT']
lim=3; tf='15';
arCo=['BINANCE:BTCUSDT', 'BINANCE:ETHUSDT', 'BINANCE:SOLUSDT', 'BINANCE:XRPUSDT', 'BINANCE:BNBUSDT', 'BINANCE:ADAUSDT', 'BINANCE:LINKUSDT', 'BINANCE:XLMUSDT', 'BINANCE:BCHUSDT', 'BINANCE:LTCUSDT', 'BINANCE:UNIUSDT', 'BINANCE:AAVEUSDT']; random.shuffle(arCo)
lSt.append('PUB;ut1T8n2nhY3cjgArO4iFqk4n0M9ssI1d') # ZigZag++ by DevLucem
# lSt.append('STD;Zig_Zag')
arB=[]
try:
# for i1 in range(0, len(lSt) - 1, 2):
for i1 in range(0, 1):
std=lSt[i1]; # std2=lSt[i1 + 1]
ch = c.Session.Chart()
ch.setMarket('BINANCE:BTCUSDT', { 'timeframe': tf }); time.sleep(1)
z =tv.getIndicator(std, 'last'); # z2=tv.getIndicator(std2, 'last'); time.sleep(1)
# print([z.description, z2.description])
print([z.description])
if re.findall(r'(?i)ZigZag\+\+', z.description): z.setOption('in_10', False) # !repaint
#if re.findall(r'(?i)ZigZag\+\+', z2.description): z2.setOption('in_10', False) # !repaint
s =ch.Study(z); #s2=ch.Study(z2); time.sleep(1)
for cn in arCo:
ch.setMarket(cn, { 'timeframe': tf }); time.sleep(1)
for i in range(0, lim):
v1 = {} if str(type( s.periods[i])) == "<class 'NoneType'>" else s.periods[i].valueOf()
#v2 = {} if str(type(s2.periods[i])) == "<class 'NoneType'>" else s2.periods[i].valueOf()
cc = ch.infos['name'] if str(type(ch.infos['base_currency'])) == "<class 'NoneType'>" else ch.infos['base_currency']
cc=re.sub('USDT?$', '',cc)
# vv = {**v1, **v2}
vv = {**v1}
# print(vv)
# if (i in [1]) and ( re.findall(r'(?i)ZigZag\+\+', z.description+' '+z2.description) ):
if (i in [1]) and ( re.findall(r'(?i)ZigZag\+\+', z.description ) ):
if int(vv['New_Higher_Low']) ==1: arB.append({'c': cc, 's': 'zz_hl', 'd':'long'})
if int(vv['New_Lower_Low']) ==1: arB.append({'c': cc, 's': 'zz_ll', 'd':'long'})
if int(vv['New_Higher_High'])==1: arB.append({'c': cc, 's': 'zz_hh', 'd':'short'})
if int(vv['New_Lower_High']) ==1: arB.append({'c': cc, 's': 'zz_lh', 'd':'short'})
for i, r in pd.DataFrame(arB).drop_duplicates().iterrows():
ss=f"{r['c']}, {r['s']}, {r['d']}, {datetime.now()}"; sFile+=f'{ss}\n'; print(f'- {ss}')
with open('crp.csv', 'w') as f: f.write(sFile)
except Exception as e:
print(e)