Exemplo n.º 1
0
def getPrice(connection, f, tmp_f, pair="btc_usd"):

    #get ticker
    ticker = btceapi.getTicker(pair, connection)
    #print ticker.high

    #get asks/bids
    asks, bids = btceapi.getDepth(pair)
    ask_prices, ask_volumes = zip(*asks)
    bid_prices, bid_volumes = zip(*bids)

    #start list with all of the ticker info
    curTrades = trades(coin='ltc',
                       updated=ticker.updated,
                       server_time=ticker.server_time,
                       buy=ticker.buy,
                       sell=ticker.sell)
    #print out_list
    #now we have a huge list with all the info, write to a single line in the csv file

    line = ','.join(
        (pair, str(time.mktime(time.localtime())), str(curTrades.buy))) + '\n'
    #print line
    f.write(line)
    tmp_f.write(line)
Exemplo n.º 2
0
def getPrice(connection,f,pair="btc_usd"):
    
    #get ticker
    ticker = btceapi.getTicker(pair, connection)
    #print ticker.high
    
    #get asks/bids
    asks, bids = btceapi.getDepth(pair)
    ask_prices, ask_volumes = zip(*asks)
    bid_prices, bid_volumes = zip(*bids)

    #start list with all of the ticker info
    curTrades = trades(coin='ltc',updated=ticker.updated,server_time=ticker.server_time,buy=ticker.buy,sell=ticker.sell)
    #print out_list
    #now we have a huge list with all the info, write to a single line in the csv file
    
    line = ','.join((pair,str(time.mktime(time.localtime())),str(curTrades.buy)))+'\n'
    #print line
    f.write(line)
Exemplo n.º 3
0
def getPrice(connection,f,pair="btc_usd"):
    
    #get ticker
    ticker = btceapi.getTicker(pair, connection)
    #print ticker.high
    #get asks/bids
    asks, bids = btceapi.getDepth(pair)
    ask_prices, ask_volumes = zip(*asks)
    bid_prices, bid_volumes = zip(*bids)

    #start list with all of the ticker info
    curTrades = trades(coin='ltc',updated=ticker.updated,server_time=ticker.server_time,buy=ticker.buy,sell=ticker.sell)
    #print out_list
    #now we have a huge list with all the info, write to a single line in the csv file
    
    
    print pair
    print curTrades.buy
    # Pickle class using protocol 0.
    pickle.dump(curTrades,f) 
                                 parse_dates=True,
                                 date_parser=functools.partial(datetime.datetime.strptime, format = "%m/%d/%Y"))
##    data[sheet_name].columns = ['DateTime', 'Open', 'High', 'Low', 'Close', 'Volume']
    data[sheet_name].columns = ['DateTime', 'Close']
outrights = xls.sheet_names[0:12]
flies = xls.sheet_names[12:]

ButterflyData = data['BL-'+ButterflyName.upper()+' Comdty']
OutrightData = data['L '+OutrightName.upper()+' Comdty']

rolling_window = 20
trade_recorder = {}
m = pd.merge(OutrightData, ButterflyData, on = "DateTime", suffixes = ('_'+OutrightName, '_'+ButterflyName))
for i in range(HedgeRatioFrom, HedgeRatioTo,1):
    index = 'hr_'+i.__str__()
    trade_recorder[index] = trades()
    m[index] = m['Close_'+OutrightName] + i*m['Close_'+ButterflyName]
    m[index+'_mean'] = pd.rolling_mean(m[index], rolling_window)
    m[index+'_std']  = pd.rolling_var (m[index], rolling_window)
    for rn in range(1,len(m)):
        if (m.iloc[rn-1][index] > m.iloc[rn-1][index+'_mean'] + EntryStd*m.iloc[rn-1][index+'_std']) and\
           (m.iloc[rn][index] < m.iloc[rn-1][index+'_mean'] + EntryStd*m.iloc[rn-1][index+'_std']) and\
           (trade_recorder[index].position == 0):
            trade_recorder[index].add(m.iloc[rn]['DateTime'],
                                      m.iloc[rn-1][index+'_mean'] + EntryStd*m.iloc[rn-1][index+'_std'],
                                      -1,
                                      "EnterShort")
        if m.iloc[rn-1][index] < m.iloc[rn-1][index+'_mean'] - EntryStd*m.iloc[rn-1][index+'_std'] and\
           m.iloc[rn][index] > m.iloc[rn-1][index+'_mean'] - EntryStd*m.iloc[rn-1][index+'_std'] and\
           trade_recorder[index].position == 0:
            trade_recorder[index].add(m.iloc[rn]['DateTime'],