-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.py
49 lines (38 loc) · 1.3 KB
/
index.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
import config
import os
import requests
import json
import base64
import ccxt
import ast
"""Telegram Bot:"""
def tg_send_mess(bm):
btoken = config.BOT_TOKEN
bchat = config.CHAT_ID
send = 'https://api.telegram.org/bot'+btoken+'/sendMessage?chat_id='+bchat+'&text='+bm+''
resp = requests.get(send)
return resp.json()
"""Decoding Message:"""
def run(event, context):
try:
"""Decoding from TreadingView Format:"""
mess = base64.b64decode(event['body']).decode('utf-8')
s = mess.replace("'", "\"")
d = ast.literal_eval(s)
pare = d['pare']
direct = d['direction']
pos = d['position']
# pos = round(float(d['position']),0)
"""Sedning Order to Exhcange:"""
exchange = ccxt.binance({"apiKey": config.apiKey, "secret": config.secret,'options': {'defaultType': 'future'}})
if direct == 'buy':
exchange.create_market_buy_order(symbol=pare, amount=pos)
if direct == 'sell':
exchange.create_market_sell_order(symbol=pare, amount=pos)
"""Telegram Message:"""
tg_send_mess(mess)
"""Checking for Errors:"""
r = {'statusCode': 200, 'body': 'Message sent!'}
except Exception as e:
r = {'statusCode': 404, 'body': 'Some error!'}
return r