コード例 #1
0
    def buildData(self, book, trades, lag):
        ed = coinwatcher.ExchangeData()

        mostRecent = self.mostRecentTransactionID
        mostRecentPrice = self.mostRecentPrice
        try:
            for t in trades['recentTrades']:
                tid = int(t['matchNumber'])
                tvol = float(t['amount'])
                d = datetime.datetime.strptime(t['timestamp'][:-2],
                                               '%Y-%m-%dT%H:%M:%S.%f')
                tdate = float(d.strftime('%s')) - time.timezone
                if ((tid > self.mostRecentTransactionID)
                        and (tdate > self.epoch)):
                    ed.volume += tvol
                    ed.nb_trades += 1
                if (tid > mostRecent):
                    mostRecent = tid
                    mostRecentPrice = float(t['price'])
        except Exception:
            self.logger.write('error: buildData() failed with trades\n' +
                              str(traceback.format_exc()))
            return None

        try:
            for b in book['bids']:
                bprice = float(b[0])
                bvol = float(b[1])
                ed.bids.append([bprice, bvol])
                ed.total_bid += bprice * bvol
            ed.bids.sort(reverse=True)

            for a in book['asks']:
                aprice = float(a[0])
                avol = float(a[1])
                ed.asks.append([aprice, avol])
                ed.total_ask += avol
            ed.asks.sort()
        except Exception:
            self.logger.write('error: buildData() failed with book\n' +
                              str(traceback.format_exc()))
            return None

        try:
            if (mostRecent != 0):
                self.mostRecentPrice = mostRecentPrice
            if (self.mostRecentPrice == 0):
                self.mostRecentPrice = ed.bids[0][0]
            if (mostRecent != 0):
                self.mostRecentTransactionID = mostRecent
            ed.rate = self.mostRecentPrice
            ed.lag = lag
            ed.ask_value = ed.asks[0][0]
            ed.bid_value = ed.bids[0][0]
        except Exception:
            self.logger.write('error: buildData() failed with ticker\n' +
                              str(traceback.format_exc()))
            return None

        return ed
コード例 #2
0
    def buildData(self, book, trades, lag):
        ed = coinwatcher.ExchangeData()

        mostRecentID = self.mostRecentTransactionID
        mostRecentPrice = self.mostRecentPrice

        try:
            for t in trades:
                tid = int(t['tid'])
                tvol = float(t['amount'])
                if ((tid > self.mostRecentTransactionID)
                        and (t['date'] > self.epoch)):
                    ed.volume += tvol
                    ed.nb_trades += 1
                if (tid > mostRecentID):
                    mostRecentID = tid
                    mostRecentPrice = float(t['price'])
        except Exception as e:
            self.logger.write('error buildData %s' % e)
            return None

        try:
            maxbprice = max([float(b[0]) for b in book['bids']])
            for b in book['bids']:
                bprice = float(b[0])
                bvol = float(b[1])
                if ((maxbprice - bprice) < 700):
                    ed.bids.append([bprice, bvol])
                ed.total_bid += bprice * bvol
            ed.bids.sort(reverse=True)

            minaprice = min([float(a[0]) for a in book['asks']])
            for a in book['asks']:
                aprice = float(a[0])
                avol = float(a[1])
                if ((aprice - minaprice) < 700):
                    ed.asks.append([aprice, avol])
                ed.total_ask += avol
            ed.asks.sort()
        except Exception as e:
            self.logger.write('error buildData %s' % e)
            return None

        try:
            if (mostRecentID != 0):
                self.mostRecentPrice = mostRecentPrice
            if (self.mostRecentPrice == 0):
                self.mostRecentPrice = ed.bids[0][0]
            if (mostRecentID != 0):  # comes last as line above may fail
                self.mostRecentTransactionID = mostRecentID
            ed.rate = self.mostRecentPrice
            ed.lag = lag
            ed.ask_value = ed.asks[0][0]
            ed.bid_value = ed.bids[0][0]
            ed.USD_conv_rate = self.CNY_USD_rate
        except Exception as e:
            self.logger.write('error buildData %s' % e)
            return None

        return ed
