@@ -89,11 +89,16 @@ def _validate_name(self, name):
89
89
None
90
90
"""
91
91
if not isinstance (name , str ):
92
- raise OperationalException ("The name of the algorithm must be a string" )
93
-
92
+ raise OperationalException (
93
+ "The name of the algorithm must be a string"
94
+ )
95
+
94
96
pattern = re .compile (r"^[a-zA-Z0-9]*$" )
95
97
if not pattern .match (name ):
96
- raise OperationalException ("The name of the algorithm can only contain letters and numbers" )
98
+ raise OperationalException (
99
+ "The name of the algorithm can only contain" +
100
+ " letters and numbers"
101
+ )
97
102
98
103
def initialize_services (
99
104
self ,
@@ -256,19 +261,19 @@ def create_order(
256
261
return self .order_service .create (
257
262
order_data , execute = execute , validate = validate , sync = sync
258
263
)
259
-
264
+
260
265
def has_balance (self , symbol , amount , market = None ):
261
266
"""
262
267
Function to check if the portfolio has enough balance to
263
268
create an order. This function will return True if the
264
- portfolio has enough balance to create an order, False
269
+ portfolio has enough balance to create an order, False
265
270
otherwise.
266
271
267
272
Parameters:
268
273
symbol: The symbol of the asset
269
274
amount: The amount of the asset
270
275
market: The market of the asset
271
-
276
+
272
277
Returns:
273
278
Boolean: True if the portfolio has enough balance
274
279
"""
@@ -309,20 +314,26 @@ def create_limit_order(
309
314
price: The price of the asset
310
315
order_side: The side of the order
311
316
amount (optional): The amount of the asset to trade
312
- amount_trading_symbol (optional): The amount of the trading symbol to trade
313
- percentage (optional): The percentage of the portfolio to allocate to the
317
+ amount_trading_symbol (optional): The amount of the
318
+ trading symbol to trade
319
+ percentage (optional): The percentage of the portfolio
320
+ to allocate to the
314
321
order
315
- percentage_of_portfolio (optional): The percentage of the portfolio to
316
- allocate to the order
317
- percentage_of_position (optional): The percentage of the position to
318
- allocate to the order. (Only supported for SELL orders)
322
+ percentage_of_portfolio (optional): The percentage
323
+ of the portfolio to allocate to the order
324
+ percentage_of_position (optional): The percentage
325
+ of the position to allocate to
326
+ the order. (Only supported for SELL orders)
319
327
precision (optional): The precision of the amount
320
328
market (optional): The market to trade the asset
321
- execute (optional): Default True. If set to True, the order will be executed
322
- validate (optional): Default True. If set to True, the order will be validated
323
- sync (optional): Default True. If set to True, the created order will be synced with the
329
+ execute (optional): Default True. If set to True,
330
+ the order will be executed
331
+ validate (optional): Default True. If set to
332
+ True, the order will be validated
333
+ sync (optional): Default True. If set to True,
334
+ the created order will be synced with the
324
335
portfolio of the algorithm
325
-
336
+
326
337
Returns:
327
338
Order: Instance of the order created
328
339
"""
@@ -369,10 +380,10 @@ def create_limit_order(
369
380
raise OperationalException (
370
381
"The amount parameter is required to create a limit order." +
371
382
"Either the amount, amount_trading_symbol, percentage, " +
372
- "percentage_of_portfolio or percentage_of_position parameter " +
373
- "must be specified."
383
+ "percentage_of_portfolio or percentage_of_position "
384
+ "parameter must be specified."
374
385
)
375
-
386
+
376
387
order_data = {
377
388
"target_symbol" : target_symbol ,
378
389
"price" : price ,
@@ -417,7 +428,7 @@ def create_market_order(
417
428
validate: If set to True, the order will be validated
418
429
sync: If set to True, the created order will be synced with the
419
430
portfolio of the algorithm
420
-
431
+
421
432
Returns:
422
433
Order: Instance of the order created
423
434
"""
@@ -454,7 +465,7 @@ def get_portfolio(self, market=None) -> Portfolio:
454
465
455
466
Parameters:
456
467
market: The market of the portfolio
457
-
468
+
458
469
Returns:
459
470
Portfolio: The portfolio of the algorithm
460
471
"""
@@ -492,7 +503,7 @@ def get_total_size(self):
492
503
"""
493
504
Returns the total size of the portfolio.
494
505
495
- The total size of the portfolio is the unallocated balance and the
506
+ The total size of the portfolio is the unallocated balance and the
496
507
allocated balance of the portfolio.
497
508
498
509
Returns:
@@ -597,7 +608,7 @@ def get_positions(
597
608
amount_lt: The amount of the asset must be less than this
598
609
amount_lte: The amount of the asset must be less than or equal
599
610
to this
600
-
611
+
601
612
Returns:
602
613
List[Position]: A list of positions that match the query parameters
603
614
"""
@@ -1167,7 +1178,7 @@ def get_closed_trades(self) -> List[Trade]:
1167
1178
"""
1168
1179
Function to get all closed trades. This function will return all
1169
1180
closed trades of the algorithm.
1170
-
1181
+
1171
1182
Returns:
1172
1183
List[Trade]: A list of closed trades
1173
1184
"""
@@ -1234,8 +1245,9 @@ def has_trading_symbol_position_available(
1234
1245
the position must be greater than the net_size of the
1235
1246
portfolio.
1236
1247
1237
- :param amount_gt: The amount of the position must be greater than
1238
- this amount.
1248
+ Parameters:
1249
+ amount_gt: The amount of the position must be greater than this
1250
+ amount.
1239
1251
:param amount_gte: The amount of the position must be greater than
1240
1252
or equal to this amount.
1241
1253
:param percentage_of_portfolio: The amount of the position must be
0 commit comments