investfly-sdk 1.2__py3-none-any.whl → 1.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,7 +15,7 @@ class StrategyApiClient:
15
15
 
16
16
  def listStrategies(self) -> List[TradingStrategyModel]:
17
17
  strategiesList: List[Dict[str, Any]] = self.restApiClient.doGet('/strategy/list')
18
- strategiesList = list(filter(lambda jsonDict: jsonDict['type'] == 'CUSTOM', strategiesList))
18
+ strategiesList = list(filter(lambda jsonDict: jsonDict['type'] == 'SCRIPT', strategiesList))
19
19
  return list(map(lambda jsonDict: TradingStrategyModel.fromDict(jsonDict), strategiesList))
20
20
 
21
21
  def getStrategy(self, strategyId: int) -> TradingStrategyModel:
@@ -24,7 +24,7 @@ class StrategyApiClient:
24
24
 
25
25
  def createStrategy(self, strategyModel: TradingStrategyModel) -> TradingStrategyModel:
26
26
  strategyDict = strategyModel.toDict()
27
- strategyDict['type'] = 'CUSTOM'
27
+ strategyDict['type'] = 'SCRIPT'
28
28
  strategyDict = self.restApiClient.doPost('/strategy/create', strategyDict)
29
29
  return TradingStrategyModel.fromDict(strategyDict)
30
30
 
@@ -2,7 +2,7 @@ import argparse
2
2
  import pickle
3
3
  import os.path
4
4
  import time
5
- from typing import List
5
+ from typing import List, cast
6
6
 
7
7
  from investfly.api.InvestflyApiClient import InvestflyApiClient
8
8
  from investfly.models import Session, IndicatorSpec
@@ -63,8 +63,9 @@ class InvestflyCli:
63
63
  strategyId = int(args.id)
64
64
  path = args.file
65
65
  strategyModel: TradingStrategyModel = self.investflyApi.strategyApi.getStrategy(strategyId)
66
+ code: str = cast(str, strategyModel.pythonCode)
66
67
  with open(path, 'w') as out_file:
67
- out_file.write(strategyModel.pythonCode)
68
+ out_file.write(code)
68
69
  return f"Strategy saved to {path}"
69
70
 
70
71
  def __updateCode(self, args: argparse.Namespace) -> str:
@@ -94,8 +95,8 @@ class InvestflyCli:
94
95
  try:
95
96
  while notFinished:
96
97
  time.sleep(3)
97
- backtestResult: BacktestResult = self.investflyApi.strategyApi.getBacktestResult(strategyId)
98
- backtestStatus: BacktestResultStatus = backtestResult.status
98
+ backtestResult = self.investflyApi.strategyApi.getBacktestResult(strategyId)
99
+ backtestStatus = backtestResult.status
99
100
  print(str(backtestStatus.toDict()))
100
101
  notFinished = backtestStatus.jobStatus == BacktestStatus.QUEUED or backtestStatus.jobStatus == BacktestStatus.INITIALIZING or backtestStatus.jobStatus == BacktestStatus.RUNNING
101
102
  except KeyboardInterrupt as e:
@@ -122,7 +122,7 @@ class IndicatorSpec:
122
122
  name = json_dict['name']
123
123
  indicatorSpec: IndicatorSpec = IndicatorSpec(name)
124
124
  indicatorSpec.indicatorId = json_dict['indicatorId']
125
- indicatorSpec.description = json_dict.get('description')
125
+ indicatorSpec.description = json_dict['description']
126
126
  indicatorSpec.valueType = IndicatorValueType[json_dict['valueType']]
127
127
  for key, value in json_dict['params'].items():
128
128
  indicatorSpec.params[key] = IndicatorParamSpec.fromDict(value)
@@ -78,7 +78,7 @@ class TradingStrategy(ABC):
78
78
  :param tradeSignals: Trade Signals correspoding to stocks matching open trade condition
79
79
  :return: List of TradeOrders to execute
