mirror of
https://github.com/wassname/catalyst.git
synced 2026-08-14 12:10:24 +08:00
Polishing live trading components
This commit is contained in:
@@ -44,7 +44,7 @@ class BitfinexTestCase(BaseExchangeTestCase):
|
||||
asset=bitfinex.get_asset('eth_usd'),
|
||||
style=LimitOrder(limit_price=200),
|
||||
limit_price=200,
|
||||
amount=1,
|
||||
amount=0.5,
|
||||
stop_price=None
|
||||
)
|
||||
log.info('order created {}'.format(order_id))
|
||||
@@ -53,7 +53,7 @@ class BitfinexTestCase(BaseExchangeTestCase):
|
||||
def test_get_order(self):
|
||||
log.info('querying orders from bitfinex')
|
||||
bitfinex = Bitfinex()
|
||||
response = bitfinex.get_order(order_id=3330866978)
|
||||
response = bitfinex.get_order(order_id=3361248395)
|
||||
log.info('the order: {}'.format(response))
|
||||
pass
|
||||
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
from unittest import TestCase
|
||||
from logbook import Logger
|
||||
from mock import patch, sentinel
|
||||
from catalyst.exchange.exchange_clock import ExchangeClock
|
||||
from catalyst.utils.calendars.trading_calendar import days_at_time
|
||||
from datetime import time
|
||||
from collections import defaultdict
|
||||
from catalyst.utils.calendars import get_calendar
|
||||
import pandas as pd
|
||||
|
||||
log = Logger('BitfinexTestCase')
|
||||
|
||||
|
||||
class BitfinexTestCase(TestCase):
|
||||
def setUp(self):
|
||||
self.internal_clock = None
|
||||
self.events = defaultdict(list)
|
||||
|
||||
def advance_clock(self, x):
|
||||
"""Mock function for sleep. Advances the internal clock by 1 min"""
|
||||
# The internal clock advance time must be 1 minute to match
|
||||
# MinutesSimulationClock's update frequency
|
||||
self.internal_clock += pd.Timedelta('1 min')
|
||||
|
||||
def get_clock(self, arg, *args, **kwargs):
|
||||
"""Mock function for pandas.to_datetime which is used to query the
|
||||
current time in RealtimeClock"""
|
||||
assert arg == "now"
|
||||
return self.internal_clock
|
||||
|
||||
def test_clock(self):
|
||||
with patch('catalyst.exchange.exchange_clock.pd.to_datetime') as to_dt, \
|
||||
patch('catalyst.exchange.exchange_clock.sleep') as sleep:
|
||||
clock = ExchangeClock()
|
||||
to_dt.side_effect = self.get_clock
|
||||
sleep.side_effect = self.advance_clock
|
||||
start_time = pd.Timestamp.utcnow()
|
||||
self.internal_clock = start_time
|
||||
|
||||
log.info('listing events')
|
||||
events = list(clock)
|
||||
|
||||
# Event 0 is SESSION_START which always happens at 00:00.
|
||||
ts, event_type = events[1]
|
||||
pass
|
||||
Reference in New Issue
Block a user