Skip to content

Commit

Permalink
sniper update for apt coin listing
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineLep committed Oct 18, 2022
1 parent 922be5d commit 15d9d76
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 15 deletions.
2 changes: 1 addition & 1 deletion config/application_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from strategies.multi_coin_abnormal_volume_tracker.multi_coin_abnormal_volume_tracker \
import MultiCoinAbnormalVolumeTracker

strategy = TwitterElonMuskDogeTracker()
strategy = ListingSniper()

log = {
"level": "info",
Expand Down
101 changes: 87 additions & 14 deletions strategies/listing_sniper/listing_sniper.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
import logging
import time
import math

from core.strategy.strategy import Strategy
from core.ftx.rest.ftx_rest_api import FtxRestApi

# Trading pair to snipe
MARKET_PAIR_TO_SNIPE = "IP3/USD"
MARKET_PAIR_TO_SNIPE = "APT/USD"

# USD amount to invest on the coin to be listed
# /!\ Make sure your wallet have more (twice is good) than this amount because due to the high demand,
# the order fill price can be higher than the computed one based on last stock data
AMOUNT_TO_INVEST = 1500
AMOUNT_TO_INVEST = 2000

# Minimum size increment to compute order size
# Ensure your order size will be a multiple of the size increment value
SIZE_INCREMENT = 10
# First take profit
TP1_TARGET_PERCENTAGE = 500
TP1_SIZE_RATIO = 0.3

# Second take profit
TP2_TARGET_PERCENTAGE = 1200
TP2_SIZE_RATIO = 0.4

# Last take profit
TP3_TARGET_PERCENTAGE = 2000
# TP3_SIZE_RATIO Will be filled with remaining position size

# Stop loss
SL_PERCENTAGE = 50


class ListingSniper(Strategy):
Expand All @@ -39,19 +49,25 @@ def loop(self) -> None:
return

try:
response = self.ftx_rest_api.get("markets/" + MARKET_PAIR_TO_SNIPE)
logging.info(f"FTX API response: {str(response)}")
m_response = self.ftx_rest_api.get("markets/" + MARKET_PAIR_TO_SNIPE)
logging.info(f"FTX API response: {str(m_response)}")

market_enabled = response["enabled"]
market_enabled = m_response["enabled"]
logging.info(f"market enabled: {str(market_enabled)}")

if market_enabled is False:
raise Exception(f"Market {MARKET_PAIR_TO_SNIPE} is not yet enabled")

order_size = math.floor(AMOUNT_TO_INVEST / response["ask"]) - \
math.floor(AMOUNT_TO_INVEST / response["ask"]) % SIZE_INCREMENT
order_size = (AMOUNT_TO_INVEST / m_response["ask"]) - \
(AMOUNT_TO_INVEST / m_response["ask"]) % m_response["sizeIncrement"]

order_params = {
logging.info(f"Order param: {str(order_size)}")

if order_size < m_response["minProvideSize"]:
raise Exception(f"Order computed size {order_size} is less than the minimum size "
f"{m_response['minProvideSize']}")

opening_order_params = {
"market": MARKET_PAIR_TO_SNIPE,
"side": "buy",
"price": None,
Expand All @@ -60,9 +76,11 @@ def loop(self) -> None:
"ioc": False
}

logging.info(f"Opening order param: {str(opening_order_params)}")

try:
logging.info(f"Opening position: {str(order_params)}")
response = self.ftx_rest_api.post("orders", order_params)
logging.info(f"Opening position: {str(opening_order_params)}")
response = self.ftx_rest_api.post("orders", opening_order_params)
logging.info(f"FTX API response: {str(response)}")

self._sniped = True
Expand All @@ -72,6 +90,61 @@ def loop(self) -> None:
logging.error(e)
raise

tp1 = {
"market": MARKET_PAIR_TO_SNIPE,
"side": "sell",
"size": (order_size * TP1_SIZE_RATIO) - (order_size * TP1_SIZE_RATIO) % m_response["sizeIncrement"],
"type": "takeProfit",
"reduceOnly": True,
"triggerPrice": m_response["ask"] + m_response["ask"] * TP1_TARGET_PERCENTAGE / 100,
"order_price": None,
"trail_value": None
}

tp2 = {
"market": MARKET_PAIR_TO_SNIPE,
"side": "sell",
"size": (order_size * TP2_SIZE_RATIO) - (order_size * TP2_SIZE_RATIO) % m_response["sizeIncrement"],
"type": "takeProfit",
"reduceOnly": True,
"triggerPrice": m_response["ask"] + m_response["ask"] * TP2_TARGET_PERCENTAGE / 100,
"order_price": None,
"trail_value": None
}

tp3 = {
"market": MARKET_PAIR_TO_SNIPE,
"side": "sell",
"size": order_size - tp1["size"] - tp2["size"],
"type": "takeProfit",
"reduceOnly": True,
"triggerPrice": m_response["ask"] + m_response["ask"] * TP3_TARGET_PERCENTAGE / 100,
"order_price": None,
"trail_value": None
}

sl = {
"market": MARKET_PAIR_TO_SNIPE,
"side": "sell",
"size": order_size,
"type": "stop",
"reduceOnly": True,
"triggerPrice": m_response["ask"] - m_response["ask"] * SL_PERCENTAGE / 100,
"order_price": None,
"trail_value": None
}

for trigger_order in [tp1, tp2, tp3, sl]:
try:
logging.info(f"Opening trigger order: {str(trigger_order)}")
co_response = self.ftx_rest_api.post("conditional_orders", trigger_order)
logging.info(f"FTX API response: {str(co_response)}")
except Exception as e:
logging.error("An error occurred when opening position:")
logging.error(e)

time.sleep(0.25)

except Exception as e:
logging.error(e)

Expand Down

0 comments on commit 15d9d76

Please sign in to comment.