def go_long(self): qty1 = utils.size_to_qty(2000, self.price + 2) qty2 = utils.size_to_qty(2000, self.price + 4) self.buy = [ (qty1, self.price + 2), (qty2, self.price + 4), ]
def test_size_to_qty(): assert utils.size_to_qty(100, 50) == 2 assert utils.size_to_qty(100, 49) == 2.041 with pytest.raises(TypeError): utils.size_to_qty(100, 'invalid_input') utils.size_to_qty('invalid_input', 100) with pytest.raises(TypeError): utils.size_to_qty(100, None) utils.size_to_qty(None, 100)
def go_short(self): # Open short position and use entire balance to sell qty = utils.size_to_qty(self.capital, self.price, fee_rate=self.fee_rate) self.sell = qty, self.price
def go_long(self): # Open long position and use entire balance to buy qty = utils.size_to_qty(self.capital, self.price, fee_rate=self.fee_rate) self.buy = qty, self.price
def go_short(self): qty = utils.size_to_qty(self.capital * 0.1, self.price, fee_rate=self.fee_rate) self.sell = qty, self.price self.vars['greed'] = self.greed self.take_profit = qty * 0.33, self.price - (self.price * self.greed * 0.4 / 100)
def go_long(self): qty = utils.size_to_qty(self.capital, self.price, 3, fee_rate=self.fee_rate) self.buy = qty, self.price self.stop_loss = qty, (self.price * .95) # Willing to lose 5% self.take_profit = qty, (self.price * 1.10) # Take profits at 10%
def go_long(self): # Determines exact entry price "self.buy" and quantity in case we go long # self.price can be mearket price (then market order), or different from market (then stop or limit order) # Open long position and use entire balance to buy qty = utils.size_to_qty(self.capital, self.price, fee_rate=self.fee_rate) self.buy = qty, self.price
def should_long(self): qty = utils.size_to_qty(self.capital, self.price, 3, fee_rate=self.fee_rate) if utils.crossed( self.rsi, 35, direction="above" ) and qty > 0 and self.available_margin > (qty * self.price): return True
def go_long(self): qty = utils.size_to_qty(self.capital * 0.1, self.price, fee_rate=self.fee_rate) self.buy = qty, self.price self.take_profit = [(qty / 3, self.price + (self.price * 0.01)), (qty / 3, self.price + (self.price * 0.02)), (qty / 3, self.price + (self.price * 0.03))]
def go_short(self): qty = utils.size_to_qty(self.capital * 0.1, self.price, fee_rate=self.fee_rate) self.sell = qty, self.price self.take_profit = [(qty / 3, self.price - (self.price * 0.01)), (qty / 3, self.price - (self.price * 0.02)), (qty / 3, self.price - (self.price * 0.03))]
def go_long(self): entry = self.price qty = utils.size_to_qty(self.capital, entry, fee_rate=self.fee_rate) self.buy = qty, entry
def go_long(self): qty = utils.size_to_qty(self.capital, self.price, fee_rate=self.fee_rate) self.buy = qty, self.price
def test_size_to_qty(): assert utils.size_to_qty(100, 50) == 2 assert utils.size_to_qty(100, 49) == 2.04 with pytest.raises(TypeError): utils.size_to_qty(100, 'invalid_input') utils.size_to_qty('invalid_input', 100) with pytest.raises(TypeError): utils.size_to_qty(100, None) utils.size_to_qty(None, 100) # when fee is included assert utils.size_to_qty(100, 50, fee_rate=0.001) == 1.994
def go_short(self): qty = utils.size_to_qty(10, self.price) self.sell = qty, self.price
def go_long(self): qty = utils.size_to_qty(100, self.price) self.buy = qty, self.price
def go_long(self): qty = utils.size_to_qty(2000, 12) self.buy = qty, 12 self.take_profit = qty, 20 self.stop_loss = qty, 10