コード例 #3
0
    def buildData(self, book, trades, lag):
        ed = coinwatcher.ExchangeData()

        mostRecent = 0
        mostRecentPrice = self.mostRecentPrice
        try:
            for t in trades:
                tvol = float(t['size'])
                tdate1 = t['timestamp']
                tdate = strict_rfc3339.rfc3339_to_timestamp(tdate1)
                if ((tdate > self.mostRecentTransaction)
                        and (tdate > self.epoch)):
                    ed.volume += tvol
                    ed.nb_trades += 1
                if (tdate > mostRecent):
                    mostRecent = tdate
                    mostRecentPrice = float(t['price'])
        except Exception:
            self.logger.write('error buildData trades\n' +
                              str(traceback.format_exc()))
            return None

        try:
            for b in book:
                bprice = float(b['bidPrice'])
                bvol = float(b['bidSize'])
                ed.bids.append([bprice, bvol])
                ed.total_bid += bprice * bvol
            ed.bids.sort(reverse=True)

            for a in book:
                aprice = float(a['askPrice'])
                avol = float(a['askSize'])
                ed.asks.append([aprice, avol])
                ed.total_ask += avol
            ed.asks.sort()
        except Exception:
            self.logger.write('error: buildData() failed with book\n' +
                              str(traceback.format_exc()))
            return None

        try:
            if (mostRecent != 0):
                self.mostRecentPrice = mostRecentPrice
            if (self.mostRecentPrice == 0):
                self.mostRecentPrice = ed.bids[0][0]
            if (mostRecent != 0):
                self.mostRecentTransactionID = mostRecent
                self.mostRecentTransaction = mostRecent
            ed.rate = self.mostRecentPrice
            ed.lag = lag
            ed.ask_value = ed.asks[0][0]
            ed.bid_value = ed.bids[0][0]
        except Exception:
            self.logger.write('error: buildData() failed with ticker\n' +
                              str(traceback.format_exc()))
            return None

        return ed
コード例 #4
0
    def buildData(self, book, trades, lag):
        ed = coinwatcher.ExchangeData()

        mostRecentID = 0
        mostRecentPrice = self.mostRecentPrice
        try:
            for t in trades['transactions']:
                tvol = float(t['quantity'])
                tid = float(t['transactionId'])
                tdate = float(t['transactionTime'])
                if ((tid > self.mostRecentTransactionID)
                        and (tdate > self.epoch)):
                    ed.volume += tvol
                    ed.nb_trades += 1
                if (tid > mostRecentID):
                    mostRecentID = tid
                    mostRecentPrice = float(t['price'])
        except Exception:
            self.logger.write('error: buildData trades\n' +
                              str(traceback.format_exc()))
            return None

        try:
            for b in book['bids']:
                bprice = float(b['price'])
                bvol = float(b['volume'])
                ed.bids.append([bprice, bvol])
                ed.total_bid += bprice * bvol
            ed.bids.sort(reverse=True)

            for a in book['asks']:
                aprice = float(a['price'])
                avol = float(a['volume'])
                ed.asks.append([aprice, avol])
                ed.total_ask += avol
            ed.asks.sort()
        except Exception:
            self.logger.write('error: buildData book\n' +
                              str(traceback.format_exc()))
            return None

        try:
            if (mostRecentID != 0):
                self.mostRecentPrice = mostRecentPrice
            if (self.mostRecentPrice == 0):
                self.mostRecentPrice = ed.bids[0][0]
            if (mostRecentID != 0):
                self.mostRecentTransactionID = mostRecentID
            ed.rate = self.mostRecentPrice
            ed.lag = lag
            ed.ask_value = ed.asks[0][0]
            ed.bid_value = ed.bids[0][0]
            ed.USD_conv_rate = self.EUR_USD_rate
        except Exception:
            self.logger.write('error: buildData ticker\n' +
                              str(traceback.format_exc()))
            return None

        return ed
コード例 #5
0
    def buildData ( self, book, trades, lag ):
        ed = coinwatcher.ExchangeData ( )

        mostRecent = 0
        mostRecentPrice = self.mostRecentPrice
        try:
            for t in trades['result']['XXBTZJPY']:
                tvol = float ( t[1] )
                tdate = float ( t[2] )
                if ( ( tdate > self.mostRecentTransaction ) and ( tdate > self.epoch ) ):
                    ed.volume += tvol
                    ed.nb_trades += 1
                if ( tdate > mostRecent ):
                    mostRecent = tdate
                    mostRecentPrice = float ( t[0] )
        except Exception as e:
            self.logger.write ( 'error buildData %s' % e )
            return None

        try:
            maxbprice = max ( [ float(b[0]) for b in book['result']['XXBTZJPY']['bids'] ] )
            for b in book['result']['XXBTZJPY']['bids']:
                bprice = float ( b[0] )
                bvol = float ( b[1] )
                if ( (maxbprice-bprice) < 4000 ):
                    ed.bids.append ( [ bprice, bvol ] )
                ed.total_bid += bprice * bvol
            ed.bids.sort ( reverse=True )

            minaprice = min ( [ float(a[0]) for a in book['result']['XXBTZJPY']['asks'] ] )
            for a in book['result']['XXBTZJPY']['asks']:
                aprice = float ( a[0] )
                avol = float ( a[1] )
                if ( (aprice-minaprice) < 4000 ):
                    ed.asks.append ( [ aprice, avol ] )
                ed.total_ask += avol
            ed.asks.sort ( )
        except Exception as e:
            self.logger.write ( 'error buildData %s' % e )
            return None

        try:
            if ( mostRecent != 0 ):
                self.mostRecentPrice = mostRecentPrice
            if ( self.mostRecentPrice == 0 ):
                self.mostRecentPrice = ed.bids[0][0]
            if ( mostRecent != 0 ):
                self.mostRecentTransactionID = trades['result']['last']
                self.mostRecentTransaction = mostRecent
            ed.rate = self.mostRecentPrice
            ed.lag = lag
            ed.ask_value = ed.asks[0][0]
            ed.bid_value = ed.bids[0][0]
            ed.USD_conv_rate = self.JPY_USD_rate
        except Exception as e:
            self.logger.write ( 'error buildData %s' % e )
            return None

        return ed
