示例#1
0
    def __init__(self, bot: TradingBot, bars: list):
        self.bars: List[Bar] = bars
        self.bot = bot
        self.bot.prepare(SilentLogger(), self)

        self.market_slipage_percent = 0.15
        self.maker_fee = -0.00025
        self.taker_fee = 0.00075

        self.symbol: Symbol = Symbol(symbol="XBTUSD",
                                     isInverse=True,
                                     tickSize=0.5,
                                     lotSize=1,
                                     makerFee=-0.00025,
                                     takerFee=0.00075)

        self.account: Account = None
        self.initialEquity = 100  # BTC

        self.hh = self.initialEquity
        self.maxDD = 0
        self.max_underwater = 0
        self.underwater = 0
        self.maxExposure = 0
        self.lastHHPosition = 0

        self.current_bars = []

        self.reset()
示例#2
0
    def get_instrument(self, symbol=None):
        if symbol is None:
            symbol = self.symbol
        instr: binance_f.model.exchangeinformation.ExchangeInformation = self.client.get_exchange_information(
        )
        for symb in instr.symbols:
            if symb.symbol == symbol:
                baseLength = len(symb.baseAsset)
                lotSize = 1
                tickSize = 1
                for filterIt in symb.filters:
                    if filterIt['filterType'] == 'LOT_SIZE':
                        lotSize = float(filterIt['stepSize'])
                    if filterIt['filterType'] == 'PRICE_FILTER':
                        tickSize = float(filterIt['tickSize'])

                return Symbol(
                    symbol=symb.symbol,
                    isInverse=symb.baseAsset != symb.symbol[:baseLength],
                    lotSize=lotSize,
                    tickSize=tickSize,
                    makerFee=0.02,
                    takerFee=0.04,
                    pricePrecision=symb.pricePrecision,
                    quantityPrecision=symb.quantityPrecision)
        return None
示例#3
0
 def get_instrument(self, symbol=None):
     if symbol is None:
         symbol = self.symbol
     instrument = self.bitmex.instrument(symbol)
     symbolInfo: Symbol = Symbol(symbol=instrument['symbol'],
                                 isInverse=instrument['isInverse'],
                                 lotSize=instrument['lotSize'],
                                 tickSize=instrument['tickSize'],
                                 makerFee=instrument['makerFee'],
                                 takerFee=instrument['takerFee'])
     return symbolInfo
示例#4
0
 def get_instrument(self, symbol=None):
     if symbol is None:
         symbol = self.symbol
     instr = self._execute(self.bybit.Symbol.Symbol_get())
     for entry in instr:
         if entry['name'] == symbol:
             return Symbol(symbol=entry['name'],
                           isInverse=True,  # all bybit is inverse
                           lotSize=entry['lot_size_filter']['qty_step'],
                           tickSize=entry['price_filter']['tick_size'],
                           makerFee=entry['maker_fee'],
                           takerFee=entry['taker_fee'])
     return None
 def get_instrument(self, symbol=None):
     if symbol is None:
         symbol = self.symbol
     instr = self._execute(self.bybit.Symbol.Symbol_get())
     for entry in instr:
         if entry['name'] == symbol:
             return Symbol(symbol=entry['name'],
                           isInverse=True,  # all bybit is inverse
                           lotSize=float(entry['lot_size_filter']['qty_step']),
                           tickSize=float(entry['price_filter']['tick_size']),
                           makerFee=float(entry['maker_fee']),
                           takerFee=float(entry['taker_fee']),
                           pricePrecision=entry['price_scale'],
                           quantityPrecision=0)  # hardcoded full dollars
     return None
示例#6
0
 def get_instrument(self, symbol=None):
     if symbol is None:
         symbol = self.symbol
     instr = self._execute(self.bybit.Symbol.Symbol_get())
     for entry in instr:
         if entry['name'] == symbol:
             return Symbol(symbol=entry['name'],
                           isInverse=entry["quote_currency"] != "USDT",  # USDT is linear
                           lotSize=float(entry['lot_size_filter']['qty_step']),
                           tickSize=float(entry['price_filter']['tick_size']),
                           makerFee=float(entry['maker_fee']),
                           takerFee=float(entry['taker_fee']),
                           pricePrecision=entry['price_scale'],
                           quantityPrecision=3 if entry["quote_currency"] == "USDT" else 0)  # hardcoded 5 digits FIXME!
     return None
