-
Notifications
You must be signed in to change notification settings - Fork 0
/
tbot2.py
77 lines (44 loc) · 1.57 KB
/
tbot2.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
from websocket import create_connection
import json
import time
import os
import schedule
import telebot
from telebot import types
bot = telebot.TeleBot('your bot token')
totalsell = 0
totalbuy = 0
maxsell = 0
maxbuy = 0
def datareset() :
totalsell = 0
totalbuy = 0
maxsell = 0
maxbuy = 0
schedule.every().day.at("00:00").do(datareset)
clear = lambda: os.system('clear')
ws = create_connection("wss://api-pub.bitfinex.com/ws/2")
ws.connect("wss://api-pub.bitfinex.com/ws/2")
ws.send('{ "event": "subscribe", "channel": "trades", "symbol": "tBTCUSD"}')
while True:
schedule.run_pending()
result = ws.recv()
result = json.loads(result)
if (len(result)) > 2 and (len(result)) < 4 :
os.system('clear')
if result[2][2] < 0 :
totalsell = totalsell+result[2][2]
if maxsell > result[2][2] :
maxsell = result[2][2]
if result[2][2] > 0 :
totalbuy = totalbuy+result[2][2]
if maxbuy < result[2][2] :
maxbuy = result[2][2]
if result[2][2]>=10 or result[2][2] <=-10 :
bot.send_message(chat_id='your channel id', text='deal volume : '+str(result[2][2])+' price : '+str(result[2][3]))
bot.send_message(chat_id='your channel id', text='totalbuy : '+str(totalbuy)+' totalsell : '+str(totalsell))
print('totalbuy : ',totalbuy,'totalsell : ',totalsell)
print('maxbuy : ',maxbuy,'maxsell : ',maxsell)
print('last deal ','size : ',result[2][2],'price : ',result[2][3])
bot.polling()
ws.close()