Python: E1136:Value 'self.exchange.get_portfolio' is unsubscriptable









up vote
0
down vote

favorite












def get_portfolio(self):
contracts = settings.CONTRACTS
portfolio =
for symbol in contracts:
position = self.bitmex.position(symbol=symbol)
instrument = self.bitmex.instrument(symbol=symbol)

if instrument['isQuanto']:
future_type = "Quanto"
elif instrument['isInverse']:
future_type = "Inverse"
elif not instrument['isQuanto'] and not instrument['isInverse']:
future_type = "Linear"
else:
raise NotImplementedError("Unknown future type; not quanto or inverse: %s" % instrument['symbol'])

if instrument['underlyingToSettleMultiplier'] is None:
multiplier = float(instrument['multiplier']) / float(instrument['quoteToSettleMultiplier'])
else:
multiplier = float(instrument['multiplier']) / float(instrument['underlyingToSettleMultiplier'])

portfolio[symbol] =
"currentQty": float(position['currentQty']),
"futureType": future_type,
"multiplier": multiplier,
"markPrice": float(instrument['markPrice']),
"spot": float(instrument['indicativeSettlePrice'])


return portfolio



qty = self.exchange.get_portfolio['currentQty']()


Does anybody know what I am doing wrong when I am calling the get_portfolio function because I keep getting this error message:



E1136:Value 'self.exchange.get_portfolio' is unsubscriptable









