1- import json
2-
31from viaduct .core import *
42from viaduct .utils import *
53
64
75class ISA (CoreModule ):
8- def __init__ (self , username , password , reality , browserPath , headless = False , timeout = 2 ):
9- super ().__init__ (username , password , TradingType .ISA ,
10- reality , headless , browserPath , timeout )
6+ def __init__ (self , email , password , browserPath , headless = False , timeout = 2 ):
7+ super ().__init__ (email , password , TradingType .ISA ,
8+ Reality .Real , headless , browserPath , timeout )
9+ self .reality = Reality .Real
10+
11+ # Format url on whether is live
12+ def urlf (self , url ):
13+ if (self .reality == Reality .Real ):
14+ return ("https://live.trading212.com" + url )
15+ elif (self .reality == Reality .Practice ):
16+ return ("https://demo.trading212.com" + url )
17+ else :
18+ raise Exception ("Invalid reality " + self .reality )
1119
1220 # Gets min and max buy and sell value in £, max sell quantity is number of shares
1321 # Not sure what sellThreshold is
1422 # The sell parameters only appear for UK stocks for some reason
1523 def getMinMax (self , code ):
16- return self .get ("https://live.trading212.com/ rest/v1/equity/value-order/min-max?instrumentCode=" + code , cookies = self .cookiePayload )
24+ return super () .get (self . urlf ( "/ rest/v1/equity/value-order/min-max?instrumentCode=" + code ) , cookies = self .cookiePayload )
1725
1826 # Takes instrument code, returns maxBuy and maxSell in shares for the account and max buy and sell that is technically
1927 # possible on the exchange, also has minTrade and if suspended
2028 def getSettings (self , code ):
21- return self .post ("https://live.trading212.com/ rest/v2/account/instruments/settings" , cookies = self .cookiePayload , payload = [code ])
29+ return super () .post (self . urlf ( "/ rest/v2/account/instruments/settings") , cookies = self .cookiePayload , payload = [code ])
2230
23- # Gets chart data fior a given ticker code
24- def getChartData (self , ticker , chartPeriod , size , includeFake = False ):
25- payload = {
26- "candles" : [
27- {
28- "ticker" : ticker ,
29- "period" : chartPeriod ,
30- "size" : size ,
31- "includeFake" : includeFake
32- }
33- ]
34- }
35- return post ("https://live.trading212.com/charting/v2/batch" , cookies = self .cookiePayload , payload = payload )
36-
3731 # Gets the account performance graph data
3832 def getPortfolioPerformance (self , historyPeriod ):
39- return get ("https://live.trading212.com/ rest/v2/portfolio?period=" + historyPeriod , cookies = self .cookiePayload )
33+ return super (). get (self . urlf ( "/ rest/v2/portfolio?period=" + historyPeriod ) , cookies = self .cookiePayload )
0 commit comments