-
-
Save JeffreyShran/a44f799f6e54da3f1d72c05f9154fbcb to your computer and use it in GitHub Desktop.
Revisions
-
talesa revised this gist
Jan 7, 2018 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ # 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 -
talesa revised this gist
Jan 7, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -44,7 +44,7 @@ def has_been_realised(orders, time, wait_time=5.0): # 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 -
talesa revised this gist
Jan 7, 2018 . 1 changed file with 26 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,38 +1,58 @@ # 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()) -
talesa created this gist
Jan 7, 2018 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ import ccxt from datetime import datetime exchange = getattr(ccxt, 'binance')() exchange.apiKey = '' exchange.secret = '' def has_been_realised(orders, time): 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() + 5.0 : [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())) factor = 1.1 tickers = exchange.fetch_tickers() balance = exchange.fetch_balance() currency = '' symbol = currency+'/BTC' buy_order_price = factor * tickers[symbol]['ask'] buy_order_amount = balance['BTC']['free'] / buy_order_price / 1.01 order = exchange.create_order(symbol, 'limit', 'buy', amount=buy_order_amount, price=buy_order_price) has_been_realised([(order['id'], symbol)], datetime.now()) balance = exchange.fetch_balance() order = exchange.create_order(symbol, 'market', 'sell', amount=balance[currency]['free']) has_been_realised([(order['id'], symbol)], datetime.now())