80
80
  """
81
- portfolioAllocator = PercentBasedPortfolioAllocator(10, PositionType.LONG)
81
+ portfolioAllocator = PercentBasedPortfolioAllocator(10)
82
82
  return portfolioAllocator.allocatePortfolio(portfolio, tradeSignals)
83
83
 
84
84
  def getStandardCloseCondition(self) -> StandardCloseCriteria | None:
@@ -30,6 +30,6 @@ class SmaCrossOverStrategy(TradingStrategy):
30
30
 
31
31
 
32
32
  def processOpenTradeSignals(self, portfolio: Portfolio, tradeSignals: List[TradeSignal]) -> List[TradeOrder]:
33
- portfolioAllocator = PercentBasedPortfolioAllocator(5, PositionType.LONG)
33
+ portfolioAllocator = PercentBasedPortfolioAllocator(5)
34
34
  return portfolioAllocator.allocatePortfolio(portfolio, tradeSignals)
35
35
 
@@ -95,7 +95,7 @@ class SmaCrossOverTemplate(TradingStrategy):
95
95
  """
96
96
 
97
97
  # We provide a convenience utility that allocates given percent (10% set below) of portfolio in the given stock
98
- portfolioAllocator = PercentBasedPortfolioAllocator(10, PositionType.LONG)
98
+ portfolioAllocator = PercentBasedPortfolioAllocator(10)
99
99
  return portfolioAllocator.allocatePortfolio(portfolio, tradeSignals)
100
100
 
101
101
  def getStandardCloseCondition(self) -> StandardCloseCriteria | None:
@@ -6,17 +6,15 @@ from investfly.models.StrategyModels import PortfolioSecurityAllocator, TradeSig
6
6
 
7
7
  class PercentBasedPortfolioAllocator(PortfolioSecurityAllocator):
8
8
 
9
- BROKER_FEE = 5.0
9
+ BROKER_FEE = 1.0
10
10
 
11
- def __init__(self, percent: float, positionType: PositionType) -> None:
11
+ def __init__(self, percent: float) -> None:
12
12
  self.percent = percent
13
- self.positionType = positionType
14
13
 
15
14
  def allocatePortfolio(self, portfolio: Portfolio, tradeSignals: List[TradeSignal]) -> List[TradeOrder]:
16
15
 
17
- tradeType = TradeType.BUY if self.positionType == PositionType.LONG else TradeType.SHORT
18
- openPositionSecurities = {p.security for p in portfolio.openPositions if p.position == self.positionType}
19
- pendingOrdersSecurities = {o.security for o in portfolio.pendingOrders if o.tradeType == tradeType}
16
+ openPositionSecurities = {p.security for p in portfolio.openPositions}
17
+ pendingOrdersSecurities = {o.security for o in portfolio.pendingOrders}
20
18
  openAndPendingSecurities = openPositionSecurities.union(pendingOrdersSecurities)
21
19
 
22
20
  tradeOrders: List[TradeOrder] = []
@@ -28,6 +26,7 @@ class PercentBasedPortfolioAllocator(PortfolioSecurityAllocator):
28
26
  while buyingPower > allocatedAmountPerSecurity and len(tradeSignals) > 0:
29
27
  tradeSignal = tradeSignals.pop(0)
30
28
  if tradeSignal.security not in openAndPendingSecurities:
29
+ tradeType = TradeType.BUY if tradeSignal.position == PositionType.LONG else TradeType.SHORT
31
30
  tradeOrder = TradeOrder(tradeSignal.security, tradeType, maxAmount=allocatedAmountPerSecurity)
32
31
  tradeOrders.append(tradeOrder)
33
32
  buyingPower = buyingPower - allocatedAmountPerSecurity - PercentBasedPortfolioAllocator.BROKER_FEE
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: investfly-sdk
3
- Version: 1.2
3
+ Version: 1.4
4
4
  Summary: Investfly SDK
5
5
  Author-email: "Investfly.com" <admin@investfly.com>
6
6
  License: The MIT License (MIT)