示例#7
0
    def __init__(self,
                 bot: TradingBot,
                 bars: list,
                 funding: dict = None,
                 symbol: Symbol = None,
                 market_slipage_percent=0.15):
        self.bars: List[Bar] = bars
        self.funding = funding
        self.firstFunding = 9999999999
        self.lastFunding = 0
        if funding is not None:
            for key in funding.keys():
                self.firstFunding = min(self.firstFunding, key)
                self.lastFunding = max(self.lastFunding, key)

        self.logger = bot.logger
        self.bot = bot
        self.bot.prepare(SilentLogger(), self)

        self.market_slipage_percent = market_slipage_percent
        self.maker_fee = -0.00025
        self.taker_fee = 0.00075

        if symbol is not None:
            self.symbol = symbol
        else:
            self.symbol: Symbol = Symbol(symbol="XBTUSD",
                                         isInverse=True,
                                         tickSize=0.5,
                                         lotSize=1,
                                         makerFee=-0.00025,
                                         takerFee=0.00075)

        self.account: Account = None
        self.initialEquity = 100  # BTC

        self.hh = self.initialEquity
        self.maxDD = 0
        self.max_underwater = 0
        self.underwater = 0
        self.maxExposure = 0
        self.lastHHPosition = 0

        self.current_bars: List[Bar] = []

        self.reset()
 def get_instrument(self, symbol=None):
     if symbol is None:
         symbol = self.symbol
     api_symb = self.client.query_products()
     for symb in api_symb["data"]:
         if symb['symbol'] == symbol:
             settle = symb['settlementCurrency']
             self.priceScale = pow(10, symb['priceScale'])
             self.valueScale = pow(10, symb['valueScale'])
             self.ratioScale = pow(10, symb['ratioScale'])
             return Symbol(
                 symbol=symb['symbol'],
                 isInverse=True if symbol[:len(settle)] else False,
                 lotSize=float(symb['lotSize']),
                 tickSize=float(symb['tickSize']),
                 makerFee=symb['makerFeeRateEr'] / self.ratioScale,
                 takerFee=symb['takerFeeRateEr'] / self.ratioScale)
     return None
示例#9
0
#bars_m = load_bars(30 * 12, 240,0,'bitmex')

#bars_b = load_bars(30 * 12, 60,0,'bybit')
#bars_m = load_bars(30 * 24, 60,0,'bitmex')

#bars1= load_bars(24)
#bars2= process_low_tf_bars(m1_bars, 240, 60)
#bars3= process_low_tf_bars(m1_bars, 240, 120)
#bars4= process_low_tf_bars(m1_bars, 240, 180)

symbol = None
if pair == "BTCUSD":
    symbol = Symbol(symbol="BTCUSD",
                    isInverse=True,
                    tickSize=0.5,
                    lotSize=1.0,
                    makerFee=-0.025,
                    takerFee=0.075,
                    quantityPrecision=2,
                    pricePrecision=2)
elif pair == "XRPUSD":
    symbol = Symbol(symbol="XRPUSD",
                    isInverse=True,
                    tickSize=0.0001,
                    lotSize=0.01,
                    makerFee=-0.025,
                    takerFee=0.075,
                    quantityPrecision=2,
                    pricePrecision=4)
elif pair == "ETHUSD":
    symbol = Symbol(symbol="ETHUSD",
                    isInverse=True,
示例#10
0
#bars1= load_bars(24)
#bars2= process_low_tf_bars(m1_bars, 240, 60)
#bars3= process_low_tf_bars(m1_bars, 240, 120)
#bars4= process_low_tf_bars(m1_bars, 240, 180)

#runOpti(bars_m,[1],[63],[1])

#checkDayFilterByDay(bars_m)

runOpti(bars_n,
        [0,0 ,0  ,10,8 ,5 ,-10],
        [1,10,2  ,20,16,30, 10],
        [1,1 ,0.5,2 ,2 ,5 ,  2],
        symbol=Symbol(symbol="BTCUSDT", isInverse=False, tickSize=0.001,
                                      lotSize=0.00001, makerFee=0.02,
                                     takerFee=0.04),
        randomCount=500)


'''
bot=MultiStrategyBot(logger=logger, directionFilter= 0)
bot.add_strategy(KuegiStrategy(
...
                 )
                 
bot.add_strategy(SfpStrategy(
...
                 )
b= BackTest(bot, bars_b).run()
示例#11
0
#bars_p = load_bars(30 * 12, 240,0,'phemex')
#bars_n = load_bars(30 * 12, 240,0,'binance')
#bars_ns = load_bars(30 * 24, 240,0,'binanceSpot')
bars_b = load_bars(30 * 18, 240,0,'bybit',"ETHUSD")
#bars_m = load_bars(30 * 12, 240,0,'bitmex')

#bars_b = load_bars(30 * 12, 60,0,'bybit')
#bars_m = load_bars(30 * 24, 60,0,'bitmex')

#bars1= load_bars(24)
#bars2= process_low_tf_bars(m1_bars, 240, 60)
#bars3= process_low_tf_bars(m1_bars, 240, 120)
#bars4= process_low_tf_bars(m1_bars, 240, 180)

symbol=Symbol(symbol="ETHUSD", isInverse=True, tickSize=0.05, lotSize=1.0, makerFee=-0.025,takerFee=0.075, quantityPrecision=2,pricePrecision=2)
#symbol=Symbol(symbol="BTCUSD", isInverse=True, tickSize=0.5, lotSize=1.0, makerFee=-0.025,takerFee=0.075, quantityPrecision=2,pricePrecision=2)
#for binance
#symbol=Symbol(symbol="BTCUSDT", isInverse=False, tickSize=0.001, lotSize=0.00001, makerFee=0.02, takerFee=0.04, quantityPrecision=5)

bars_full= bars_b
oos_cut=int(len(bars_full)/4)
bars= bars_full[oos_cut:]
bars_oos= bars_full[:oos_cut]


'''
checkDayFilterByDay(bars,symbol=symbol)

#'''