def test_ticker(): api = poloniex.Poloniex('examples/config.py') while True: print(api.ticker()) # Change this to less at your own risk - Bitstamp has a harsh policy about exceeding allowed number of calls time.sleep(1)
def __init__(self): self.conn = poloniex.Poloniex(po_api.api_key, po_api.secret) self.active_trader = trader.Trader() self.actions = [ 'BUY_USDC_BTC', 'BUY_BTC_ETH', 'BUY_BTC_XMR', 'BUY_BTC_XRP', 'BUY_BTC_DOGE', 'SELL_USDC_BTC', 'SELL_BTC_ETH', 'SELL_BTC_XMR', 'SELL_BTC_XRP', 'SELL_BTC_DOGE', ] self.state = []
def main(argv): period = 10 pair = "BTC_ARDR" try: opts, args = getopt.getopt(argv, "hp:c:a:s:", ["period=", "currency=", "api=", "secret="]) except getopt.GetoptError: print( "trading-bot.py -p <period> -c <currency pair> -a <api key> -s <secret key>" ) sys.exit(2) for opt, arg in opts: if opt == "-h": print( "trading-bot.py -p <period> -c <currency pair> -a <api key> -s <secret key>" ) sys.exit() elif opt in ("-p", "--period"): if (int(arg) in [300, 900, 1800, 7200, 14400, 86400]): period = arg else: print( "Poloniex requires a period in 300, 900, 1800, 7200, 14400, 86400" ) sys.exit(2) elif opt in ("-c", "--currency"): pair = arg elif opt in ("-a", "--apikey"): API_KEY = arg elif opt in ("-s", "--secretkey"): SECRET_KEY = arg conn = poloniex.Poloniex(API_KEY, SECRET_KEY) while True: last_pair_price = conn.returnTicker()[pair]["percentChange"] print(datetime.now().strftime("%Y-%m-%d %H:%M:%S") + " Peroid: " + str(period) + "s " + pair + ": " + str(last_pair_price)) time.sleep(period)
def __init__(self, *argv): # Optparse parser = argparse.ArgumentParser( description='Automated Bitcoin Trading Bot') parser.add_argument( '-p', '--period', type=int, default=900, dest='period', help= "candlestick period in seconds; valid values are 300, 900, 1800, 7200, 14400, and 86400", ) parser.add_argument( '-c', '--currency', type=str, default='USDC_BTC', dest='currency', help='Use a specific currency', ) parser.add_argument( '--show-chart', default=False, dest='show_chart', help='Show chart for debug', ) parser.add_argument( '-s', '--start-date', default=str( datetime.timestamp(datetime.fromisoformat('2019-01-05'))), type=str, dest='start_date', help='First Date to print ChartData must be ISO YYYY-MM-DD', ) parser.add_argument( '-e', '--end-date', default=str(datetime.timestamp(datetime.now())), type=str, dest='end_date', help='First Date to print ChartData must be ISO YYYY-MM-DD', ) parser.add_argument( '-v', '--verbose', default=False, type=bool, dest='verbose', help='Verbose output', ) parser.add_argument( '-g', '--get-all-exchanges', default=True, type=bool, dest='get_all_exchanges', help= 'Using get-all-exchanges will get the entire transaction chart in the specified timeframe.' ' Saved under data/exchange/data.csv', ) parser.add_argument( '--dry-run', default=False, type=bool, dest='dry_run', help='Dry run to check how well the model works', ) parser.add_argument( '--logging', default=True, type=bool, dest='logging', help='Set logging', ) opts = parser.parse_args(args=argv) # Params self.currency = opts.currency self.period = opts.period self.start_date = opts.start_date self.end_date = opts.end_date self.verbose = opts.verbose self.get_all_exchanges = opts.get_all_exchanges self.dry_run = opts.dry_run self.logging = opts.logging self.conn = poloniex.Poloniex(po_api.api_key, po_api.secret) # Attributes self.current_balance = self.get_balance() self.prices = [] self.historical_data_head = { 'date', 'high', 'low', 'open', 'close', 'volume', 'quoteVolume', 'weightedAverage' } self.historical_data = [] self.valid_periods = frozenset([300, 900, 1800, 7200, 14400, 86400]) # Set up logging if self.logging is True: logging.basicConfig(filename='logs/logging.log', level=logging.DEBUG) # Sanity checks for opts if opts.period not in self.valid_periods: parser.error( 'Period must be 300, 900, 1800, 7200, 14400, or 86400')
print(api.ticker()) # Change this to less at your own risk - Bitstamp has a harsh policy about exceeding allowed number of calls time.sleep(1) def test_volume(): api = poloniex.Poloniex('examples/config.py') while True: print(api.daily_volume()) # Change this to less at your own risk - Bitstamp has a harsh policy about exceeding allowed number of calls time.sleep(1) def test_order_book(): api = poloniex.Poloniex('examples/config.py') while True: print(api.order_book()) # Change this to less at your own risk - Bitstamp has a harsh policy about exceeding allowed number of calls time.sleep(1) def test_ws(*args, **kwargs): print(args, kwargs) if __name__ == '__main__': api = poloniex.Poloniex('examples/config.py') api.attach_order_book(test_ws, 'BTC_ETH')
import os import time from Balance import Balance from Cotacao import Cotacao from DataBase import BancoDeDados from TabelaHistorico import Historico from TabelaMarket import Market from poloniex import poloniex #API Key e Secret Key (Poloniex) api = '<colar API>' secret = '<colar Secret>' #Instancia da Classe Poloniex polo = poloniex.Poloniex(api, secret) #Variável que recebe a função que retorna os valores disponíveis montanteTotal = polo.returnCompleteBalances('all') valoresDiarios = polo.returnTicker() #Construtor do Banco de Dados bd = BancoDeDados() #Construtor da Tabela Historico historico = Historico() #Construtor da Tabela Market market = Market() #Construtor da Classe que pega a cotação do BTC cotacao = Cotacao()
self.conn = poloniex.Poloniex(po_api.api_key, po_api.secret) self.active_trader = trader.Trader() self.actions = [ 'BUY_USDC_BTC', 'BUY_BTC_ETH', 'BUY_BTC_XMR', 'BUY_BTC_XRP', 'BUY_BTC_DOGE', 'SELL_USDC_BTC', 'SELL_BTC_ETH', 'SELL_BTC_XMR', 'SELL_BTC_XRP', 'SELL_BTC_DOGE', ] self.state = [] def _update_orders(self): self.activeOrders = conn.returnOrderBook('all') def execute(self, action): pass def reset(self): self.state = [] conn = poloniex.Poloniex(po_api.api_key, po_api.secret) print(conn.returnOrderBook('all')) print(conn.returnBalances())