Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
fredfortier committed Mar 19, 2018
2 parents 1cafcc1 + 2a97ade commit 1e02506
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 15 deletions.
3 changes: 3 additions & 0 deletions catalyst/exchange/ccxt/ccxt_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ def get_candle_frequencies(self, data_frequency=None):
if data_frequency == 'minute' and not freq.endswith('T'):
continue

elif data_frequency == 'hourly' and not freq.endswith('D'):
continue

elif data_frequency == 'daily' and not freq.endswith('D'):
continue

Expand Down
7 changes: 1 addition & 6 deletions catalyst/exchange/exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
PricingDataNotLoadedError, \
NoDataAvailableOnExchange, NoValueForField, \
NoCandlesReceivedFromExchange, \
InvalidHistoryFrequencyAlias, \
TickerNotFoundError, NotEnoughCashError
from catalyst.exchange.utils.datetime_utils import get_delta, \
get_periods_range, \
Expand Down Expand Up @@ -509,10 +508,6 @@ def get_history_window(self,
frequency, data_frequency, supported_freqs=['T', 'D', 'H']
)

if unit == 'H':
raise InvalidHistoryFrequencyAlias(
freq=frequency)

# we want to avoid receiving empty candles
# so we request more than needed
# TODO: consider defining a const per asset
Expand Down Expand Up @@ -616,7 +611,7 @@ def get_history_window_with_bundle(self,
# TODO: this function needs some work,
# we're currently using it just for benchmark data
freq, candle_size, unit, data_frequency = get_frequency(
frequency, data_frequency
frequency, data_frequency, supported_freqs=['T', 'D']
)
adj_bar_count = candle_size * bar_count
try:
Expand Down
4 changes: 2 additions & 2 deletions catalyst/exchange/exchange_data_portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def get_exchange_history_window(self,
bundle = self.exchange_bundles[exchange_name] # type: ExchangeBundle

freq, candle_size, unit, adj_data_frequency = get_frequency(
frequency, data_frequency
frequency, data_frequency, supported_freqs=['T', 'D']
)
adj_bar_count = candle_size * bar_count

Expand All @@ -312,7 +312,7 @@ def get_exchange_history_window(self,
algo_end_dt=self._last_available_session,
)

start_dt = get_start_dt(end_dt, adj_bar_count, data_frequency)
start_dt = get_start_dt(end_dt, adj_bar_count, adj_data_frequency)
df = resample_history_df(pd.DataFrame(series), freq, field, start_dt)
return df

Expand Down
11 changes: 7 additions & 4 deletions catalyst/exchange/utils/datetime_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,12 @@ def get_year_start_end(dt, first_day=None, last_day=None):
return year_start, year_end


def get_frequency(freq, data_frequency=None, supported_freqs=['D', 'T']):
def get_frequency(freq, data_frequency=None, supported_freqs=['D', 'H', 'T']):
"""
Get the frequency parameters.
Takes an arbitrary candle size (e.g. 15T) and converts to the lowest
common denominator supported by the data bundles (e.g. 1T). The data
bundles only support 1T and 1D frequencies. If another frequency
is requested, Catalyst must request the underlying data and resample.
Notes
-----
Expand Down Expand Up @@ -306,14 +309,14 @@ def get_frequency(freq, data_frequency=None, supported_freqs=['D', 'T']):
data_frequency = 'minute'

elif unit.lower() == 'h':
data_frequency = 'minute'

if 'H' in supported_freqs:
unit = 'H'
alias = '{}H'.format(candle_size)

else:
candle_size = candle_size * 60
alias = '{}T'.format(candle_size)
data_frequency = 'minute'

else:
raise InvalidHistoryFrequencyAlias(freq=freq)
Expand Down
12 changes: 10 additions & 2 deletions catalyst/marketplace/utils/auth_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import hashlib
import hmac
import webbrowser

import requests
import time
Expand Down Expand Up @@ -45,10 +46,17 @@ def get_key_secret(pubAddr, wallet='mew'):
nonce = '0x{}'.format(d['nonce'])

if wallet == 'mew':
url = 'https://www.myetherwallet.com/signmsg.html'

print('\nObtaining a key/secret pair to streamline all future '
'requests with the authentication server.\n'
'Visit https://www.myetherwallet.com/signmsg.html and sign the '
'following message:\n{}'.format(nonce))
'Visit {url} and sign the '
'following message:\n{nonce}'.format(
url=url,
nonce=nonce))

webbrowser.open_new(url)

signature = input('Copy and Paste the "sig" field from '
'the signature here (without the double quotes, '
'only the HEX value):\n')
Expand Down
49 changes: 49 additions & 0 deletions catalyst/support/issue_227.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import pytz
from datetime import datetime
from catalyst.api import symbol
from catalyst.utils.run_algo import run_algorithm

coin = 'btc'
base_currency = 'usd'
n_candles = 5


def initialize(context):
context.symbol = symbol('%s_%s' % (coin, base_currency))


def handle_data_polo_partial_candles(context, data):
history = data.history(symbol('btc_usdt'), ['volume'],
bar_count=10,
frequency='4H')
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 = False

if live:
run_algorithm(initialize=lambda ctx: True,
handle_data=handle_data_polo_partial_candles,
exchange_name='poloniex',
base_currency='usdt',
algo_namespace='ns',
live=True,
data_frequency='minute',
capital_base=3000)
else:
run_algorithm(initialize=lambda ctx: True,
handle_data=handle_data_polo_partial_candles,
exchange_name='poloniex',
base_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)
)
35 changes: 35 additions & 0 deletions catalyst/support/issue_274.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import pytz
from datetime import datetime
from catalyst.api import symbol
from catalyst.utils.run_algo import run_algorithm

coin = 'btc'
base_currency = 'usd'


def initialize(context):
context.symbol = symbol('%s_%s' % (coin, base_currency))


def handle_data_polo_partial_candles(context, data):
history = data.history(symbol('btc_usdt'), ['volume'],
bar_count=10,
frequency='1D')
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')


run_algorithm(initialize=lambda ctx: True,
handle_data=handle_data_polo_partial_candles,
exchange_name='poloniex',
base_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))
2 changes: 1 addition & 1 deletion docs/source/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ with the following steps:

.. code-block:: bash
conda create --name catalyst python=2.7 scipy zlib
conda create --name catalyst python=3.6 scipy zlib
3. Activate the environment:

Expand Down

0 comments on commit 1e02506

Please sign in to comment.