replace single quote docstrings with double quote docstrings

This commit is contained in:
Sam Germain 2022-01-14 05:49:46 -06:00
parent 7abffee755
commit 0c8205ab3b
5 changed files with 54 additions and 51 deletions

View File

@ -139,8 +139,11 @@ class Binance(Exchange):
[amt, old_ratio] = [None, None] [amt, old_ratio] = [None, None]
brackets = [] brackets = []
for [notional_floor, mm_ratio] in brkts: for [notional_floor, mm_ratio] in brkts:
amt = ((float(notional_floor) * (float(mm_ratio) - float(old_ratio))) + amt = (
amt) if old_ratio else 0 (
(float(notional_floor) * (float(mm_ratio)) - float(old_ratio))
) + amt
) if old_ratio else 0
old_ratio = mm_ratio old_ratio = mm_ratio
brackets.append([ brackets.append([
float(notional_floor), float(notional_floor),
@ -234,14 +237,14 @@ class Binance(Exchange):
pair: str, pair: str,
nominal_value: Optional[float] = 0.0, nominal_value: Optional[float] = 0.0,
): ):
''' """
Maintenance amt = Floor of Position Bracket on Level n * Maintenance amt = Floor of Position Bracket on Level n *
difference between difference between
Maintenance Margin Rate on Level n and Maintenance Margin Rate on Level n and
Maintenance Margin Rate on Level n-1) Maintenance Margin Rate on Level n-1)
+ Maintenance Amount on Level n-1 + Maintenance Amount on Level n-1
https://www.binance.com/en/support/faq/b3c689c1f50a44cabb3a84e663b81d93 https://www.binance.com/en/support/faq/b3c689c1f50a44cabb3a84e663b81d93
''' """
if pair not in self._leverage_brackets: if pair not in self._leverage_brackets:
raise InvalidOrderException(f"Cannot calculate liquidation price for {pair}") raise InvalidOrderException(f"Cannot calculate liquidation price for {pair}")
pair_brackets = self._leverage_brackets[pair] pair_brackets = self._leverage_brackets[pair]

View File

@ -1985,10 +1985,10 @@ class Exchange:
@retrier @retrier
def get_liquidation_price(self, pair: str): def get_liquidation_price(self, pair: str):
''' """
Set's the margin mode on the exchange to cross or isolated for a specific pair Set's the margin mode on the exchange to cross or isolated for a specific pair
:param pair: base/quote currency pair (e.g. "ADA/USDT") :param pair: base/quote currency pair (e.g. "ADA/USDT")
''' """
if self._config['dry_run'] or not self.exchange_has("fetchPositions"): if self._config['dry_run'] or not self.exchange_has("fetchPositions"):
# Some exchanges only support one collateral type # Some exchanges only support one collateral type
return return
@ -2008,9 +2008,9 @@ class Exchange:
pair: str, pair: str,
nominal_value: Optional[float] = 0.0, nominal_value: Optional[float] = 0.0,
): ):
''' """
:return: The maintenance amount, and maintenance margin rate :return: The maintenance amount, and maintenance margin rate
''' """
# TODO-lev: return the real amounts # TODO-lev: return the real amounts
return 0, 0.4 return 0, 0.4

View File

@ -266,7 +266,7 @@ def okex(
interest: float, interest: float,
position_assets: float position_assets: float
): ):
''' """
PERPETUAL: https://www.okex.com/support/hc/en-us/articles/ PERPETUAL: https://www.okex.com/support/hc/en-us/articles/
360053909592-VI-Introduction-to-the-isolated-mode-of-Single-Multi-currency-Portfolio-margin 360053909592-VI-Introduction-to-the-isolated-mode-of-Single-Multi-currency-Portfolio-margin
@ -293,7 +293,7 @@ def okex(
short: (liability + interest* (1 + maintenance margin ratio) * short: (liability + interest* (1 + maintenance margin ratio) *
(1 + taker fee rate) (1 + taker fee rate)
''' """
if trading_mode == TradingMode.FUTURES and collateral == Collateral.ISOLATED: if trading_mode == TradingMode.FUTURES and collateral == Collateral.ISOLATED:
if is_short: if is_short:
return (liability + interest) * (1 + mm_ratio) * (1 + taker_fee_rate) return (liability + interest) * (1 + mm_ratio) * (1 + taker_fee_rate)

View File

@ -3638,41 +3638,41 @@ def test__fetch_and_calculate_funding_fees(
amount, amount,
expected_fees expected_fees
): ):
''' """
nominal_value = mark_price * size nominal_value = mark_price * size
funding_fee = nominal_value * funding_rate funding_fee = nominal_value * funding_rate
size: 30 size: 30
time: 0, mark: 2.77, nominal_value: 83.1, fundRate: -0.000008, fundFee: -0.0006648 time: 0, mark: 2.77, nominal_value: 83.1, fundRate: -0.000008, fundFee: -0.0006648
time: 1, mark: 2.73, nominal_value: 81.9, fundRate: -0.000004, fundFee: -0.0003276 time: 1, mark: 2.73, nominal_value: 81.9, fundRate: -0.000004, fundFee: -0.0003276
time: 2, mark: 2.74, nominal_value: 82.2, fundRate: 0.000012, fundFee: 0.0009864 time: 2, mark: 2.74, nominal_value: 82.2, fundRate: 0.000012, fundFee: 0.0009864
time: 3, mark: 2.76, nominal_value: 82.8, fundRate: -0.000003, fundFee: -0.0002484 time: 3, mark: 2.76, nominal_value: 82.8, fundRate: -0.000003, fundFee: -0.0002484
time: 4, mark: 2.76, nominal_value: 82.8, fundRate: -0.000007, fundFee: -0.0005796 time: 4, mark: 2.76, nominal_value: 82.8, fundRate: -0.000007, fundFee: -0.0005796
time: 5, mark: 2.77, nominal_value: 83.1, fundRate: 0.000003, fundFee: 0.0002493 time: 5, mark: 2.77, nominal_value: 83.1, fundRate: 0.000003, fundFee: 0.0002493
time: 6, mark: 2.78, nominal_value: 83.4, fundRate: 0.000019, fundFee: 0.0015846 time: 6, mark: 2.78, nominal_value: 83.4, fundRate: 0.000019, fundFee: 0.0015846
time: 7, mark: 2.78, nominal_value: 83.4, fundRate: 0.000003, fundFee: 0.0002502 time: 7, mark: 2.78, nominal_value: 83.4, fundRate: 0.000003, fundFee: 0.0002502
time: 8, mark: 2.77, nominal_value: 83.1, fundRate: -0.000003, fundFee: -0.0002493 time: 8, mark: 2.77, nominal_value: 83.1, fundRate: -0.000003, fundFee: -0.0002493
time: 9, mark: 2.77, nominal_value: 83.1, fundRate: 0, fundFee: 0.0 time: 9, mark: 2.77, nominal_value: 83.1, fundRate: 0, fundFee: 0.0
time: 10, mark: 2.84, nominal_value: 85.2, fundRate: 0.000013, fundFee: 0.0011076 time: 10, mark: 2.84, nominal_value: 85.2, fundRate: 0.000013, fundFee: 0.0011076
time: 11, mark: 2.81, nominal_value: 84.3, fundRate: 0.000077, fundFee: 0.0064911 time: 11, mark: 2.81, nominal_value: 84.3, fundRate: 0.000077, fundFee: 0.0064911
time: 12, mark: 2.81, nominal_value: 84.3, fundRate: 0.000072, fundFee: 0.0060696 time: 12, mark: 2.81, nominal_value: 84.3, fundRate: 0.000072, fundFee: 0.0060696
time: 13, mark: 2.82, nominal_value: 84.6, fundRate: 0.000097, fundFee: 0.0082062 time: 13, mark: 2.82, nominal_value: 84.6, fundRate: 0.000097, fundFee: 0.0082062
size: 50 size: 50
time: 0, mark: 2.77, nominal_value: 138.5, fundRate: -0.000008, fundFee: -0.001108 time: 0, mark: 2.77, nominal_value: 138.5, fundRate: -0.000008, fundFee: -0.001108
time: 1, mark: 2.73, nominal_value: 136.5, fundRate: -0.000004, fundFee: -0.000546 time: 1, mark: 2.73, nominal_value: 136.5, fundRate: -0.000004, fundFee: -0.000546
time: 2, mark: 2.74, nominal_value: 137.0, fundRate: 0.000012, fundFee: 0.001644 time: 2, mark: 2.74, nominal_value: 137.0, fundRate: 0.000012, fundFee: 0.001644
time: 3, mark: 2.76, nominal_value: 138.0, fundRate: -0.000003, fundFee: -0.000414 time: 3, mark: 2.76, nominal_value: 138.0, fundRate: -0.000003, fundFee: -0.000414
time: 4, mark: 2.76, nominal_value: 138.0, fundRate: -0.000007, fundFee: -0.000966 time: 4, mark: 2.76, nominal_value: 138.0, fundRate: -0.000007, fundFee: -0.000966
time: 5, mark: 2.77, nominal_value: 138.5, fundRate: 0.000003, fundFee: 0.0004155 time: 5, mark: 2.77, nominal_value: 138.5, fundRate: 0.000003, fundFee: 0.0004155
time: 6, mark: 2.78, nominal_value: 139.0, fundRate: 0.000019, fundFee: 0.002641 time: 6, mark: 2.78, nominal_value: 139.0, fundRate: 0.000019, fundFee: 0.002641
time: 7, mark: 2.78, nominal_value: 139.0, fundRate: 0.000003, fundFee: 0.000417 time: 7, mark: 2.78, nominal_value: 139.0, fundRate: 0.000003, fundFee: 0.000417
time: 8, mark: 2.77, nominal_value: 138.5, fundRate: -0.000003, fundFee: -0.0004155 time: 8, mark: 2.77, nominal_value: 138.5, fundRate: -0.000003, fundFee: -0.0004155
time: 9, mark: 2.77, nominal_value: 138.5, fundRate: 0, fundFee: 0.0 time: 9, mark: 2.77, nominal_value: 138.5, fundRate: 0, fundFee: 0.0
time: 10, mark: 2.84, nominal_value: 142.0, fundRate: 0.000013, fundFee: 0.001846 time: 10, mark: 2.84, nominal_value: 142.0, fundRate: 0.000013, fundFee: 0.001846
time: 11, mark: 2.81, nominal_value: 140.5, fundRate: 0.000077, fundFee: 0.0108185 time: 11, mark: 2.81, nominal_value: 140.5, fundRate: 0.000077, fundFee: 0.0108185
time: 12, mark: 2.81, nominal_value: 140.5, fundRate: 0.000072, fundFee: 0.010116 time: 12, mark: 2.81, nominal_value: 140.5, fundRate: 0.000072, fundFee: 0.010116
time: 13, mark: 2.82, nominal_value: 141.0, fundRate: 0.000097, fundFee: 0.013677 time: 13, mark: 2.82, nominal_value: 141.0, fundRate: 0.000097, fundFee: 0.013677
''' """
d1 = datetime.strptime(f"{d1} +0000", '%Y-%m-%d %H:%M:%S %z') d1 = datetime.strptime(f"{d1} +0000", '%Y-%m-%d %H:%M:%S %z')
d2 = datetime.strptime(f"{d2} +0000", '%Y-%m-%d %H:%M:%S %z') d2 = datetime.strptime(f"{d2} +0000", '%Y-%m-%d %H:%M:%S %z')
funding_rate_history = { funding_rate_history = {

View File

@ -723,7 +723,7 @@ def test_process_informative_pairs_added(default_conf_usdt, ticker_usdt, mocker)
def test_execute_entry(mocker, default_conf_usdt, fee, limit_order, def test_execute_entry(mocker, default_conf_usdt, fee, limit_order,
limit_order_open, is_short, trading_mode, limit_order_open, is_short, trading_mode,
exchange_name, margin_mode, liq_price) -> None: exchange_name, margin_mode, liq_price) -> None:
''' """
exchange_name = binance, is_short = true exchange_name = binance, is_short = true
(wb + cum_b - side_1 * position * ep1) / (position * mmr_b - side_1 * position) (wb + cum_b - side_1 * position * ep1) / (position * mmr_b - side_1 * position)
((2 + 0.01) - ((-1) * 0.6 * 10)) / ((0.6 * 0.01) - ((-1) * 0.6)) = 13.217821782178218 ((2 + 0.01) - ((-1) * 0.6 * 10)) / ((0.6 * 0.01) - ((-1) * 0.6)) = 13.217821782178218
@ -740,7 +740,7 @@ def test_execute_entry(mocker, default_conf_usdt, fee, limit_order,
exchange_name = gateio, is_short = false exchange_name = gateio, is_short = false
(open_rate - (wallet_balance / position)) / (1 - (mm_ratio + taker_fee_rate)) (open_rate - (wallet_balance / position)) / (1 - (mm_ratio + taker_fee_rate))
(10 - (2 / 0.6)) / (1 - (0.01 + 0.0002)) = 6.735367414292449 (10 - (2 / 0.6)) / (1 - (0.01 + 0.0002)) = 6.735367414292449
''' """
open_order = limit_order_open[enter_side(is_short)] open_order = limit_order_open[enter_side(is_short)]
order = limit_order[enter_side(is_short)] order = limit_order[enter_side(is_short)]
default_conf_usdt['trading_mode'] = trading_mode default_conf_usdt['trading_mode'] = trading_mode
@ -4828,7 +4828,7 @@ def test_update_funding_fees(
limit_order_open, limit_order_open,
schedule_off schedule_off
): ):
''' """
nominal_value = mark_price * size nominal_value = mark_price * size
funding_fee = nominal_value * funding_rate funding_fee = nominal_value * funding_rate
size = 123 size = 123
@ -4844,7 +4844,7 @@ def test_update_funding_fees(
"XRP/BTC" "XRP/BTC"
time: 0, mark: 1.2, fundRate: 0.00049426, nominal_value: 147.6, fundFee: 0.072952776 time: 0, mark: 1.2, fundRate: 0.00049426, nominal_value: 147.6, fundFee: 0.072952776
time: 8, mark: 1.2, fundRate: 0.00032715, nominal_value: 147.6, fundFee: 0.04828734 time: 8, mark: 1.2, fundRate: 0.00032715, nominal_value: 147.6, fundFee: 0.04828734
''' """
# SETUP # SETUP
time_machine.move_to("2021-09-01 00:00:00 +00:00") time_machine.move_to("2021-09-01 00:00:00 +00:00")