Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Increase the usage of augmented assignment statements #176

Open
elfring opened this issue Nov 3, 2021 · 0 comments
Open

Increase the usage of augmented assignment statements #176

elfring opened this issue Nov 3, 2021 · 0 comments

Comments

@elfring
Copy link

elfring commented Nov 3, 2021

馃憖 Some source code analysis tools can help to find opportunities for improving software components.
馃挱 I propose to increase the usage of augmented assignment statements accordingly.

diff --git a/qtpylib/broker.py b/qtpylib/broker.py
index 8c3461a..54cdade 100644
--- a/qtpylib/broker.py
+++ b/qtpylib/broker.py
@@ -698,7 +698,7 @@ class Broker():
             self.orders.recent[orderId]['price'] = 0
 
         # add orderId / ttl to (auto-adds to history)
-        expiry = expiry * 1000 if expiry > 0 else 60000  # 1min
+        expiry *= 1000 if expiry > 0 else 60000  # 1min
         self._update_pending_order(symbol, orderId, expiry, order_quantity)
         time.sleep(0.1)
 
diff --git a/qtpylib/futures.py b/qtpylib/futures.py
index 773034c..bfca38f 100644
--- a/qtpylib/futures.py
+++ b/qtpylib/futures.py
@@ -140,13 +140,13 @@ def create_continuous_contract(df, resolution="1T"):
     contract.drop(['expiry_y', 'expiry_x'], axis=1, inplace=True)
 
     try:
-        contract['open'] = contract['open'] + contract['gap']
-        contract['high'] = contract['high'] + contract['gap']
-        contract['low'] = contract['low'] + contract['gap']
-        contract['close'] = contract['close'] + contract['gap']
+        contract['open'] += contract['gap']
+        contract['high'] += contract['gap']
+        contract['low'] += contract['gap']
+        contract['close'] += contract['gap']
         # contract['volume'] = df['volume'].resample("D").sum()
     except Exception as e:
-        contract['last'] = contract['last'] + contract['gap']
+        contract['last'] += contract['gap']
 
     contract.drop(['gap'], axis=1, inplace=True)
 
diff --git a/qtpylib/tools.py b/qtpylib/tools.py
index 67720ef..9fa9eb5 100644
--- a/qtpylib/tools.py
+++ b/qtpylib/tools.py
@@ -464,7 +464,7 @@ def get_timezone(as_timedelta=False):
         offset_hour = -(datetime.datetime.now() -
                         datetime.datetime.utcnow()).seconds
 
-    offset_hour = offset_hour // 3600
+    offset_hour //= 3600
     offset_hour = offset_hour if offset_hour < 10 else offset_hour // 10
 
     if as_timedelta:
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant