示例#1
0
    def makeTrade(self, rawTradeDict, act):
        #TODO validate the trade, attach a "post-trade cash balance" element and record in the mongoDB db
        #tradeClass does not interact with the account class
        specificTrade = trade.EquityTrade(rawTradeDict, act)
        #an instantiation of EquityTrade class... no processing done yet

        #TODO ensure that illegal trades are not logged... this logic is contained within tradeClass.qaTrade() function
        try:
            specificTradeResult = specificTrade.tradeType()
            #we post the trade to the account class from here
            #print('sending the following to the accounts class:')
            #print(specificTradeResult)
            act.postEquityTrade(specificTradeResult)
            #retrieve the coin_bal post trade
            coin_bal = act.coin_bal
            #TODO must append cash position to the trade dict... can either do here or in tradeClass... tradeClass is preferred
            formattedDic = self.prepDict(specificTradeResult, rawTradeDict,
                                         coin_bal)
            #self.logTrade(formattedDic) - legacy
            self.mongo_connection.tradeInjection(formattedDic)
            print('your trade has been logged')

        except ValueError:
            #TODO ensure this breaks out of the function
            print('trade was not executed')
            raise ValueError  #pass the ValueError to the calling function in engageUser class
示例#2
0
    def makeTrade(self, rawTradeDict, act):
        #log the trade and make the trade object available for passing to the account object... Call the yahoo finance scraper. trade.EquityTrade requires fewer attributes than what is to be retrieved from the scraper and what we need to record here on the log.
        #TODO parameter specificTradeDict contains an entry for the timestamp, but this is not persisted by the 'trade' object; this is needed for the trade log
        specificTrade = trade.EquityTrade(rawTradeDict, act)
        #an instantiation of EquityTrade class... no processing done yet

        #TODO ensure that illegal trades are not logged... this logic is contained within tradeClass.qaTrade() function
        try:
            specificTradeResult = specificTrade.tradeType()
            formattedDic = self.prepDict(specificTradeResult, rawTradeDict)
            self.logTrade(formattedDic)
            print('your trade has been logged')
            return (specificTradeResult)
        except ValueError:
            #TODO ensure this breaks out of the function
            print('trade was not executed')
            raise ValueError  #pass the ValueError to the calling function in engageUser class
buy_trade={'ticker':'CPT','price':98.108,'shares':1000,'timestamp':datetime.datetime.today(),'tradetype':'buy','original_tradetype':'long'}

buy_trade_2={'ticker':'HD','price':78.108,'shares':1000000,'timestamp':datetime.datetime.today(),'tradetype':'buy','original_tradetype':'long'}
sell_trade_dic={'ticker':'HD','price':102.108,'shares':1000,'timestamp':datetime.datetime.today(),'tradetype':'sell to close','original_tradetype':'long'}

short_trade_dic={'ticker':'RLS','price':67.108,'shares':1000,'timestamp':datetime.datetime.today(),'tradetype':'short','original_tradetype':'short'}
btc_trade_dic={'ticker':'RLS','price':69.108,'shares':1000,'timestamp':datetime.datetime.today(),'tradetype':'buy to close','original_tradetype':'short'}

#initiate trading day object and pass all trades through the object in order to log it
todayTrading=tm.TradingDay()

#using the new tradeManager framework
buy_test_today=todayTrading.makeTrade(buy_trade,act)

#following along the tradeClass object... instantiation does not affect the portfolio
buy_test=trade.EquityTrade(buy_trade,act)
buy_test_2=trade.EquityTrade(buy_trade_2,act)
sell_test=trade.EquityTrade(sell_trade_dic,act)
short_test=trade.EquityTrade(short_trade_dic,act)
short_test.tradetype

#testing only the tradeClass class and circumventing tradeManager class
buy_test_dict=buy_test.tradeType()
buy_test_dict2=buy_test_2.tradeType()
sell_test_dict=sell_test.tradeType()
#nothing is being returned here
short_test_dict=short_test.tradeType()

#update the portfolio
act.postEquityTrade(buy_test_dict)
act.postEquityTrade(short_test_dict)
示例#4
0
 def makeTrade(self, specificTradeDict, act):
     #log the trade and make the trade object available for passing to the account object... Call the yahoo finance scraper. trade.EquityTrade requires fewer attributes than what is to be retrieved from the scraper and what we need to record here on the log.
     specificTrade = trade.EquityTrade(specificTradeDict, act)
     self.logTrade(specificTrade)
     return specificTrade