Esempio n. 1
0
 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),
     ]
Esempio n. 2
0
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)
Esempio n. 3
0
    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
Esempio n. 4
0
    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
Esempio n. 5
0
 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)
Esempio n. 6
0
 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
Esempio n. 8
0
    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
Esempio n. 9
0
    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))]
Esempio n. 10
0
    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))]
Esempio n. 11
0
 def go_long(self):
     entry = self.price
     qty = utils.size_to_qty(self.capital, entry, fee_rate=self.fee_rate)
     self.buy = qty, entry
Esempio n. 12
0
 def go_long(self):
     qty = utils.size_to_qty(self.capital,
                             self.price,
                             fee_rate=self.fee_rate)
     self.buy = qty, self.price
Esempio n. 13
0
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
Esempio n. 14
0
 def go_short(self):
     qty = utils.size_to_qty(10, self.price)
     self.sell = qty, self.price
Esempio n. 15
0
 def go_long(self):
     qty = utils.size_to_qty(100, self.price)
     self.buy = qty, self.price
Esempio n. 16
0
 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