@@ -4,12 +4,12 @@ investfly/api/InvestflyApiClient.py,sha256=I_hi1Uw8EGa3jr06cNkrGbhjIT90BPr_YN5EF
4
4
  investfly/api/MarketDataApiClient.py,sha256=bOlMzzZzN5A35oo0Iml2xCekV0jOig8Q_L66xi6n0n0,611
5
5
  investfly/api/PortfolioApiClient.py,sha256=llNISIHWSx3wvf83usGhwPhVr-3RYGAndBNpZV9w3W0,1858
6
6
  investfly/api/RestApiClient.py,sha256=XjvJCqAqUMPa7tXkhxGwaOj1xgHkfLcA8Q0027Z6xm8,3236
7
- investfly/api/StrategyApiClient.py,sha256=6HmCv7Q_yynVinWIrLfyhCATnqMaJfsqEdiNizqaWiY,2087
7
+ investfly/api/StrategyApiClient.py,sha256=w5_hQrxtQ7-1C1uu0UKL37ZbcjXmtdBAYXPtEiM-MC4,2087
8
8
  investfly/api/__init__.py,sha256=JeeOmrsPbVk4B26DT3hbvBoxAvkMEhJ-PeKeloNGF08,600
9
- investfly/cli/InvestflyCli.py,sha256=GB_5QxiifXDRwy2MxV8Wq_WykVgcZbpeQ_UfhJFMWhs,10561
9
+ investfly/cli/InvestflyCli.py,sha256=SCRqC4GpaVPB7RDzMAgr7_GpEl0ai4GF1qlBKXsjUws,10565
10
10
  investfly/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
11
  investfly/models/CommonModels.py,sha256=kbyWsez1voii2K2wyflYCW7i9lYQh49nbrts4bTvvG4,2348
12
- investfly/models/Indicator.py,sha256=R98Lkxjw5pnpMgucL-GxgQHoF-mP8qsylC_FtVMQ1wc,10664
12
+ investfly/models/Indicator.py,sha256=9v46Ozs2O8UPUjDzVC1MpoGx2iwnA__ZyrySVXxX8Qo,10660
13
13
  investfly/models/MarketData.py,sha256=NbyOh472uIXyHaTW9eYCBbiTu2szSq47iCz8i3qI1v0,6081
14
14
  investfly/models/MarketDataIds.py,sha256=CTNCb7G8NgLb84LYCqqxwlhO8e6RV-AUGwJH9GDv53A,3248
15
15
  investfly/models/ModelUtils.py,sha256=pnrVIDM26LqK0Wuw7gTs0c97lCLIV_fm0EUtlEfT7j4,964
@@ -17,7 +17,7 @@ investfly/models/PortfolioModels.py,sha256=wEHzaxEMEmliNR1OXS0WNzzao7ZA5qhKIPzAj
17
17
  investfly/models/SecurityFilterModels.py,sha256=4baTBBI-XOKh8uTpvqVvk3unD-xHoyooO3dd5lKWbXA,5806
18
18
  investfly/models/SecurityUniverseSelector.py,sha256=N2cYhgRz3PTh6T98liiiTbJNg27SBpaUaIQGgDHFbF4,8645
19
19
  investfly/models/StrategyModels.py,sha256=n9MVOJFPtc_Wkiq5TyhdQnaiTUeXGMYqLmBE9IEiW10,5553
20
- investfly/models/TradingStrategy.py,sha256=uUgQpZRgioVADIKerdC5VD0LEy9LvDqEEGvtRTgWASM,6381
20
+ investfly/models/TradingStrategy.py,sha256=N1V0dZX6T2buVyg5NZL8inAKlLZSHZnrv-x2g9kxQBk,6362
21
21
  investfly/models/__init__.py,sha256=6uMfJwcYaH1r-T-bbh6gMud0VpnoSQTkPNDVMDE3JXo,1383
22
22
  investfly/samples/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
23
  investfly/samples/indicators/IndicatorTemplate.py,sha256=X0AlStLnL1SBSnTwrtW_sthm00tmuN5V7N-GrtiarmM,4454