コード例 #6
0
    def buildData(self, book, trades, lag):
        ed = coinwatcher.ExchangeData()

        mostRecent = 0
        mostRecentPrice = self.mostRecentPrice
        try:
            for t in trades['result']['XXBTZGBP']:
                tvol = float(t[1])
                tdate = float(t[2])
                if ((tdate > self.mostRecentTransaction)
                        and (tdate > self.epoch)):
                    ed.volume += tvol
                    ed.nb_trades += 1
                if (tdate > mostRecent):
                    mostRecent = tdate
                    mostRecentPrice = float(t[0])
        except Exception:
            self.logger.write('error buildData trades\n' +
                              str(traceback.format_exc()))
            return None

        try:
            for b in book['result']['XXBTZGBP']['bids']:
                bprice = float(b[0])
                bvol = float(b[1])
                ed.bids.append([bprice, bvol])
                ed.total_bid += bprice * bvol
            ed.bids.sort(reverse=True)

            for a in book['result']['XXBTZGBP']['asks']:
                aprice = float(a[0])
                avol = float(a[1])
                ed.asks.append([aprice, avol])
                ed.total_ask += avol
            ed.asks.sort()
        except Exception:
            self.logger.write('error buildData book\n' +
                              str(traceback.format_exc()))
            return None

        try:
            if (mostRecent != 0):
                self.mostRecentPrice = mostRecentPrice
            if (self.mostRecentPrice == 0):
                self.mostRecentPrice = ed.bids[0][0]
            if (mostRecent != 0):
                self.mostRecentTransactionID = trades['result']['last']
                self.mostRecentTransaction = mostRecent
            ed.rate = self.mostRecentPrice
            ed.lag = lag
            ed.ask_value = ed.asks[0][0]
            ed.bid_value = ed.bids[0][0]
            ed.USD_conv_rate = self.GBP_USD_rate
        except Exception:
            self.logger.write('error buildData ticker\n' +
                              str(traceback.format_exc()))
            return None

        return ed
コード例 #7
0
    def buildData(self, book, trades, lag):
        ed = coinwatcher.ExchangeData()

        mostRecent = 0
        mostRecentPrice = self.mostRecentPrice
        try:
            for t in trades['models']:
                tvol = float(t['quantity'])
                tdate = t['created_at']
                if ((tdate > self.mostRecentTransaction)
                        and (tdate > self.epoch)):
                    ed.volume += tvol
                    ed.nb_trades += 1
                if (tdate > mostRecent):
                    mostRecent = tdate
                    mostRecentPrice = float(t['price'])
        except Exception:
            self.logger.write('error buildData trades\n' +
                              str(traceback.format_exc()))
            return None

        try:
            for b in book['buy_price_levels']:
                bprice = float(b[0])
                bvol = float(b[1])
                ed.bids.append([bprice, bvol])
                ed.total_bid += bprice * bvol
            ed.bids.sort(reverse=True)

            for a in book['sell_price_levels']:
                aprice = float(a[0])
                avol = float(a[1])
                ed.asks.append([aprice, avol])
                ed.total_ask += avol
            ed.asks.sort()
        except Exception:
            self.logger.write('error: buildData() failed with book\n' +
                              str(traceback.format_exc()))
            return None

        try:
            if (mostRecent != 0):
                self.mostRecentPrice = mostRecentPrice
            if (self.mostRecentPrice == 0):
                self.mostRecentPrice = ed.bids['market_bid']
            if (mostRecent != 0):
                self.mostRecentTransactionID = mostRecent
                self.mostRecentTransaction = mostRecent
            ed.rate = self.mostRecentPrice
            ed.lag = lag
            ed.ask_value = aprice
            ed.bid_value = bprice
            ed.USD_conv_rate = self.JPY_USD_rate
        except Exception:
            self.logger.write('error: buildData() failed with ticker\n' +
                              str(traceback.format_exc()))
            return None

        return ed
