Skip to content

Commit 0c4c63f

Browse files
committed
feat: cosider is_buy and remove try-catch
1 parent f0fb22d commit 0c4c63f

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

examples/basic_tpsl.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ def main():
1616
position_is_long = args.is_buy
1717
quantity = 1
1818
px = 184.80
19-
tp = px * 1.05 # take profit at +5%
20-
sl = px * 0.95 # stop loss at -5%
19+
tpsl_percent = 0.05 # 5%
20+
21+
tp = px * (1 + (tpsl_percent * (1 if position_is_long else -1)))
22+
sl = px * (1 - (tpsl_percent * (1 if position_is_long else -1)))
2123

2224
orders = [
2325
{
@@ -59,11 +61,8 @@ def main():
5961
},
6062
]
6163

62-
try:
63-
resp = exchange.bulk_orders(orders, grouping="normalTpsl")
64-
print(resp)
65-
except Exception as e:
66-
print(e)
64+
resp = exchange.bulk_orders(orders, grouping="normalTpsl")
65+
print(resp)
6766

6867

6968
if __name__ == "__main__":

0 commit comments

Comments
 (0)