mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-04 12:29:03 +08:00
Error handling improvements
This commit is contained in:
@@ -37,18 +37,18 @@ def handle_data(context, data):
|
||||
# bar_count=20,
|
||||
# frequency='1d'
|
||||
# )
|
||||
ohlc = data.history(context.asset,
|
||||
fields=['price', 'volume'],
|
||||
bar_count=120,
|
||||
frequency='1m'
|
||||
)
|
||||
# ohlc = data.history(context.asset,
|
||||
# fields=['price', 'volume'],
|
||||
# bar_count=120,
|
||||
# frequency='1m'
|
||||
# )
|
||||
# ohlc = data.history([context.asset, symbol('iot_usd')],
|
||||
# fields=['price', 'volume'],
|
||||
# bar_count=20,
|
||||
# frequency='1d'
|
||||
# )
|
||||
|
||||
hist_price = ohlc['price']
|
||||
# hist_price = ohlc['price']
|
||||
|
||||
cash = context.portfolio.cash
|
||||
log.info('base currency available: {cash}'.format(cash=cash))
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
from datetime import time
|
||||
from time import sleep
|
||||
import logbook
|
||||
|
||||
import catalyst.protocol as zp
|
||||
@@ -129,7 +130,7 @@ class ExchangeTradingAlgorithm(TradingAlgorithm):
|
||||
'update portfolio attempt {}: {}'.format(attempt_index, e)
|
||||
)
|
||||
if attempt_index < self.retry_update_portfolio:
|
||||
time.sleep(self.retry_delay)
|
||||
sleep(self.retry_delay)
|
||||
self._update_portfolio(attempt_index + 1)
|
||||
|
||||
def _check_open_orders(self, attempt_index=0):
|
||||
@@ -140,7 +141,7 @@ class ExchangeTradingAlgorithm(TradingAlgorithm):
|
||||
'check open orders attempt {}: {}'.format(attempt_index, e)
|
||||
)
|
||||
if attempt_index < self.retry_check_open_orders:
|
||||
time.sleep(self.retry_delay)
|
||||
sleep(self.retry_delay)
|
||||
return self._check_open_orders(attempt_index + 1)
|
||||
|
||||
def handle_data(self, data):
|
||||
@@ -174,7 +175,7 @@ class ExchangeTradingAlgorithm(TradingAlgorithm):
|
||||
'order attempt {}: {}'.format(attempt_index, e)
|
||||
)
|
||||
if attempt_index < self.retry_order:
|
||||
time.sleep(self.retry_delay)
|
||||
sleep(self.retry_delay)
|
||||
return self._order(
|
||||
asset, amount, limit_price, stop_price, style,
|
||||
attempt_index + 1)
|
||||
|
||||
@@ -15,6 +15,8 @@ from time import sleep
|
||||
|
||||
from logbook import Logger
|
||||
import pandas as pd
|
||||
import signal
|
||||
import sys
|
||||
|
||||
from catalyst.gens.sim_engine import (
|
||||
BAR,
|
||||
@@ -57,6 +59,13 @@ class ExchangeClock(object):
|
||||
self._before_trading_start_bar_yielded = True
|
||||
|
||||
def __iter__(self):
|
||||
def signal_handler(signal, frame):
|
||||
log.info('You pressed Ctrl+C!')
|
||||
# yield pd.Timestamp.utcnow(), BAR
|
||||
sys.exit(0)
|
||||
|
||||
signal.signal(signal.SIGINT, signal_handler)
|
||||
|
||||
yield pd.Timestamp.utcnow(), SESSION_START
|
||||
|
||||
while True:
|
||||
|
||||
Reference in New Issue
Block a user