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

Hey, Is this still the way you would do this today? Any lessons learned since you wrote this? Thanks!

@talesa
Copy link
Author

talesa commented Feb 21, 2021

Hey hey!
Thanks for your interest, I was wondering if I saved this script somewhere since the new gold rush began recently, so thanks for reminding me :)
I'd say it worked pretty well back in 2018, most people participating in pumps are rather not very tech savvy so such a simple script was already giving you an edge back then, I doubt people are more sophisticated these days, maybe even less given a larger crowd is pouring in, while practices like this still seem not to be well regulated.
I think the direction that would yield the most benefit would be somehow tuning/automating the delay/moment at which you place the sell order.
Would be keen to chat more if you're interested!

@JeffreyShran
Copy link

JeffreyShran commented Feb 21, 2021

Thanks for the info. Glad I was able to remind you! :)

I think the sell order part is quite tricky. Especially as the duration of the pump can vary wildly. Also detecting how close you are to the peak of the pump and when to offload may be something that is best decided 'in the moment' depending on a multitude of factors, like general crypto interest, Twitter sentiment, pump participation - there's an endless list I feel.

My main interest really is in how quickly and reliably can the buy order be placed. I expect that's key to the whole thing.

I'm new to the pumping phenomenon and stumbled upon your script whilst wondering about what's possible. It got my creative juices flowing which is great. Thanks for sharing in the first place. :)

@talesa
Copy link
Author

talesa commented Feb 21, 2021

I think the sell order part is quite tricky. [...]

Absolutely agreed.

[...] how quickly and reliably can the buy order be placed. I expect that's key to the whole thing.

Yeah, that's definitely the key thing.
The answer I'm tempted to give is:

  1. definitely faster than anyone who uses GUI,
  2. no guarantees about the reliability, cannot comment on how smooth binance API calls execution is at the moment, haven't used it for 3 years now, surely a lot has changed (hopefully for the better),
  3. on the side of how this script works the reliability depends on factor = 1.1, which sorta decides how late to the pump you agree to join. Then if your limit buy order is not executed within 5sec you cancel the order for it not to be executed as the pump ends when the price falls back to pre-pump level (as you'd expect).

@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