コード例 #8
0
    def buildData ( self, book, trades, lag ):
        ed = coinwatcher.ExchangeData ( )

        mostRecent = self.mostRecentTransactionID
        mostRecentPrice = self.mostRecentPrice
        try:
            for t in trades:
                tid = int ( t['tid'] )
                tvol = float ( t['amount'] )
                if ( ( tid > self.mostRecentTransactionID ) and ( t['timestamp'] > self.epoch_ms ) ):
                    ed.volume += tvol
                    ed.nb_trades += 1
                if ( tid > mostRecent ):
                    mostRecent = tid
                    mostRecentPrice = float ( t['price'] )
        except Exception:
            self.logger.write ( 'error: buildData() failed with trades\n' + str(traceback.format_exc()) )
            return None

        try:
            maxbprice = max ( [ float(b[0]) for b in book['bids'] ] )
            for b in book['bids']:
                bprice = float ( b[0] )
                bvol = float ( b[1] )
                if ( (maxbprice-bprice) < 4000 ):
                    ed.bids.append ( [ bprice, bvol ] )
                ed.total_bid += bprice * bvol
            ed.bids.sort ( reverse=True )

            minaprice = min ( [ float(a[0]) for a in book['asks'] ] )
            for a in book['asks']:
                aprice = float ( a[0] )
                avol = float ( a[1] )
                if ( (aprice-minaprice) < 4000 ):
                    ed.asks.append ( [ aprice, avol ] )
                ed.total_ask += avol
            ed.asks.sort ( )
        except Exception:
            self.logger.write ( 'error: buildData() failed with book\n' + str(traceback.format_exc()) )
            return None

        try:
            if ( mostRecent != 0 ):
                self.mostRecentPrice = mostRecentPrice
            if ( self.mostRecentPrice == 0 ):
                self.mostRecentPrice = ed.bids[0][0]
            if ( mostRecent != 0 ):
                self.mostRecentTransactionID = mostRecent
            ed.rate = self.mostRecentPrice
            ed.lag = lag
            ed.ask_value = ed.asks[0][0]
            ed.bid_value = ed.bids[0][0]
            ed.USD_conv_rate = self.KRW_USD_rate
        except Exception:
            self.logger.write ( 'error: buildData() failed with ticker\n' + str(traceback.format_exc()) )
            return None

        return ed
コード例 #9
0
    def buildData(self, book, trades, lag):
        ed = coinwatcher.ExchangeData()

        mostRecentID = self.mostRecentTransactionID
        mostRecentDate = 0
        mostRecentPrice = self.mostRecentPrice
        try:
            for t in trades:
                tid = int(t['id'])
                tvol = float(t['size'])
                if (tid > self.mostRecentTransactionID):
                    ed.volume += tvol
                    ed.nb_trades += 1
                if (tid > mostRecentID):
                    mostRecentID = tid
                    mostRecentPrice = float(t['price'])
        except Exception:
            self.logger.write('error: buildData() failed with trades\n' +
                              str(traceback.format_exc()))
            return None

        try:
            for b in book['bids']:
                bprice = float(b['price'])
                bvol = float(b['size'])
                ed.bids.append([bprice, bvol])
                ed.total_bid += bprice * bvol
            ed.bids.sort(reverse=True)

            for a in book['asks']:
                aprice = float(a['price'])
                avol = float(a['size'])
                ed.asks.append([aprice, avol])
                ed.total_ask += avol
            ed.asks.sort()
        except Exception:
            self.logger.write('error: buildData() failed with book\n' +
                              str(traceback.format_exc()))
            return None

        try:
            if (mostRecentID != 0):
                self.mostRecentPrice = mostRecentPrice
            if (self.mostRecentPrice == 0):
                self.mostRecentPrice = ed.bprice
            if (mostRecentID != 0):
                self.mostRecentTransactionID = mostRecentID
            ed.rate = self.mostRecentPrice
            ed.lag = lag
            ed.ask_value = aprice
            ed.bid_value = bprice
            ed.USD_conv_rate = self.JPY_USD_rate
        except Exception:
            self.logger.write('error: buildData() failed with ticker\n' +
                              str(traceback.format_exc()))
            return None

        return ed
