def eq_only(): with open("sectors.json", "r") as f: sectors = json.load(f) start = datetime.datetime(2017, 10, 26, 0, 0, 0, 0, pytz.utc) end = datetime.datetime(2018, 1, 4, 0, 0, 0, 0, pytz.utc) for sector in sectors: # only run sectors with sufficient info if sector in global_vars.ignored_sectors: print("skipping {}".format(sector)) continue # first run an optimized sector global_vars.SECTOR_NAME = sector # try with equal weights global_vars.SECTOR_NAME = sector print("\nRunning portfolio with equal weights for: {}".format( global_vars.SECTOR_NAME)) run_algorithm( initialize=portfolio_equal_weights.initialize, handle_data=portfolio_equal_weights.handle_data, analyze=portfolio_equal_weights.analyze, start=start, end=end, exchange_name='bittrex', capital_base=100000, ) print("\nDone portfolio with equal weights for: {}".format( global_vars.SECTOR_NAME))
def run_algorithm_helper(args): syms, exchange, start_date, end_date = args def initialize(context): context.assets = [ (sym, symbol(sym)) for sym in syms ] context.ohlcv_df = [] def analyze(context=None, results=None): path = os.path.join(os.getcwd(), 'data', exchange) print(path) os.makedirs(path, exist_ok=True) csv_file_name = os.path.join(path, start_date.strftime('%Y%m%d') + '.csv') df = pd.concat(context.ohlcv_df) df = df[['sym', 'dt', 'open', 'high', 'low', 'close', 'volume']].sort_values(['sym', 'dt']) df.to_csv(csv_file_name, index=False) print('Processing sym={} from {} to {} on {}'.format(syms, start_date, end_date, exchange)) try: results = run_algorithm(initialize=initialize, handle_data=handle_data, analyze=analyze, start=start_date, end=end_date, exchange_name=exchange, data_frequency='minute', base_currency='usdt', capital_base=10000) return(results) except Exception as e: print('Error: {}'.format(e)) return(e)
# ax3 = plt.subplot(313, sharex=ax1) # perf.alpha.plot(ax=ax3) plt.show() print("Starting Cash: $", perf.starting_cash.iloc[0]) print("Ending portfolio value: $", perf.portfolio_value.iloc[-1]) print("Cash: $", perf.cash.iloc[-1]) print("Ending cash: $", perf.ending_cash.iloc[-1]) print("Max Drawdown: ", perf.max_drawdown.min() * 100, "%") print("Algorithm Period Return: ", perf.algorithm_period_return.iloc[-1] * 100, "%") print("Pnl $", perf.pnl.sum()) print(get_pretty_stats(perf)) # if __name__ == '__main__': run_algorithm( capital_base=1000, data_frequency='minute', initialize=initialize, handle_data=handle_data, analyze=analyze, exchange_name='poloniex, binance', quote_currency='usdt', live=False, start=pd.to_datetime('2017-1-1', utc=True), end=pd.to_datetime('2018-1-1', utc=True), )
def initialize(context): pass def _handle_data(context, data): global symbols if symbols is None: symbols = [symbol(c + '_usdt') for c in coins] print('getting history for: %s' % [s.symbol for s in symbols]) history = data.history( symbols, ['close', 'volume'], bar_count=1, # EXCEPTION, Change to 2 frequency='5T') print('history: %s' % history.shape) run_algorithm(initialize=initialize, handle_data=_handle_data, analyze=lambda _, results: True, exchange_name='poloniex', quote_currency='usdt', algo_namespace='issue-236', live=True, data_frequency='minute', capital_base=3000, simulate_orders=True)
if len(context.errors) > 0: log.info('the errors:\n{}'.format(context.errors)) def analyze(context, stats): log.info('the daily stats:\n{}'.format(get_pretty_stats(stats))) pass # run_algorithm( # initialize=initialize, # handle_data=handle_data, # analyze=analyze, # exchange_name='bitfinex', # live=True, # algo_namespace=algo_namespace, # base_currency='btc', # live_graph=False # ) # Backtest run_algorithm(capital_base=250, data_frequency='minute', initialize=initialize, handle_data=handle_data, analyze=analyze, exchange_name='bitfinex', algo_namespace=algo_namespace, base_currency='btc')
log.info('completed bar {}, total execution errors {}'.format( data.current_dt, len(context.errors))) if len(context.errors) > 0: log.info('the errors:\n{}'.format(context.errors)) def analyze(context, stats): log.info('the daily stats:\n{}'.format(get_pretty_stats(stats))) pass run_algorithm(capital_base=100000, initialize=initialize, handle_data=handle_data, analyze=analyze, exchange_name='poloniex', start=pd.to_datetime('2017-5-01', utc=True), end=pd.to_datetime('2017-10-16', utc=True), base_currency='usdt', data_frequency='daily') # run_algorithm( # initialize=initialize, # handle_data=handle_data, # analyze=analyze, # exchange_name='poloniex', # live=True, # algo_namespace=algo_namespace, # base_currency='btc' # )
"""" history = data.history(sample_symbol_stock, ['close', 'volume'], bar_count=3, frequency='1d') current = data.current(sample_symbol_stock, ['close', 'volume']) print ('CURRENT: {}'.format(current)) print ('HISTORY: {}'.format(history)) if not hasattr(context, 'i'): context.i = 0 context.i += 1 if context.i > 5: raise Exception('stop') """ run_algorithm(initialize=lambda ctx: True, handle_data=handle_data_polo_partial_candles, exchange_name='poloniex', quote_currency='usdt', algo_namespace='ns', live=False, data_frequency='minute', capital_base=3000, start=datetime(2018, 2, 2, 0, 0, 0, 0, pytz.utc), end=datetime(2018, 2, 20, 0, 0, 0, 0, pytz.utc))
for exit_point in exit_points: if gap < exit_point['gap']: sell_amount = exit_point['amount'] if sell_amount: log.info('found sell trigger for amount: {}'.format(sell_amount)) place_orders( context=context, amount=sell_amount, buying_price=buying_price, selling_price=selling_price, action='exit' ) def analyze(context, stats): log.info('the daily stats:\n{}'.format(get_pretty_stats(stats))) pass run_algorithm( initialize=initialize, handle_data=handle_data, analyze=analyze, exchange_name='poloniex,bitfinex', live=True, algo_namespace=algo_namespace, base_currency='btc', live_graph=False )
print('Bitfinex Price: {}, Poloniex Price: {}'.format( bitfinex_price, poloniex_price)) order(asset=context.bitfinex_trading_pair, amount=1, limit_price=buy_b) order(asset=context.poloniex_trading_pair, amount=-1, limit_price=sell_p) elif is_profitable_after_fees(sell_b, buy_p, context.bitfinex, context.poloniex): print('Date: {}'.format(data.current_dt)) print('Bitfinex Price: {}, Poloniex Price: {}'.format( bitfinex_price, poloniex_price)) order(asset=context.poloniex_trading_pair, amount=1, limit_price=buy_p) order(asset=context.bitfinex_trading_pair, amount=-1, limit_price=sell_b) if __name__ == '__main__': run_algorithm(capital_base=10000, initialize=initialze, handle_data=handle_data, live=False, quote_currency='usd', exchange_name='bitfinex, poloniex', algo_namespace='arbitrage002', data_frequency='minute', start=pd.to_datetime('2017-12-06', utc=True), end=pd.to_datetime('2018-05-03', utc=True))
# Other options include 'open', 'high', 'open', 'close' # Please note that 'price' equals 'close' current = data.history(context.asset, ['volume', 'high', 'low', 'open', 'close'], 1, '1T') # Append the current information to the pricing_data DataFrame context.pricing_data = context.pricing_data.append(current) def analyze(context=None, results=None): # Save pricing data to a CSV file filename = os.path.splitext(os.path.basename(__file__))[0] context.pricing_data.to_csv(filename + '.csv') #%% # year-month-day start = datetime(2019, 2, 21, 0, 0, 0, 0, pytz.utc) end = datetime(2020, 2, 22, 0, 0, 0, 0, pytz.utc) results = run_algorithm(initialize=initialize, handle_data=handle_data, analyze=analyze, start=start, end=end, exchange_name='binance', data_frequency='minute', quote_currency='usdt', capital_base=10000) # %%
ax6.plot( sells.index, results.loc[sells.index, 'rsi'], 'v', markersize=10, color='r', ) plt.legend(loc=3) # Show the plot. plt.gcf().set_size_inches(18, 8) plt.show() pass if __name__ == '__main__': # Backtest run_algorithm( capital_base=0.5, data_frequency='minute', initialize=initialize, handle_data=handle_data, analyze=analyze, exchange_name='poloniex', algo_namespace=algo_namespace, base_currency='btc', start=pd.to_datetime('2017-9-1', utc=True), end=pd.to_datetime('2017-10-1', utc=True), )
def analyze(context, stats): log.info('the daily stats:\n{}'.format(get_pretty_stats(stats))) pass if __name__ == '__main__': live = True if live: run_algorithm( capital_base=1000, initialize=initialize, handle_data=handle_data, analyze=analyze, exchange_name='bittrex', live=True, algo_namespace=algo_namespace, base_currency='btc', simulate_orders=True, ) else: run_algorithm( capital_base=10000, data_frequency='daily', initialize=initialize, handle_data=handle_data, analyze=analyze, exchange_name='poloniex', algo_namespace='buy_and_hodl', base_currency='usdt',
context=context, amount=sell_amount, buying_price=buying_price, selling_price=selling_price, action='exit' ) def analyze(context, stats): log.info('the daily stats:\n{}'.format(get_pretty_stats(stats))) pass if __name__ == '__main__': # The execution mode: backtest or live MODE = 'live' if MODE == 'live': run_algorithm( capital_base=0.1, initialize=initialize, handle_data=handle_data, analyze=analyze, exchange_name='poloniex,bitfinex', live=True, algo_namespace=algo_namespace, base_currency='btc', live_graph=False, simulate_orders=True, stats_output=None, )
record(pr=pr, r=r, m=m, stds=stds, max_sharpe_port=max_sharpe_port, corr_m=corr_m) context.i += 1 def analyze(context=None, results=None): # Form DataFrame with selected data data = results[['pr', 'r', 'm', 'stds', 'max_sharpe_port', 'corr_m', 'portfolio_value']] # Save results in CSV file filename = os.path.splitext(os.path.basename(__file__))[0] data.to_csv(filename + '.csv') if __name__ == '__main__': # Bitcoin data is available from 2015-3-2. Dates vary for other tokens. start = datetime(2017, 1, 1, 0, 0, 0, 0, pytz.utc) end = datetime(2017, 8, 16, 0, 0, 0, 0, pytz.utc) results = run_algorithm(initialize=initialize, handle_data=handle_data, analyze=analyze, start=start, end=end, exchange_name='poloniex', capital_base=100000, )
log.info('found sell trigger for amount: {}'.format(sell_amount)) place_orders(context=context, amount=sell_amount, buying_price=buying_price, selling_price=selling_price, action='exit') def analyze(context, stats): log.info('the daily stats:\n{}'.format(get_pretty_stats(stats))) pass if __name__ == '__main__': # The execution mode: backtest or live MODE = 'live' if MODE == 'live': run_algorithm( capital_base=0.1, initialize=initialize, handle_data=handle_data, analyze=analyze, exchange_name='poloniex,bitfinex', live=True, algo_namespace=algo_namespace, quote_currency='btc', live_graph=False, simulate_orders=True, stats_output=None, )
def analyze(context, stats): log.info('the daily stats:\n{}'.format(get_pretty_stats(stats))) pass if __name__ == '__main__': live = False if live: run_algorithm( capital_base=1000, initialize=initialize, handle_data=handle_data, analyze=analyze, exchange_name='bittrex', live=True, algo_namespace=algo_namespace, base_currency='btc', simulate_orders=True, ) else: run_algorithm( capital_base=100000, data_frequency='minute', initialize=initialize, handle_data=handle_data, analyze=analyze, exchange_name='poloniex', algo_namespace='buy_low_sell_high', base_currency='usdt',
r=r, m=m, stds=stds, max_sharpe_port=max_sharpe_port, corr_m=corr_m) context.i += 1 def analyze(context=None, results=None): # Form DataFrame with selected data data = results[['pr', 'r', 'm', 'stds', 'max_sharpe_port', 'corr_m', 'portfolio_value']] # Save results in CSV file filename = os.path.splitext(os.path.basename(__file__))[0] data.to_csv(filename + '.csv') if __name__ == '__main__': # Bitcoin data is available from 2015-3-2. Dates vary for other tokens. start = datetime(2017, 1, 1, 0, 0, 0, 0, pytz.utc) end = datetime(2017, 8, 16, 0, 0, 0, 0, pytz.utc) results = run_algorithm(initialize=initialize, handle_data=handle_data, analyze=analyze, start=start, end=end, exchange_name='poloniex', capital_base=100000, quote_currency='usdt', )
#print(context.blotter.current_dt) #print(data.current_dt) context.index += 1 def analyze(context=None, results=None): # Close open file properly at the end context.pricing_data.to_csv( os.path.splitext(os.path.basename(__file__))[0] + '2.csv') context.csvfile.close() results = run_algorithm( initialize=initialize, handle_data=handle_data, analyze=analyze, exchange_name='poloniex', quote_currency='usd', algo_namespace='issue-430', live=False, data_frequency='minute', capital_base=3000, start=pd.to_datetime('2018-08-1', utc=True), end=pd.to_datetime('2018-09-1', utc=True), ) print("hi")
# Add commission and slippage context.set_commission(maker=0.000, taker=0.001) context.set_slippage(spread=0.000) def analyze(context, perf): Logger(__name__).info('elapsed time: {}'.format(time.time() - context.start_time)) context.quote_currency = list( context.exchanges.values())[0].quote_currency.upper() context.asset = list(broker.agents.keys())[0] plotter = Plotter(context, perf) plotter.plot('portfolio_value', 'asset_trades', 'portfolio_change', 'cash') if __name__ == '__main__': run_algorithm( capital_base=1, data_frequency='minute', initialize=initialize, handle_data=broker.handle_data, analyze=analyze, exchange_name='binance', quote_currency='eth', start=pd.to_datetime('2018-05-10', utc=True), end=pd.to_datetime('2018-05-25', utc=True), )
m=m, stds=stds, max_sharpe_port=max_sharpe_port, corr_m=corr_m) context.i += 1 def analyze(context=None, results=None): # Form DataFrame with selected data data = results[['pr', 'r', 'm', 'stds', 'max_sharpe_port', 'corr_m', 'portfolio_value']] # Save results in CSV file #filename = os.path.splitext(os.path.basename(__file__))[0] #data.to_csv(filename + '.csv') if __name__ == '__main__': # Bitcoin data is available from 2015-3-2. Dates vary for other tokens. #start = datetime(2017, 1, 1, 0, 0, 0, 0, pytz.utc) #end = datetime(2017, 8, 16, 0, 0, 0, 0, pytz.utc) results = run_algorithm(initialize=initialize, handle_data=handle_data, analyze=analyze, exchange_name='poloniex', capital_base=100000, simulate_orders=True, algo_namespace='portfolio_optimization', base_currency='usdt', live=True)
log.warn('aborting the bar on error {}'.format(e)) context.errors.append(e) # log.info('completed bar {}, total execution errors {}'.format(data.current_dt, len(context.errors))) if len(context.errors) > 0: log.info('the errors:\n{}'.format(context.errors)) def analyze(context, perf): import matplotlib.pyplot as plt # Plot the portfolio and asset data. ax1 = plt.subplot(411) ax2 = plt.subplot(412) perf.loc[:, ['portfolio_value']].plot(ax=ax1) perf[['zscore']].plot(ax=ax2) plt.show() run_algorithm(initialize=initialize, handle_data=handle_data, analyze=analyze, capital_base=10000, live=False, quote_currency='usd', exchange_name='bitfinex', algo_namespace='Trade Pairs', data_frequency='minute', start=pd.to_datetime('2018-04-01', utc=True), end=pd.to_datetime('2018-04-02', utc=True))
fields=['open', 'high', 'low', 'close'], bar_count=50, frequency='1T' ) set_print_settings() print(prices.tail(10)) context.data.append(prices) context.i = context.i + 1 if context.i == 3: context.interrupt_algorithm() def analyze(context, prefs): for dataset in context.data: print(dataset[-2:]) if __name__ == '__main__': run_algorithm( capital_base=0.1, initialize=initialize, handle_data=handle_data, analyze=analyze, exchange_name='binance', algo_namespace='Test candles', base_currency='eth', data_frequency='minute', live=True, simulate_orders=True)
# Show the plot. plt.gcf().set_size_inches(18, 8) plt.show() pass # run_algorithm( # initialize=initialize, # handle_data=handle_data, # analyze=analyze, # exchange_name='bittrex', # live=True, # algo_namespace=algo_namespace, # base_currency='btc', # live_graph=False # ) # Backtest run_algorithm( capital_base=0.5, data_frequency='minute', initialize=initialize, handle_data=handle_data, analyze=analyze, exchange_name='poloniex', algo_namespace=algo_namespace, base_currency='btc', start=pd.to_datetime('2017-9-1', utc=True), end=pd.to_datetime('2017-10-1', utc=True), )
#print('\nnow: %s\n%s' % (data.current_dt, history)) #if not hasattr(context, 'i'): # context.i = 0 #context.i += 1 #print(history) #get_order(5, return_price=True) print(get_open_orders(sym)) # print(context.exchanges['poloniex'].get_trades(symbol("xrp_btc"), start_dt=1533081600000)) #if context.i > 10: # raise Exception('stop') #order(symbol("XRP_BTC"), 1) live = True if live: run_algorithm( initialize=lambda ctx: True, handle_data=handle_data, exchange_name='poloniex', quote_currency='btc', algo_namespace='issue-409', live=live, data_frequency='minute', capital_base=0.015, simulate_orders=False, auth_aliases=dict(poloniex='auth3') #poloniex,auth3" #start=pd.to_datetime('2017-09-14', utc=True), #end=pd.to_datetime('2018-08-01', utc=True), )
def handle_data(context, data): # Variables to record for a given asset: price and volume # Other options include 'open', 'high', 'open', 'close' # Please note that 'price' equals 'close' date = context.blotter.current_dt # current time in each iteration price = data.current(context.asset, 'price') volume = data.current(context.asset, 'volume') high = data.current(context.asset, 'high') low = data.current(context.asset, 'low') open = data.current(context.asset, 'open') close = data.current(context.asset, 'close') # Writes one line to CSV on each iteration with the chosen variables context.csvwriter.writerow([date, price, volume, high, low, open, close]) def analyze(context=None, results=None): # Close open file properly at the end context.csvfile.close() # Bitcoin data is available from 2015-3-2. Dates vary for other tokens. results = run_algorithm(initialize=initialize, handle_data=handle_data, analyze=analyze, start=start, end=end, exchange_name=EXCHANGE, data_frequency=FREQUENCY, base_currency ='usd', capital_base=10000 )
def analyze(context, stats): log.info('the daily stats:\n{}'.format(get_pretty_stats(stats))) exchange = list(context.exchanges.values())[0] quote_currency = exchange.quote_currency.upper() if __name__ == '__main__': live = True if live: run_algorithm( capital_base=1000, initialize=initialize, handle_data=handle_data, analyze=analyze, exchange_name='bittrex', live=True, algo_namespace='Cmomentum13', quote_currency='usd', simulate_orders=True, ) else: run_algorithm( capital_base=1000, data_frequency='minute', initialize=initialize, handle_data=handle_data, analyze=analyze, exchange_name='bitfinex', algo_namespace='CMomentum13', quote_currency='usd',
ax1 = plt.subplot(211) perf.portfolio_value.plot(ax=ax1) ax1.set_ylabel('portfolio value') # volatility ax2 = plt.subplot(212, sharex=ax1) perf.algo_volatility.plot(ax=ax2) ax2.set_ylabel('Volatility') plt.show() if __name__ == '__main__': # input region of time to test print("Backtesting region. Give in YYYY-MM-DD") start_input = input("Start date:") end_input = input("End date:") # slippage input slippage = float(input("Slippage:")) # run run_algorithm( initialize=initialize, handle_data=handle_data, analyze=analyze, capital_base=1000, live=False, quote_currency='usdt', exchange_name='bitfinex, poloniex', data_frequency='minute', start=pd.to_datetime(str(start_input), utc=True), end=pd.to_datetime(str(end_input), utc=True), )
# log.info('the errors:\n{}'.format(context.errors)) if __name__ == '__main__': # === v-long bear # t0 = pd.to_datetime('2018-06-01', utc=True) # tf = pd.to_datetime('2018-12-30', utc=True) # === long neutral hill # t0 = pd.to_datetime('2018-01-08', utc=True) # tf = pd.to_datetime('2018-03-13', utc=True) # === med bull # t0 = pd.to_datetime('2018-12-21', utc=True) # tf = pd.to_datetime('2018-12-30', utc=True) # === short neutral t0 = pd.to_datetime('2018-12-21', utc=True) tf = pd.to_datetime('2018-12-21', utc=True) run_algorithm( live=False, # set this to true to lose all your money capital_base=1, # starting captial data_frequency='minute', # minute || daily initialize=initialize, handle_data=handle_data, analyze=analyze, exchange_name='binance', algo_namespace=ALGO_NAMESPACE, quote_currency='btc', start=t0, end=tf, )
def handle_data(context, data): prices = data.history(symbol('xlm_eth'), fields=['open', 'high', 'low', 'close'], bar_count=50, frequency='1T') set_print_settings() print(prices.tail(10)) context.data.append(prices) context.i = context.i + 1 if context.i == 3: context.interrupt_algorithm() def analyze(context, prefs): for dataset in context.data: print(dataset[-2:]) if __name__ == '__main__': run_algorithm(capital_base=0.1, initialize=initialize, handle_data=handle_data, analyze=analyze, exchange_name='binance', algo_namespace='Test candles', quote_currency='eth', data_frequency='minute', live=True, simulate_orders=True)
from catalyst.api import symbol from catalyst.utils.run_algo import run_algorithm def initialize(context): context.asset = symbol('bcc_usdt') def handle_data(context, data): data.history(context.asset, ['close'], bar_count=100, frequency='5T') def analyze(context=None, results=None): pass if __name__ == '__main__': run_algorithm( capital_base=100, initialize=initialize, handle_data=handle_data, analyze=analyze, exchange_name='bittrex', algo_namespace="bittrex_is_broken", quote_currency='usdt', data_frequency='minute', simulate_orders=True, live=True)
#coding:utf-8 #rom sample import * from TurtleM import * from datetime import datetime import pytz from catalyst.utils.run_algo import run_algorithm start = datetime(2018, 1, 1, 0, 0, 0, 0, pytz.utc) end = datetime(2018, 4, 1, 0, 0, 0, 0, pytz.utc) results = run_algorithm( initialize=initialize, handle_data=handle_data, analyze=analyze, start=start, end=end, #live=True, #simulate_orders=True, data_frequency='minute', #algo_namespace='my_algo_name', exchange_name='bitfinex', capital_base=10000, base_currency='usd', #output='PaperTrading.pickle' )
r=r, m=m, stds=stds, max_sharpe_port=max_sharpe_port, corr_m=corr_m) context.i += 1 def analyze(context=None, results=None): # Form DataFrame with selected data data = results[['portfolio_value']] # Save results in CSV file if not os.path.exists(os.path.join("comparisons", global_vars.SECTOR_NAME)): os.mkdir(os.path.join("comparisons", global_vars.SECTOR_NAME)) filename = "optimized_" + global_vars.SECTOR_NAME data.to_csv(os.path.join("comparisons", global_vars.SECTOR_NAME, filename + ".csv")) if __name__ == '__main__': start = datetime(2017, 10, 27, 0, 0, 0, 0, pytz.utc) end = datetime(2018, 1, 5, 0, 0, 0, 0, pytz.utc) results = run_algorithm(initialize=initialize, handle_data=handle_data, analyze=analyze, start=start, end=end, exchange_name='bittrex', capital_base=100000, )
amount=1, limit_price=bitfinex_price) order(asset=context.poloniex_trading_pair, amount=-1, limit_price=poloneix_price) elif (bitfinex_price > poloneix_price): print('Buy poloneix, selling bitfinex') order(asset=context.poloniex_trading_pair, amount=1, limit_price=poloneix_price) order(asset=context.bitfinex_trading_pair, amount=-1, limit_price=bitfinex_price) def analyze(context, perf): # TODO: Next tutorial pass perf = run_algorithm(capital_base=100, initialize=initialze, handle_data=handle_data, analyze=analyze, live=False, base_currency='btc', exchange_name='bitfinex, poloniex', data_frequency='minute', start=pd.to_datetime('2017-12-12', utc=True), end=pd.to_datetime('2017-12-12', utc=True))
def initialize(context): pass def handle_data(context, data): history = data.history(symbol('btc_usd'), ['volume'], bar_count=288, frequency='5T') print('\nnow: %s\n%s' % (data.current_dt, history)) if not hasattr(context, 'i'): context.i = 0 context.i += 1 if context.i > 5: raise Exception('stop') live = True if live: run_algorithm(initialize=lambda ctx: True, handle_data=handle_data, exchange_name='gdax', quote_currency='usd', algo_namespace='issue-323', live=True, data_frequency='daily', capital_base=3000, )
from catalyst.api import symbol from catalyst.utils.run_algo import run_algorithm def initialize(context): context.asset = symbol('bcc_usdt') def handle_data(context, data): data.history(context.asset, ['close'], bar_count=100, frequency='5T') def analyze(context=None, results=None): pass if __name__ == '__main__': run_algorithm( capital_base=100, initialize=initialize, handle_data=handle_data, analyze=analyze, exchange_name='bittrex', algo_namespace="bittrex_is_broken", base_currency='usdt', data_frequency='minute', simulate_orders=True, live=True)