Skip to content

Instantly share code, notes, and snippets.

@talesa
Last active March 17, 2021 12:32
Show Gist options
  • Save talesa/5edaed2c3947af410ab11730915e6bb5 to your computer and use it in GitHub Desktop.
Save talesa/5edaed2c3947af410ab11730915e6bb5 to your computer and use it in GitHub Desktop.
Short script to for pump and dumps, you have to execute this code line by line so use `jupyter notebook` or `hydrogen` inside `atom` editor
# you have to execute this code line by line so use jupyter notebook or hydrogen inside atom editor
# import libraries
import ccxt
from datetime import datetime
# create exchange API handle
exchange = getattr(ccxt, 'binance')()
# paste in your API key and secret here (if you're afraid they're gonna get stolen, inspect the ccxt library open source code on github)
exchange.apiKey = ''
exchange.secret = ''
# This function waits until your orders has been executed
def has_been_realised(orders, time, wait_time=5.0):
while True:
orders = [(id, symbol) for id, symbol in orders if exchange.fetch_order(id=id, symbol=symbol)['status'] != 'closed']
if len(orders) == 0:
print('Realised at {}'.format(datetime.now()))
return True
if datetime.now().timestamp() > time.timestamp() + wait_time :
[exchange.cancel_order(id=id, symbol=symbol) for id, symbol in orders]
print('Cancelling orders at {}'.format(self.now()))
return False
print('Try at {}'.format(datetime.now()))
# the factor of what multiple of pre-pump price to limit buy at
factor = 1.1
# run ahead of time to fetch your balance
balance = exchange.fetch_balance()
# run this few seconds before the pump coin is announced to obtain most recent tickers
tickers = exchange.fetch_tickers()
# this is where you start executing the script the moment you receive info on which coin is pumped
# insert the code of pumped coin here
currency = ''
symbol = currency+'/BTC'
# these lines determine the buy order price and amount
buy_order_price = factor * tickers[symbol]['ask']
buy_order_amount = balance['BTC']['free'] / buy_order_price / 1.01 # this 1.01 is safety factor so that you won't get insufficient amount error
# this places the limit buy order
order = exchange.create_order(symbol, 'limit', 'buy', amount=buy_order_amount, price=buy_order_price)
# this function waits until the order has been realised or cancels the order after 5 seconds (you can change this time in the command below)
has_been_realised([(order['id'], symbol)], datetime.now(), wait_time=5.0)
# It produces output of this sort:
# Try at 2018-01-07 19:00:18.168240
# Try at 2018-01-07 19:00:18.477217
# Realised at 2018-01-07 19:00:18.928225
# Fetch balance again so you know how much of currency you've actually bought
balance = exchange.fetch_balance()
# Create market sell order
order = exchange.create_order(symbol, 'market', 'sell', amount=balance[currency]['free'])
has_been_realised([(order['id'], symbol)], datetime.now())
@JeffreyShran
Copy link

Thanks @talesa. It's always nice to meet friendly people on Github. :)

If I end up doing anything beyond minor changes I'll certainly let you know in the event you might find it interesting in some way.

Just an FYI... I found some whitepapers that were published around the same time you wrote this script. I don't know if you've read them (easy to Google for them) but they're interesting reading if you do choose to pick something like this back up. You may have already seen them of course if you were previously curious.

Good luck, stay safe,

Jeff

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment