-
-
Save JeffreyShran/a44f799f6e54da3f1d72c05f9154fbcb 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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment