visit
As a trader, you might wonder how you can take your trading to the next level. The
If you’re familiar with 3Commas, then you know that it’s a platform for trading with bots. You connect your favorite exchange to your 3Commas dashboard account, and you can automate much of the research and trading that takes hours to do manually. The platform also has an API that can be used in conjunction with the LunarCrush API. LunarCrush serves as your automated research tool, and the 3Commas API serves as a way to take botted action when the LunarCrush research reaches specific thresholds that you determine and design in your scripted bot.
In this example, we’ll use Galaxy Score, which is a score calculated from several social and price metrics. You can read about the other
Galaxy score™ is a combination of four metrics — the price score, social impact score, average sentiment, and correlation rank. It measures the relative price appreciation between current and previous interval MACD (moving average convergence divergence), engagement and impact across various social media platforms, average sentiment classified by our machine-learning engines, and correlation of social media volumes and spam to price and volume. The metrics are aggregated and normalized to a scale of 100.
To understand more about why you would use Galaxy Score to guide your trades, check out the
Using Galaxy Score, a trader could identify the top crypto opportunities for several assets and trigger trades on the 3Commas platform. You first retrieve the top opportunities via the LunarCrush API endpoint and then use the
We’ll be using Python as our scripting language, but you can see several other language examples in the
The sort and limit parameters can be used on the coin endpoint to perform the query. Since the galaxy_score sort value sorts with the most popular asset first, you can use it with a limit value of “2” to get the top two assets. The following code snippet uses the API to pull the top 2 coins based on their Galaxy Score and prints them to the screen:
import requests
import json
# Define the URL for lunarcrush and set the authorization header.
# This header is standard when passing keys to an API and must be present to
# successfully execute queries against the API.
apiUrl = "//lunarcrush.com/api3/coins?sort=galaxy_score&limit=2"
headers = {"Authorization":"Bearer <your_api_keys>"}
response = requests.request("GET", apiUrl, headers=headers)
print(json.dumps(response.json(), indent=2))
The print command displays:
{
"data": [
{
"id": 72743,
"s": "SUZUME",
"n": "Shita-Kira Suzume",
"p": 3.8585999e-06,
"v": 400666.64,
"pc": -8.82,
"pch": -3.15,
"mc": 0,
"gs": 68,
"gs_p": 48,
"ss": 824467,
"as": 3.3546,
"sv": 1261,
"c": 79,
"sd": 0.20536,
"d": 0,
"acr": 750,
"acr_p": 30,
"tc": 1660255200,
"categories": "defi,erc20,meme"
},
{
"id": 483,
"s": "BOMB",
"n": "BOMB",
"p": 0.21063406,
"v": 131720.37,
"pc": 8.72,
"pch": -0.88,
"mc": 172195,
"gs": 67,
"gs_p": 36.5,
"ss": 186953,
"as": 3.7999999999999994,
"sv": 60,
"c": 5,
"sd": 0.005897728801816271,
"d": 1.70778e-05,
"acr": 160,
"acr_p": 428,
"tc": 1567036800,
"categories": ""
}
]
}
import requests
import json
# Define the URL for lunarcrush and set the authorization header.
# This header is standard when passing keys to an API and must be present to
# successfully execute queries against the API.
apiUrl = "//lunarcrush.com/api3/coins?sort=galaxy_score&limit=2"
headers = {"Authorization":"Bearer <your_api_keys>"}
response = requests.request("GET", apiUrl, headers=headers)
res = response.json()
print(json.dumps(response.json(), indent=2))
# Loop through each coin in the response
for coin in res['data']:
print("name: ", coin['s'])
print("galaxy score: ", coin['gs'])
import requests
import json
import os
from py3cw.request import Py3CW
p3cw = Py3CW(
key='<your_3commas_key>',
secret='<your_3commas_secret>',
request_options={
'request_timeout': 10,
'nr_of_retries': 1,
'retry_status_codes': [502]
}
)
# Define the URL for lunarcrush and set the authorization header.
# This header is standard when passing keys to an API and must be present to
# successfully execute queries against the API.
apiUrl = "//lunarcrush.com/api3/coins?sort=galaxy_score&limit=2"
headers = {"Authorization":"Bearer <your_api_keys>"}
response = requests.request("GET", apiUrl, headers=headers)
res = response.json()
# Loop through each coin in the response
for coin in res['data']:
# Send the coin information to 3Commas and make a purchase
error, data = p3cw.request(
entity='smart_trades_v2',
action='new',
payload={
"account_id": your_account_id,
"pair": "<your_pair>",
"instant": "true",
"position": {
"type": "buy",
"units": {
"value": "0.01"
},
"order_type": "market"
}
}
)
In this code snippet, the p3cw 3Commas wrapper simplifies all the calls to the API. The “entity” can be one of several listed in the
import requests
import json
import os
from py3cw.request import Py3CW
p3cw = Py3CW(
key='<your_3commas_key>',
secret='<your_3commas_secret>',
request_options={
'request_timeout': 10,
'nr_of_retries': 1,
'retry_status_codes': [502]
}
)
# Define the URL for lunarcrush and set the authorization header.
# This header is standard when passing keys to an API and must be present to
# successfully execute queries against the API.
apiUrl = "//lunarcrush.com/api3/coins?sort=galaxy_score&limit=50"
headers = {"Authorization":"Bearer <your_api_keys>"}
response = requests.request("GET", apiUrl, headers=headers)
res = response.json()
# Loop through each coin in the response
for coin in res['data']:
# The chosen filter is to only work with coins in the NFT category,
# so eliminate anything that isn't an NFT
# You can use any filter you want from the LunarCrush categories
if coin['categories'].find('nft') > -1:
# Send the coin information to 3Commas and make a purchase
error, data = p3cw.request(
entity='smart_trades_v2',
action='new',
payload={
"account_id": your_account_id,
"pair": "<your_pair>",
"instant": "true",
"position": {
"type": "buy",
"units": {
"value": "0.01"
},
"order_type": "market"
}
}
)
{
id: 11880 LunarCrush internal ID for the asset,
s: RAY symbol,
n: Raydium Protocol name,
p: 0.65456285 Price,
v: 27393233.82 Volume (USD),
pc: 6.9 Percent change (24 Hours),
pch: -1.04 Percent change (1 Hour),
mc: 87523220 Market cap,
gs: 70.5 Galaxy ScoreTM,
gs_p: 40.5 Galaxy ScoreTM previous 24h,
ss: 59960 Social score/engagement,
as: 4.0296 Average sentiment - using a scoring system from 1 to 5 with 1 being very bearish and 5 being very bullish,
sv: 63 Social volume/mentions,
c: 14 Social contributors (24 hours),
sd: 0.0701735 Social dominance,
d: 0.0084609 Market dominance,
acr: 198 ALTRankTM,
acr_p: 515 ALTRankTM previous 24h,
tc: 1619553600 Time created,
categories: defi, solana,
}
import requests
import json
import os
from py3cw.request import Py3CW
p3cw = Py3CW(
key='<your_3commas_key>',
secret='<your_3commas_secret>',
request_options={
'request_timeout': 10,
'nr_of_retries': 1,
'retry_status_codes': [502]
}
)
# Define the URL for lunarcrush and set the authorization header.
# This header is standard when passing keys to an API and must be present to
# successfully execute queries against the API.
apiUrl = "//lunarcrush.com/api3/coins?sort=galaxy_score&limit=50&desc=1"
headers = {"Authorization":"Bearer <your_api_keys>"}
response = requests.request("GET", apiUrl, headers=headers)
res = response.json()
# Loop through each coin in the response
for coin in res['data']:
# The chosen filter is to only work with coins in the NFT category,
# so eliminate anything that isn't an NFT
# You can use any filter you want from the LunarCrush categories
if coin['categories'].find('nft') > -1:
# Send the coin information to 3Commas and make a purchase
error, data = p3cw.request(
entity='smart_trades_v2',
action='new',
payload={
"account_id": your_account_id,
"pair": "<your_pair>",
"instant": "true",
"position": {
"type": "buy",
"units": {
"value": "0.01"
},
"order_type": "market"
}
}
)
Try out both code snippets to see the difference in your dataset. We limit it to 50 coins, but you can leave the parameter empty to return all coins or limit your dataset even further.**
**
Building with LunarCrush introduces opportunities that you might not know without hours of research and constant monitoring. Let LunarCrush help you simplify and automate your discovery process, and use it to automate trades against any bot interface.
Check out what’s happening in the market__ now, or