Esempio n. 1
0
    def initPairs(self,assets):
        try:
            if self.pairs:
                for pair in self.pairs:
                    #construct marketDepth for this pair
                    marketDepth = MarketDepth(u.getPairUrl(pair,self.url_depth),
                                              self.regex_bid_ask,self.index_bid,self.index_ask,
                                              self.regex_price_volume,self.index_price,self.index_volume)
                    self.pairs.update({pair:marketDepth})

            else:
                l = re.findall(self.regex_info,u.getHttpResponse(self.url_info))
                self.pairs = {}
                for i in l:
                    #case where pair has no separation (ie: 'BTCUSD')
                    if type(i) is bytes:
                        pair = u.deducePair(i.decode().lower(),assets)
                    #case where pair has separation (ie: 'BTC-USD' or 'BTC_USD' or 'BTC/USD')
                    if type(i) is tuple:
                        pair = (i[0].decode() + '-' + i[1].decode()).lower()

                    #construct marketDepth for this pair
                    marketDepth = MarketDepth(u.getPairUrl(pair,self.url_depth),
                                      self.regex_bid_ask,self.index_bid,self.index_ask,
                                      self.regex_price_volume,self.index_price,self.index_volume)
                    self.pairs.update({pair:marketDepth})

            return 0,''

        except Exception as e:
            return -1,str(e)
Esempio n. 2
0
 def refresh(self):
     bBids,bAsks = re.match(self.regex_bid_ask,u.getHttpResponse(self.url)).group(self.index_bid,self.index_ask)
     self.bids,self.asks = (u.getFloatList(bBids,self.regex_price_volume,self.index_price,self.index_volume,0),
                            u.getFloatList(bAsks,self.regex_price_volume,self.index_price,self.index_volume,1))
Esempio n. 3
0
    from worker import PriceListenerWorker
except ImportError:
    pass

import threading
import time

#test
if __name__=="__main__":

    logger = loggerHandler('test',log_path='log/')
    lock = threading.Lock()
    
    #getHttpResponse
    print('test getHttpResponse: ')
    print(u.getHttpResponse('https://btc-e.com/api/3/depth/btc_usd'))
    print('--------------------------------------')
    
    #getExchangesFromXml
    print('test getExchangesFromXml: ')
    exchanges = u.getExchangesFromXml('exchanges.xml')
    expected_len = 6
    for exchange in exchanges:
        print(exchange)
    if len(exchanges)!=expected_len:
        raise Exception('Expected # exchanges is ' + str(expected_len) +
                        ', only ' + str(len(exchanges)) + ' in the list')
    print('--------------------------------------')
    
    #getAssetsFromXml
    print('test getAssetsFromXml: ')