-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjupiter-jlp.py
75 lines (58 loc) · 2.29 KB
/
jupiter-jlp.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
# oracle_discord_bot.py
# pip3 install python-dotenv discord.py
# .env
# DISCORD_TOKEN=<YOURTOKEN>
import os
import requests
import discord
from dotenv import load_dotenv
from web3 import Web3
import json
import time
import decimal
#Input Token Priced against Stable
inputToken = "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4"
outputToken = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
amountIn = "1000000"
#Priced against SOL
outputNativeToken = "So11111111111111111111111111111111111111112"
amountInputIn = "1000000"
decimalsNative = 1000000000
decimalsStable = 1000000
decimalsToken = 1000000
url = "https://quote-api.jup.ag/v6/quote?outputMint="+outputToken+"&inputMint="+inputToken+"&amount="+amountIn+"&slippage=0.2"
urlNative = "https://quote-api.jup.ag/v6/quote?outputMint="+outputNativeToken+"&inputMint="+inputToken+"&amount="+amountInputIn+"&slippage=0.2"
payload = {}
headers = {
'Accept': 'application/json'
}
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN_JUPITER_JLP')
client = discord.Client()
@client.event
async def on_ready():
print(f'{client.user} has connected to Discord!')
while True:
for guild in client.guilds:
#while True:
response = requests.request("GET", url, headers=headers, data=payload)
responseNative = requests.request("GET", urlNative, headers=headers, data=payload)
#print(response.text)
#print(response.json())
responsePrice = json.dumps(response.json())
resp = json.loads(responsePrice)
priceValue = (resp['outAmount'])
finalValue = decimal.Decimal(priceValue)/decimalsStable
print(finalValue)
responsePriceNative = json.dumps(responseNative.json())
respNative = json.loads(responsePriceNative)
priceValueNative = (respNative['outAmount'])
finalValueNative = decimal.Decimal(priceValueNative)/decimalsNative
print(finalValueNative)
botPrice = "JLP $" + str(finalValue)
botPriceNative = "SOL " + str(finalValueNative)
await guild.me.edit(nick=botPrice)
await client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name=botPriceNative ))
# time.sleep(5)
time.sleep(10)
client.run(TOKEN)