コード例 #10
0
    def buildData ( self, book, trades, lag ):
        ed = coinwatcher.ExchangeData ( )

        mostRecentID = self.mostRecentTransactionID
        mostRecentDate = 0
        mostRecentPrice = self.mostRecentPrice
        try:
            for t in trades:
                tid = int ( t['tid'] )
                tvol = float ( t['amount'] )
                tdate = float ( t['date'] )
                if ( ( tid > self.mostRecentTransactionID ) and ( tdate > self.epoch ) ):
                    ed.volume += tvol
                    ed.nb_trades += 1
                if ( tid > mostRecentID ):
                    mostRecentID = tid
                    mostRecentDate = tdate
                    mostRecentPrice = float ( t['price'] )
        except Exception as e:
            self.logger.write ( 'error buildData %s' % e )
            return None

        try:
            for b in book['bids']:
                bprice = float ( b[0] )
                bvol = float ( b[1] )
                ed.bids.append ( [ bprice, bvol ] )
                ed.total_bid += bprice * bvol
            ed.bids.sort ( reverse=True )

            for a in book['asks']:
                aprice = float ( a[0] )
                avol = float ( a[1] )
                ed.asks.append ( [ aprice, avol ] )
                ed.total_ask += avol
            ed.asks.sort ( )
        except Exception as e:
            self.logger.write ( 'error buildData %s' % e )
            return None

        try:
            if ( mostRecentID != 0 ):
                self.mostRecentPrice = mostRecentPrice
            if ( self.mostRecentPrice == 0 ):
                self.mostRecentPrice = ed.bids[0][0]
            if ( mostRecentID != 0 ):
                self.mostRecentTransactionID = mostRecentID
                self.mostRecentTransaction = mostRecentDate
            ed.rate = self.mostRecentPrice
            ed.lag = lag
            ed.ask_value = ed.asks[0][0]
            ed.bid_value = ed.bids[0][0]
        except Exception as e:
            self.logger.write ( 'error buildData %s' % e )
            return None

        return ed
コード例 #11
0
    def buildData ( self, book, trades, lag ):
        ed = coinwatcher.ExchangeData ( )

        mostRecentID = self.mostRecentTransactionID
        mostRecentPrice = self.mostRecentPrice
        try:
            for t in trades:
                tid = int ( t['tid'] )
                tprice = float ( t['price'] )
                tvol = tprice * float ( t['amount'] ) # amount is LTC, convert to BTC using price
                tdate = float ( t['date'] )
                if ( ( tid > self.mostRecentTransactionID ) and ( tdate > self.epoch ) ):
                    ed.volume += tvol
                    ed.nb_trades += 1
                if ( tid > mostRecentID ):
                    mostRecentID = tid
                    mostRecentPrice = 1 / tprice # trade pair must be inverted ltcbtc -> btcltc
        except Exception:
            self.logger.write ( 'error buildData trades\n' + str(traceback.format_exc()) )
            return None

        try: # bids and asks are inverted
            for b in book['asks']:
                bprice = 1 / float ( b[0] ) # trade pair must be inverted ltcbtc -> btcltc
                bvol = float ( b[0] ) * float ( b[1] )
                ed.bids.append ( [ bprice, bvol ] )
                ed.total_bid += bprice * bvol
            ed.bids.sort ( reverse=True )

            for a in book['bids']:
                aprice = 1 / float ( a[0] ) # trade pair must be inverted ltcbtc -> btcltc
                avol = float ( a[0] ) * float ( a[1] )
                ed.asks.append ( [ aprice, avol ] )
                ed.total_ask += avol
            ed.asks.sort ( )
        except Exception:
            self.logger.write ( 'error buildData book\n' + str(traceback.format_exc()) )
            return None

        try:
            if ( mostRecentID != 0 ):
                self.mostRecentPrice = mostRecentPrice
            if ( self.mostRecentPrice == 0 ):
                self.mostRecentPrice = ed.bids[0][0]
            if ( mostRecentID != 0 ):
                self.mostRecentTransactionID = mostRecentID
            ed.rate = self.mostRecentPrice
            ed.lag = lag
            ed.ask_value = ed.asks[0][0]
            ed.bid_value = ed.bids[0][0]
            ed.USD_conv_rate = self.LTC_USD_rate
        except Exception:
            self.logger.write ( 'error buildData ticker\n' + str(traceback.format_exc()) )
            return None

        return ed