@@ -25,15 +25,15 @@ investfly/samples/indicators/NewsSentiment.py,sha256=fcpAqOcNWmqYsP-xwJquCX_6G7N
25
25
  investfly/samples/indicators/RsiOfSma.py,sha256=kiLvMhrsbc_lV0EEpERGW2im19u5XmyJk88aTDGSBis,1719
26
26
  investfly/samples/indicators/SmaEmaAverage.py,sha256=9pp3TtEKJADD_bfufwrWlwMswlTLoN7Nj6BC_jJ1sRs,1749
27
27
  investfly/samples/indicators/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
28
- investfly/samples/strategies/SmaCrossOverStrategy.py,sha256=szjmnqQN8O7CRIS1vc-fRONKg4Dy1d59dZhiSEpEJAI,1699
29
- investfly/samples/strategies/SmaCrossOverTemplate.py,sha256=HSyVh89_d-k1aAzqs_WFt8EDxs809OjWq6V3VJVUNQw,8200
28
+ investfly/samples/strategies/SmaCrossOverStrategy.py,sha256=e_gR8gwHJ5m6lU_Ib8jeQrER3cD6q569IIhwglKePew,1680
29
+ investfly/samples/strategies/SmaCrossOverTemplate.py,sha256=rLYVT8dYDx7TKx5PFI8nN4JzTHtx4pPlnZ9JvxWnBfo,8181
30
30
  investfly/samples/strategies/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
31
31
  investfly/utils/CommonUtils.py,sha256=lCXAdI8-6PgbutcXJqUmSfuuLXp82FcnlxNVjCJpqLU,2631
32
- investfly/utils/PercentBasedPortfolioAllocator.py,sha256=oKaSjq5L_3NfRo2iayepCZtZnCevsx4XpsxFfZMTnV8,1684
32
+ investfly/utils/PercentBasedPortfolioAllocator.py,sha256=EHrOyHbaYHLwE-4vUSQCVXwbEgLs-nDjLVRH3cdgslI,1563
33
33
  investfly/utils/__init__.py,sha256=2BqXoOQElv-GIU6wvmf2aaAABAcNny2TETcj7kf9rzM,129
34
- investfly_sdk-1.2.dist-info/LICENSE.txt,sha256=Jmd2U7G7Z1oNdnRERRzFXN6C--bEo_K56j4v9EpJSTg,1090
35
- investfly_sdk-1.2.dist-info/METADATA,sha256=5SO14Syv4-fKY4ggso8X7RwuJd_vM4zu5Ji5ANtAdH4,7507
36
- investfly_sdk-1.2.dist-info/WHEEL,sha256=y4mX-SOX4fYIkonsAGA5N0Oy-8_gI4FXw5HNI1xqvWg,91
37
- investfly_sdk-1.2.dist-info/entry_points.txt,sha256=GDRF4baJQXTh90DvdJJx1DeRezWfPt26E567lTs3g6U,66
38
- investfly_sdk-1.2.dist-info/top_level.txt,sha256=dlEJ2OGWA3prqMvXELeydS5RTdpSzh7hz1LwR3NMc7A,10
39
- investfly_sdk-1.2.dist-info/RECORD,,
34
+ investfly_sdk-1.4.dist-info/LICENSE.txt,sha256=Jmd2U7G7Z1oNdnRERRzFXN6C--bEo_K56j4v9EpJSTg,1090
35
+ investfly_sdk-1.4.dist-info/METADATA,sha256=V4g8ckW2EKMQw6XXoyT-MONak8Mrn-KJF113rYrl74E,7507
36
+ investfly_sdk-1.4.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
37
+ investfly_sdk-1.4.dist-info/entry_points.txt,sha256=GDRF4baJQXTh90DvdJJx1DeRezWfPt26E567lTs3g6U,66
38
+ investfly_sdk-1.4.dist-info/top_level.txt,sha256=dlEJ2OGWA3prqMvXELeydS5RTdpSzh7hz1LwR3NMc7A,10
39
+ investfly_sdk-1.4.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (70.2.0)
2
+ Generator: setuptools (75.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5