示例#1
0
    def getBidsAsks(self):

        stockValues = {}

        bids = {}
        asks = {}

        allStocks = self.getAllStocksArr()

        # Load all the bids and asks values from the service (Etrade) into the dicts
        for stocks in allStocks:
            cn = lpl.ConnectEtrade(self.c, stocks, 1, 1, "intraday", False, 0)

            stockVals = []

            for ctr in range(self.numSpreadSamples):
                stockValues = cn.setStockValues(0, 0, "")
                #            for item in stockValues.items():
                #               print ("item " + str(item))
                #               for v1, v2 in enumerate(item):
                #                  print ("v1 " + str(v1))
                #                  print ("v2 " + str(v2))
                #                  if v2[0] == 0.0:
                #                     break
                stockVals.append(stockValues)

            print("stockVals\n" + str(stockVals))

            bidList = []
            askList = []

            for stock in stocks:
                for ctr in range(len(stockVals)):
                    for k, v in stockVals[ctr].items():
                        if k == stock:
                            #                     if v[0] == 0.0 or v[1] == 0.0:
                            #                        print ("skipping stock bid: " + stock + " " + str(v[0]))
                            #                        print ("skipping stock ask: " + stock + " " + str(v[1]))
                            #                        continue
                            bidList.append(v[0])
                            askList.append(v[1])
                    bids[stock] = bidList
                    asks[stock] = askList
                bidList = []
                askList = []

        print("bids\n" + str(bids))
        print("asks\n" + str(asks))

        return bids, asks
示例#2
0
    def getDailyTrends(self, stockData):

        trends = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

        dailyTrends = {}
        tr = {}

        allStocks = self.getAllStocksArr()

        for stocks in allStocks:
            cn = lpl.ConnectEtrade(self.c, stocks, 1, 1, "intraday", False, 1)

            for stock in stocks:
                tr[stock] = lpl.Trends(self.d, self.l, cn, 0, 0, stock)

                stockValues = cn.setStockValues(0, 0, "")

                print("stockData[stock] len\n" + str(len(stockData[stock])) +
                      " " + str(stock))

                tr[stock].setTrendLimits(stockData[stock],
                                         len(stockData[stock]), 0, 0)

                trends[self.bearS] = tr[stock].isBearShortTrend()
                trends[self.bearM] = tr[stock].isBearMidTrend()
                trends[self.bearL] = tr[stock].isBearLongTrend()
                trends[self.bearE] = tr[stock].isBearMegaTrend()
                trends[self.bearU] = tr[stock].isBearSuperTrend()

                trends[self.bullS] = tr[stock].isBullShortTrend()
                trends[self.bullM] = tr[stock].isBullMidTrend()
                trends[self.bullL] = tr[stock].isBullLongTrend()
                trends[self.bullE] = tr[stock].isBullMegaTrend()
                trends[self.bullU] = tr[stock].isBullSuperTrend()

                print("trends " + str("trends\n" + str(trends)))

                dailyTrends[stock] = trends
                trends = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

        print("dailyTrends " + str(dailyTrends))

        return dailyTrends
示例#3
0
tr = {}
lm = {}
a = {}
pr = {}

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Setup connection to the exchange service

if service == "bitstamp":
    cn = lpl.ConnectBitStamp(service, currency, alt)
    cn.connectPublic()
elif service == "bitfinex":
    cn = lpl.ConnectBitFinex()
elif service == "eTrade":
    symbol = stock
    cn = lpl.ConnectEtrade(c, stocks, debug, verbose, marketDataType, sandBox,
                           offLine)

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Initialize algorithm,  barcharts objects

stocks = stocks.split(",")

for stock in stocks:
    ba[stock] = lpl.Barchart()
    tr[stock] = lpl.Trends(d, lg[stock], cn, ba[stock], offLine, stock)
    lm[stock] = lpl.Limits(d, lg[stock], cn, ba[stock], offLine, stock)
    a[stock] = lpl.Algorithm(d, lg[stock], cn, ba[stock], tr[stock], lm[stock],
                             offLine, stock)
    pr[stock] = lpl.Price(a[stock], cn, usePricesFromFile, offLine,
                          a[stock].getMarketBeginTime())
示例#4
0
lg = lpl.Log(debug, verbose, logPath, slave)

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Setup connection to the exchange service

stockArr = []
if service == "bitstamp":
    cn = lpl.ConnectBitStamp(service, currency, alt)
    cn.connectPublic()
elif service == "bitfinex":
    cn = lpl.ConnectBitFinex()
elif service == "eTrade":
    symbol = stock
    stockArr.append(stock)
    cn = lpl.ConnectEtrade(c, stockArr, debug, verbose, marketDataType,
                           sandBox, slave)

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Initialize algorithm,  barcharts objects

bc = lpl.Barchart()
tr = lpl.Trends(d, lg, cn, bc, slave)
lm = lpl.Limits(d, lg, cn, bc, slave, symbol)
pa = lpl.Pattern(d, bc)
pr = lpl.Price(cn, slave)
a = lpl.Algorithm(d, lg, cn, bc, tr, lm, pa, pr, slave, stock)

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Initialize files

lg.info("Using " + pricesPath + " as prices file")