コード例 #12
0
    def buildData(self, book, trades, lag):
        ed = coinwatcher.ExchangeData()

        mostRecentID = self.mostRecentTransactionID
        mostRecentDate = self.mostRecentTransaction
        mostRecentPrice = self.mostRecentPrice
        try:
            for t in trades:
                tid = int(t['tid'])
                tvol = float(t['amount'])
                tdate = int(t['timestamp'])
                if ((tdate > self.mostRecentTransaction)
                        and (tdate > self.epoch)):
                    ed.volume += tvol
                    ed.nb_trades += 1
                if (tdate > mostRecentDate):
                    mostRecentID = tid
                    mostRecentDate = tdate
                    mostRecentPrice = float(t['price'])
        except Exception:
            self.logger.write('error buildData failed with trades\n' +
                              str(traceback.format_exc()))
            return None

        try:
            for b in book['bids']:
                bprice = float(b['price'])
                bvol = float(b['amount'])
                ed.bids.append([bprice, bvol])
                ed.total_bid += bprice * bvol
            ed.bids.sort(reverse=True)

            for a in book['asks']:
                aprice = float(a['price'])
                avol = float(a['amount'])
                ed.asks.append([aprice, avol])
                ed.total_ask += avol
            ed.asks.sort()
        except Exception:
            self.logger.write('error buildData failed with book\n' +
                              str(traceback.format_exc()))
            return None

        try:
            if (mostRecentID != 0):
                self.mostRecentPrice = mostRecentPrice
            if (self.mostRecentPrice == 0):
                self.mostRecentPrice = ed.bids[0][0]
            if (mostRecentID != 0):
                self.mostRecentTransactionID = mostRecentID
                self.mostRecentTransaction = mostRecentDate
            ed.rate = self.mostRecentPrice
            ed.lag = lag
            ed.ask_value = ed.asks[0][0]
            ed.bid_value = ed.bids[0][0]
        except Exception:
            self.logger.write('error buildData failed with ticker\n' +
                              str(traceback.format_exc()))
            return None

        return ed
コード例 #13
0
    def buildData(self, book, trades, lag):
        ed = coinwatcher.ExchangeData()

        mostRecentID = self.mostRecentTransactionID
        mostRecentDate = 0
        mostRecentPrice = self.mostRecentPrice
        try:
            for t in trades:
                tid = int(t['tid'])
                tvol = float(t['amount'])
                tdate = float(t['date'])
                if ((tid > self.mostRecentTransactionID)
                        and (tdate > self.epoch)):
                    ed.volume += tvol
                    ed.nb_trades += 1
                if (tid > mostRecentID):
                    mostRecentID = tid
                    mostRecentDate = tdate
                    mostRecentPrice = float(t['price'])
        except Exception:
            self.logger.write('error: buildData() failed with trades\n' +
                              str(traceback.format_exc()))
            return None

        try:
            bookbids = json.loads(book['cumulatedBids'])
            maxbprice = max([float(b[0]) for b in bookbids])
            for b in bookbids:
                bprice = float(b[0])
                bvol = float(b[1])
                if ((maxbprice - bprice) < 700):
                    ed.bids.append([bprice, bvol])
                ed.total_bid += bprice * bvol
            ed.bids.sort(reverse=True)

            bookasks = json.loads(book['cumulatedAsks'])
            minaprice = min([float(a[0]) for a in bookasks])
            for a in bookasks:
                aprice = float(a[0])
                avol = float(a[1])
                if ((aprice - minaprice) < 700):
                    ed.asks.append([aprice, avol])
                ed.total_ask += avol
            ed.asks.sort()
        except Exception:
            self.logger.write('error: buildData() failed with book\n' +
                              str(traceback.format_exc()))
            return None

        try:
            if (mostRecentID != 0):
                self.mostRecentPrice = mostRecentPrice
            if (self.mostRecentPrice == 0):
                self.mostRecentPrice = ed.bids[0][0]
            if (mostRecentID != 0):
                self.mostRecentTransactionID = mostRecentID
                self.mostRecentTransaction = mostRecentDate
            ed.rate = self.mostRecentPrice
            ed.lag = lag
            ed.ask_value = ed.asks[0][0]
            ed.bid_value = ed.bids[0][0]
        except Exception:
            self.logger.write('error: buildData() failed with ticker\n' +
                              str(traceback.format_exc()))
            return None

        return ed