share|improve this question



























    up vote
    0
    down vote

    favorite












    def get_portfolio(self):
    contracts = settings.CONTRACTS
    portfolio =
    for symbol in contracts:
    position = self.bitmex.position(symbol=symbol)
    instrument = self.bitmex.instrument(symbol=symbol)

    if instrument['isQuanto']:
    future_type = "Quanto"
    elif instrument['isInverse']:
    future_type = "Inverse"
    elif not instrument['isQuanto'] and not instrument['isInverse']:
    future_type = "Linear"
    else:
    raise NotImplementedError("Unknown future type; not quanto or inverse: %s" % instrument['symbol'])

    if instrument['underlyingToSettleMultiplier'] is None:
    multiplier = float(instrument['multiplier']) / float(instrument['quoteToSettleMultiplier'])
    else:
    multiplier = float(instrument['multiplier']) / float(instrument['underlyingToSettleMultiplier'])

    portfolio[symbol] =
    "currentQty": float(position['currentQty']),
    "futureType": future_type,
    "multiplier": multiplier,
    "markPrice": float(instrument['markPrice']),
    "spot": float(instrument['indicativeSettlePrice'])


    return portfolio



    qty = self.exchange.get_portfolio['currentQty']()


    Does anybody know what I am doing wrong when I am calling the get_portfolio function because I keep getting this error message:



    E1136:Value 'self.exchange.get_portfolio' is unsubscriptable









    share|improve this question

























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      def get_portfolio(self):
      contracts = settings.CONTRACTS
      portfolio =
      for symbol in contracts:
      position = self.bitmex.position(symbol=symbol)
      instrument = self.bitmex.instrument(symbol=symbol)

      if instrument['isQuanto']:
      future_type = "Quanto"
      elif instrument['isInverse']:
      future_type = "Inverse"
      elif not instrument['isQuanto'] and not instrument['isInverse']:
      future_type = "Linear"
      else:
      raise NotImplementedError("Unknown future type; not quanto or inverse: %s" % instrument['symbol'])

      if instrument['underlyingToSettleMultiplier'] is None:
      multiplier = float(instrument['multiplier']) / float(instrument['quoteToSettleMultiplier'])
      else:
      multiplier = float(instrument['multiplier']) / float(instrument['underlyingToSettleMultiplier'])

      portfolio[symbol] =
      "currentQty": float(position['currentQty']),
      "futureType": future_type,
      "multiplier": multiplier,
      "markPrice": float(instrument['markPrice']),
      "spot": float(instrument['indicativeSettlePrice'])


      return portfolio



      qty = self.exchange.get_portfolio['currentQty']()


      Does anybody know what I am doing wrong when I am calling the get_portfolio function because I keep getting this error message:



      E1136:Value 'self.exchange.get_portfolio' is unsubscriptable









      share|improve this question















      def get_portfolio(self):
      contracts = settings.CONTRACTS
      portfolio =
      for symbol in contracts:
      position = self.bitmex.position(symbol=symbol)
      instrument = self.bitmex.instrument(symbol=symbol)

      if instrument['isQuanto']:
      future_type = "Quanto"
      elif instrument['isInverse']:
      future_type = "Inverse"
      elif not instrument['isQuanto'] and not instrument['isInverse']:
      future_type = "Linear"
      else:
      raise NotImplementedError("Unknown future type; not quanto or inverse: %s" % instrument['symbol'])

      if instrument['underlyingToSettleMultiplier'] is None:
      multiplier = float(instrument['multiplier']) / float(instrument['quoteToSettleMultiplier'])
      else:
      multiplier = float(instrument['multiplier']) / float(instrument['underlyingToSettleMultiplier'])

      portfolio[symbol] =
      "currentQty": float(position['currentQty']),
      "futureType": future_type,
      "multiplier": multiplier,
      "markPrice": float(instrument['markPrice']),
      "spot": float(instrument['indicativeSettlePrice'])


      return portfolio



      qty = self.exchange.get_portfolio['currentQty']()


      Does anybody know what I am doing wrong when I am calling the get_portfolio function because I keep getting this error message:



      E1136:Value 'self.exchange.get_portfolio' is unsubscriptable






      python algorithm bitmex






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 16:48









      shriek

      2,01342651




      2,01342651










      asked Nov 10 at 16:07









      Varun Reddy

      1




      1






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote













          You have a little mistake in the call:



          self.exchange.get_portfolio is a function, so you first have to call it and then you can reference the entries from the returned dict.



          Oh I just saw, that you also have to insert your symbol before:



          qty = self.exchange.get_portfolio()[<YOUR_SYMBOL>]['currentQty']


          If you don't know the symbols, you can use the keys function which lists all the keys of your dict:



          port = self.exchange.get_portfolio()
          port_keys = port.keys()
          qty = port[port_keys[<SOME KEY NUMBER>]]['currentQty']





          share|improve this answer






















          • thank you!!, your help was much appreciated
            – Varun Reddy
            Nov 10 at 16:16










          • Don't forget to accept the answer, so others know it's solved ;)
            – user8408080
            Nov 10 at 16:18










          • @VarunReddy you tested it and worked?
            – Geeocode
            Nov 10 at 16:19










          • @VarunReddy user8408080 He may not know the symbol's value, see my working answer below
            – Geeocode
            Nov 10 at 16:30











          • You think I should also point out, that there is a keys function?
            – user8408080
            Nov 10 at 16:32

















          up vote
          0
          down vote













          You should do it as follows:



          qty = self.exchange.get_portfolio()
          qty = qty[qty.keys()[0]]['currentQty']


          or in a single row:



          qty = self.exchange.get_portfolio()[self.exchange.get_portfolio().keys()[0]]['currentQty']





          share|improve this answer




















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240803%2fpython-e1136value-self-exchange-get-portfolio-is-unsubscriptable%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote













            You have a little mistake in the call:



            self.exchange.get_portfolio is a function, so you first have to call it and then you can reference the entries from the returned dict.



            Oh I just saw, that you also have to insert your symbol before:



            qty = self.exchange.get_portfolio()[<YOUR_SYMBOL>]['currentQty']


            If you don't know the symbols, you can use the keys function which lists all the keys of your dict:



            port = self.exchange.get_portfolio()
            port_keys = port.keys()
            qty = port[port_keys[<SOME KEY NUMBER>]]['currentQty']





            share|improve this answer






















            • thank you!!, your help was much appreciated
              – Varun Reddy
              Nov 10 at 16:16










            • Don't forget to accept the answer, so others know it's solved ;)
              – user8408080
              Nov 10 at 16:18










            • @VarunReddy you tested it and worked?
              – Geeocode
              Nov 10 at 16:19










            • @VarunReddy user8408080 He may not know the symbol's value, see my working answer below
              – Geeocode
              Nov 10 at 16:30











            • You think I should also point out, that there is a keys function?
              – user8408080
              Nov 10 at 16:32














            up vote
            1
            down vote













            You have a little mistake in the call:



            self.exchange.get_portfolio is a function, so you first have to call it and then you can reference the entries from the returned dict.



            Oh I just saw, that you also have to insert your symbol before:



            qty = self.exchange.get_portfolio()[<YOUR_SYMBOL>]['currentQty']


            If you don't know the symbols, you can use the keys function which lists all the keys of your dict:



            port = self.exchange.get_portfolio()
            port_keys = port.keys()
            qty = port[port_keys[<SOME KEY NUMBER>]]['currentQty']





            share|improve this answer






















            • thank you!!, your help was much appreciated
              – Varun Reddy
              Nov 10 at 16:16










            • Don't forget to accept the answer, so others know it's solved ;)
              – user8408080
              Nov 10 at 16:18










            • @VarunReddy you tested it and worked?
              – Geeocode
              Nov 10 at 16:19










            • @VarunReddy user8408080 He may not know the symbol's value, see my working answer below
              – Geeocode
              Nov 10 at 16:30











            • You think I should also point out, that there is a keys function?
              – user8408080
              Nov 10 at 16:32












            up vote
            1
            down vote










            up vote
            1
            down vote









            You have a little mistake in the call:



            self.exchange.get_portfolio is a function, so you first have to call it and then you can reference the entries from the returned dict.



            Oh I just saw, that you also have to insert your symbol before:



            qty = self.exchange.get_portfolio()[<YOUR_SYMBOL>]['currentQty']


            If you don't know the symbols, you can use the keys function which lists all the keys of your dict:



            port = self.exchange.get_portfolio()
            port_keys = port.keys()
            qty = port[port_keys[<SOME KEY NUMBER>]]['currentQty']





            share|improve this answer














            You have a little mistake in the call:



            self.exchange.get_portfolio is a function, so you first have to call it and then you can reference the entries from the returned dict.



            Oh I just saw, that you also have to insert your symbol before:



            qty = self.exchange.get_portfolio()[<YOUR_SYMBOL>]['currentQty']


            If you don't know the symbols, you can use the keys function which lists all the keys of your dict:



            port = self.exchange.get_portfolio()
            port_keys = port.keys()
            qty = port[port_keys[<SOME KEY NUMBER>]]['currentQty']






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 10 at 16:36

























            answered Nov 10 at 16:11









            user8408080

            75228




            75228











            • thank you!!, your help was much appreciated
              – Varun Reddy
              Nov 10 at 16:16










            • Don't forget to accept the answer, so others know it's solved ;)
              – user8408080
              Nov 10 at 16:18










            • @VarunReddy you tested it and worked?
              – Geeocode
              Nov 10 at 16:19










            • @VarunReddy user8408080 He may not know the symbol's value, see my working answer below
              – Geeocode
              Nov 10 at 16:30











            • You think I should also point out, that there is a keys function?
              – user8408080
              Nov 10 at 16:32
















            • thank you!!, your help was much appreciated
              – Varun Reddy
              Nov 10 at 16:16










            • Don't forget to accept the answer, so others know it's solved ;)
              – user8408080
              Nov 10 at 16:18










            • @VarunReddy you tested it and worked?
              – Geeocode
              Nov 10 at 16:19










            • @VarunReddy user8408080 He may not know the symbol's value, see my working answer below
              – Geeocode
              Nov 10 at 16:30











            • You think I should also point out, that there is a keys function?
              – user8408080
              Nov 10 at 16:32















            thank you!!, your help was much appreciated
            – Varun Reddy
            Nov 10 at 16:16




            thank you!!, your help was much appreciated
            – Varun Reddy
            Nov 10 at 16:16












            Don't forget to accept the answer, so others know it's solved ;)
            – user8408080
            Nov 10 at 16:18




            Don't forget to accept the answer, so others know it's solved ;)
            – user8408080
            Nov 10 at 16:18












            @VarunReddy you tested it and worked?
            – Geeocode
            Nov 10 at 16:19




            @VarunReddy you tested it and worked?
            – Geeocode
            Nov 10 at 16:19












            @VarunReddy user8408080 He may not know the symbol's value, see my working answer below
            – Geeocode
            Nov 10 at 16:30





            @VarunReddy user8408080 He may not know the symbol's value, see my working answer below
            – Geeocode
            Nov 10 at 16:30













            You think I should also point out, that there is a keys function?
            – user8408080
            Nov 10 at 16:32




            You think I should also point out, that there is a keys function?
            – user8408080
            Nov 10 at 16:32












            up vote
            0
            down vote













            You should do it as follows:



            qty = self.exchange.get_portfolio()
            qty = qty[qty.keys()[0]]['currentQty']


            or in a single row:



            qty = self.exchange.get_portfolio()[self.exchange.get_portfolio().keys()[0]]['currentQty']





            share|improve this answer
























              up vote
              0
              down vote













              You should do it as follows:



              qty = self.exchange.get_portfolio()
              qty = qty[qty.keys()[0]]['currentQty']


              or in a single row:



              qty = self.exchange.get_portfolio()[self.exchange.get_portfolio().keys()[0]]['currentQty']





              share|improve this answer






















                up vote
                0
                down vote










                up vote
                0
                down vote









                You should do it as follows:



                qty = self.exchange.get_portfolio()
                qty = qty[qty.keys()[0]]['currentQty']


                or in a single row:



                qty = self.exchange.get_portfolio()[self.exchange.get_portfolio().keys()[0]]['currentQty']





                share|improve this answer












                You should do it as follows:



                qty = self.exchange.get_portfolio()
                qty = qty[qty.keys()[0]]['currentQty']


                or in a single row:



                qty = self.exchange.get_portfolio()[self.exchange.get_portfolio().keys()[0]]['currentQty']






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 10 at 16:25









                Geeocode

                1,7701718




                1,7701718



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240803%2fpython-e1136value-self-exchange-get-portfolio-is-unsubscriptable%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    Barbados

                    How to read a connectionString WITH PROVIDER in .NET Core?

                    Node.js Script on GitHub Pages or Amazon S3