我正在与BitStamp客户端的ALGO合作,该算好与30分钟的棒一起工作,而不是将每个交易视为bar。
是否有一种"正确"的方式将这些条重新采样为30分钟的间隔?
我可以对比特币经纪人做任何问题,但是我需要BitStampBroker的执行,所以我希望与一个人一起做。
这应该有所帮助:
from pyalgotrade.bitstamp import barfeed
from pyalgotrade.bitstamp import broker
from pyalgotrade import strategy
class Strategy(strategy.BaseStrategy):
def __init__(self, feed, brk):
super(Strategy, self).__init__(feed, brk)
self._instrument = "BTC"
self._bid = None
self._ask = None
self._resampledBF = self.resampleBarFeed(60, self.onResampledBars)
# Subscribe to order book update events to get bid/ask prices to trade.
feed.getOrderBookUpdateEvent().subscribe(self._onOrderBookUpdate)
def _onOrderBookUpdate(self, orderBookUpdate):
bid = orderBookUpdate.getBidPrices()[0]
ask = orderBookUpdate.getAskPrices()[0]
if bid != self._bid or ask != self._ask:
self._bid = bid
self._ask = ask
self.info("Order book updated. Best bid: %s. Best ask: %s" % (self._bid, self._ask))
def onResampledBars(self, dt, bars):
bar = bars[self._instrument]
self.info("Resampled - Price: %s. Volume: %s." % (bar.getClose(), bar.getVolume()))
def onBars(self, bars):
bar = bars[self._instrument]
self.info("Price: %s. Volume: %s." % (bar.getClose(), bar.getVolume()))
def main():
barFeed = barfeed.LiveTradeFeed()
brk = broker.PaperTradingBroker(1000, barFeed)
strat = Strategy(barFeed, brk)
strat.run()
if __name__ == "__main__":
main()