コード例 #14
0
    def buildData ( self, book, trades, lag ):
        ed = coinwatcher.ExchangeData ( )

        mostRecentID = self.mostRecentTransactionID
        mostRecentDate = 0
        mostRecentPrice = self.mostRecentPrice
        # 2016-08-10: tzoffset is used when timestamp key is not available
        tzoffset = time.timezone
        if time.daylight:
            tzoffset = time.altzone
        try:
            for t in trades:
                # 2016-08-10: tid key disappeared from API
                tid = int ( t['tid'] )
                #tid = int ( t['id'] )
                tvol = float ( t['amount'] )
                # 2016-08-10: timestamp key disappeared from API
                tdate = float ( t['timestamp'] )
                #d = datetime.datetime.strptime ( t['created_at'], '%Y-%m-%dT%H:%M:%SZ' )
                #tdate = float ( d.strftime('%s') ) - tzoffset
                if ( ( tid > self.mostRecentTransactionID ) and ( tdate > self.epoch ) ):
                    ed.volume += tvol
                    ed.nb_trades += 1
                if ( tid > mostRecentID ):
                    mostRecentID = tid
                    mostRecentDate = tdate
                    mostRecentPrice = float ( t['price'] )
        except Exception:
            self.logger.write ( 'error: buildData() failed with trades\n' + str(traceback.format_exc()) )
            return None

        try:
            for b in book['bids']:
                bprice = float ( b['price'] )
                bvol = float ( b['amount'] )
                ed.bids.append ( [ bprice, bvol ] )
                ed.total_bid += bprice * bvol
            ed.bids.sort ( reverse=True )

            for a in book['asks']:
                aprice = float ( a['price'] )
                avol = float ( a['amount'] )
                ed.asks.append ( [ aprice, avol ] )
                ed.total_ask += avol
            ed.asks.sort ( )
        except Exception:
            self.logger.write ( 'error: buildData() failed with book\n' + str(traceback.format_exc()) )
            return None

        try:
            if ( mostRecentID != 0 ):
                self.mostRecentPrice = mostRecentPrice
            if ( self.mostRecentPrice == 0 ):
                self.mostRecentPrice = ed.bids[0][0]
            if ( mostRecentID != 0 ):
                self.mostRecentTransactionID = mostRecentID
                self.mostRecentTransaction = mostRecentDate
            ed.rate = self.mostRecentPrice
            ed.lag = lag
            ed.ask_value = ed.asks[0][0]
            ed.bid_value = ed.bids[0][0]
        except Exception:
            self.logger.write ( 'error: buildData() failed with ticker\n' + str(traceback.format_exc()) )
            return None

        return ed
コード例 #15
0
    def buildData(self, book, trades, lag):
        ed = coinwatcher.ExchangeData()

        mostRecentID = self.mostRecentTransactionID
        mostRecentDate = 0
        mostRecentPrice = self.mostRecentPrice
        tzoffset = time.timezone
        if time.daylight:
            tzoffset = time.altzone
        try:
            for t in trades:
                tid = int(t['trade_id'])
                tvol = float(t['size'])
                try:
                    d = datetime.datetime.strptime(t['time'],
                                                   '%Y-%m-%dT%H:%M:%S.%fZ')
                except:
                    d = datetime.datetime.strptime(t['time'],
                                                   '%Y-%m-%dT%H:%M:%SZ')
                tdate = float(d.strftime('%s')) - tzoffset
                if ((tid > self.mostRecentTransactionID)
                        and (tdate > self.epoch)):
                    ed.volume += tvol
                    ed.nb_trades += 1
                if (tid > mostRecentID):
                    mostRecentID = tid
                    mostRecentDate = tdate
                    mostRecentPrice = float(t['price'])
        except Exception as e:
            self.logger.write('error buildData %s' % e)
            return None

        #if ( self.book_fetch_full ):
        #    self.book = book
        #    self.book_fetch_full = False
        #else:
        #    book = self.book

        try:
            for b in book['bids']:
                bprice = float(b[0])
                bvol = float(b[1])
                ed.bids.append([bprice, bvol])
                ed.total_bid += bprice * bvol
            ed.bids.sort(reverse=True)

            for a in book['asks']:
                aprice = float(a[0])
                avol = float(a[1])
                ed.asks.append([aprice, avol])
                ed.total_ask += avol
            ed.asks.sort()
        except Exception as e:
            self.logger.write('error buildData %s' % e)
            return None

        try:
            if (mostRecentID != 0):
                self.mostRecentPrice = mostRecentPrice
            if (self.mostRecentPrice == 0):
                self.mostRecentPrice = ed.bids[0][0]
            if (mostRecentID != 0):
                self.mostRecentTransactionID = mostRecentID
                self.mostRecentTransaction = mostRecentDate
            ed.rate = self.mostRecentPrice
            ed.lag = lag
            ed.ask_value = ed.asks[0][0]
            ed.bid_value = ed.bids[0][0]
            ed.USD_conv_rate = self.EUR_USD_rate
        except Exception as e:
            self.logger.write('error buildData %s' % e)
            return None

        return ed
