def test_add(self): with TradeService as trade_service: trade = Trade() trade.stock_code = 'sz002177' trade.trade_time = datetime.datetime.strptime( '2016-06-27 14:56:07', '%Y-%m-%d %H:%M:%S') trade.trade_price = decimal.Decimal('9.51') trade.price_change = decimal.Decimal('0.00') trade.volume = 220 trade.amount = 209435 trade.nature = 'S' trade_service.add_trade(trade)
def parse(cls, stock_code, text): array = text.split('/') if len(array) != 7: raise SpiderError("parse TradeDetail error. invalid text:" + text) trade = Trade(stock_code=stock_code) trade.trade_seq = int(array[0]) trade.trade_time = cls._get_trade_time(array[1]) trade.trade_price = decimal.Decimal(array[2]) trade.price_change = decimal.Decimal(array[3]) trade.volume = int(array[4]) trade.amount = int(array[5]) trade.nature = array[6] return trade
def test_mail_content(self): trade = Trade(stock_code='sz002177', trade_time=datetime.datetime.now()) strategy = BlockTradingStrategy() content = strategy.get_mail_content(trade) print content Mail().send('股票账号交易行情', content, subtype='html')
def test_add(self): with TradeService as trade_service: trade = Trade() trade.stock_code = "sz002177" trade.trade_time = datetime.datetime.strptime("2016-06-27 14:56:07", "%Y-%m-%d %H:%M:%S") trade.trade_price = decimal.Decimal("9.51") trade.price_change = decimal.Decimal("0.00") trade.volume = 220 trade.amount = 209435 trade.nature = "S" trade_service.add_trade(trade)
def test_eq(self): with TradeService() as trade_service: db_trades = trade_service.query_trades('sz002177') trade = Trade() trade.stock_code = 'sz002177' trade.trade_time = datetime.datetime.strptime( '2016-06-27 14:56:07', '%Y-%m-%d %H:%M:%S') trade.trade_price = decimal.Decimal('9.51') trade.price_change = decimal.Decimal('0.00') trade.volume = 220 trade.amount = 209435 trade.nature = 'S' self.assertEqual(trade, db_trades[0])
def _run(self): if not self._in_trading(): return parser = TencentSpider().query_stock_minute(self._stock_code) with TradeService() as trade_service: db_trades = trade_service.query_trades(self._stock_code, trade_time=parser.begin_time) add_trades = Trade.minus(parser.trades, db_trades) for trade in add_trades: trade_service.add_trade(trade) self._callback(trade)
def _run(self): if not self._in_trading(): return parser = TencentSpider().query_stock_minute(self._stock_code) with TradeService() as trade_service: db_trades = trade_service.query_trades( self._stock_code, trade_time=parser.begin_time) add_trades = Trade.minus(parser.trades, db_trades) for trade in add_trades: trade_service.add_trade(trade) self._callback(trade)
def test_eq(self): with TradeService() as trade_service: db_trades = trade_service.query_trades("sz002177") trade = Trade() trade.stock_code = "sz002177" trade.trade_time = datetime.datetime.strptime("2016-06-27 14:56:07", "%Y-%m-%d %H:%M:%S") trade.trade_price = decimal.Decimal("9.51") trade.price_change = decimal.Decimal("0.00") trade.volume = 220 trade.amount = 209435 trade.nature = "S" self.assertEqual(trade, db_trades[0])