diff --git a/catalyst/exchange/exchange_blotter.py b/catalyst/exchange/exchange_blotter.py index 1250f605..d4957e31 100644 --- a/catalyst/exchange/exchange_blotter.py +++ b/catalyst/exchange/exchange_blotter.py @@ -209,7 +209,12 @@ class ExchangeBlotter(Blotter): log.debug('found open order: {}'.format(order.id)) transactions = exchange.process_order(order) - if transactions and order.status == ORDER_STATUS.FILLED: + # This is a temporary measure, we should really update all + # trades, not just when the order gets filled. I just think + # that this is safer until we have a robust way to track + # the trades already processed by the algo. We can't loose + # them if the algo shuts down. + if transactions and order.open_amount == 0: avg_price = np.average( a=[t.price for t in transactions], weights=[t.amount for t in transactions], diff --git a/catalyst/support/binance_history.py b/catalyst/support/binance_history.py new file mode 100644 index 00000000..899c292c --- /dev/null +++ b/catalyst/support/binance_history.py @@ -0,0 +1,57 @@ +import pandas as pd +from catalyst import run_algorithm + + +def initialize(context): + context.i = -1 # counts the minutes + context.exchange = 'cryptopia' + context.base_currency = 'btc' + context.coins = context.exchanges[context.exchange].assets + context.coins = [c for c in context.coins if + c.quote_currency == context.base_currency] + + +def handle_data(context, data): + # current date formatted into a string + today = data.current_dt + + # update universe everyday + new_day = 60 * 24 # assuming data_frequency='minute' + if not context.i % new_day: + context.coins = context.exchanges[context.exchange].assets + context.coins = [c for c in context.coins if + c.quote_currency == context.base_currency] + + # get data every 30 minutes + minutes = 1 + if not context.i % minutes: + # we iterate for every pair in the current universe + for coin in context.coins: + pair = str(coin.symbol) + + price = data.current(coin, 'price') + print(today, pair, price) + + +def analyze(context=None, results=None): + pass + + +if __name__ == '__main__': + start_date = pd.to_datetime('2018-01-17', utc=True) + end_date = pd.to_datetime('2018-01-18', utc=True) + + performance = run_algorithm( + capital_base=1.0, + # amount of base_currency, not always in dollars unless usd + initialize=initialize, + handle_data=handle_data, + analyze=analyze, + exchange_name='cryptopia', + data_frequency='minute', + base_currency='btc', + live=True, + live_graph=False, + simulate_orders=True, + algo_namespace='simple_universe' + )