コード例 #16
0
    def buildData ( self, book, trades, lag ):
        ed = coinwatcher.ExchangeData ( )

        mostRecentID = self.mostRecentTransactionID
        mostRecentPrice = self.mostRecentPrice
        try:
            for t in trades:
                tid = int ( t['tid'] )
                if ( 'ammount' in t ):
                    tvol = float ( t['ammount'] )
                else:
                    tvol = float ( t['amount'] )
                tdate = float ( t['date'] )
                if ( ( tid > self.mostRecentTransactionID ) and ( tdate > self.epoch ) ):
                    ed.volume += tvol
                    ed.nb_trades += 1
                if ( tid > mostRecentID ):
                    mostRecentID = tid
                    mostRecentPrice = float ( t['price'] )
        except Exception:
            self.logger.write ( 'error buildData trades\n' + str(traceback.format_exc()) )
            return None

        try:
            bstr = 'bids'
            astr = 'asks'
            if ( float(book['bids'][0][0]) > float(book['asks'][0][0]) ):
                bstr = 'asks'
                astr = 'bids'
            maxbprice = max ( [ float(b[0]) for b in book[bstr] ] )
            for b in book[bstr]:
                bprice = float ( b[0] )
                bvol = float ( b[1] )
                if ( (maxbprice-bprice) < 700 ):
                    ed.bids.append ( [ bprice, bvol ] )
                ed.total_bid += bprice * bvol
            ed.bids.sort ( reverse=True )

            minaprice = min ( [ float(a[0]) for a in book[astr] ] )
            for a in book[astr]:
                aprice = float ( a[0] )
                avol = float ( a[1] )
                if ( (aprice-minaprice) < 700 ):
                    ed.asks.append ( [ aprice, avol ] )
                ed.total_ask += avol
            ed.asks.sort ( )
        except Exception:
            self.logger.write ( 'error buildData book\n' + str(traceback.format_exc()) )
            return None

        try:
            if ( mostRecentID != 0 ):
                self.mostRecentPrice = mostRecentPrice
            if ( self.mostRecentPrice == 0 ):
                self.mostRecentPrice = ed.bids[0][0]
            if ( mostRecentID != 0 ):
                self.mostRecentTransactionID = mostRecentID
            ed.rate = self.mostRecentPrice
            ed.lag = lag
            ed.ask_value = ed.asks[0][0]
            ed.bid_value = ed.bids[0][0]
        except Exception:
            self.logger.write ( 'error buildData ticker\n' + str(traceback.format_exc()) )
            return None

        return ed
コード例 #17
0
    def buildData(self, book, trades, lag):
        ed = coinwatcher.ExchangeData()

        mostRecentID = self.mostRecentTransactionID
        mostRecentDate = 0
        mostRecentPrice = self.mostRecentPrice
        trades_list = []
        tid_str = 'id'
        try:
            trades_list = trades['trades']
        except:
            # sometimes, we get data with a different format
            trades_list = trades['orders']
            tid_str = 'id'
        try:
            for t in trades_list:
                tid = int(t[tid_str])
                tvol = float(t['amount'])
                tdate = float(t['date'])
                if ((tid > self.mostRecentTransactionID)
                        and (tdate > self.epoch)):
                    ed.volume += tvol
                    ed.nb_trades += 1
                if (tid > mostRecentID):
                    mostRecentID = tid
                    mostRecentDate = tdate
                    mostRecentPrice = float(t['price'])
        except Exception:
            print trades
            self.logger.write('error: buildData() failed with trades\n' +
                              str(traceback.format_exc()))
            return None

        bids_list = []
        asks_list = []
        try:
            bids_list = book['orderbook']['bids']
            asks_list = book['orderbook']['asks']
        except:
            # sometimes, we get data with a different format
            bids_list = book['bids']
            asks_list = book['asks']
        try:
            maxbprice = max([float(b[0]) for b in bids_list])
            for b in bids_list:
                bprice = float(b[0])
                bvol = float(b[1])
                if ((maxbprice - bprice) < 700):
                    ed.bids.append([bprice, bvol])
                ed.total_bid += bprice * bvol
            ed.bids.sort(reverse=True)

            minaprice = min([float(a[0]) for a in asks_list])
            for a in asks_list:
                aprice = float(a[0])
                avol = float(a[1])
                if ((aprice - minaprice) < 700):
                    ed.asks.append([aprice, avol])
                ed.total_ask += avol
            ed.asks.sort()
        except Exception:
            self.logger.write('error: buildData() failed with book\n' +
                              str(traceback.format_exc()))
            return None

        try:
            if (mostRecentDate != 0):
                self.mostRecentPrice = mostRecentPrice
            if (self.mostRecentPrice == 0):
                self.mostRecentPrice = ed.bids[0][0]
            if (mostRecentDate != 0):
                self.mostRecentTransactionID = mostRecentID
            ed.rate = self.mostRecentPrice
            ed.lag = lag
            ed.ask_value = ed.asks[0][0]
            ed.bid_value = ed.bids[0][0]
            ed.USD_conv_rate = self.CAD_USD_rate
        except Exception:
            self.logger.write('error: buildData() failed with ticker\n' +
                              str(traceback.format_exc()))
            return None

        return ed