简体   繁体   中英

unable to iterate through loop in python

i have a sql query which basically retrieves coin names and submits an order for each coin. However, it only submits an order on one coin and fails to loop through the rest, not sure why thats happening.

import sys

**
import pandas as pd


postgreSQL_select_Query = "SELECT base,quote FROM instrument_static where exchange='ftx'"

cursor.execute(postgreSQL_select_Query)
row=([y for y in cursor.fetchall()])

for i in row:
   base=i[0]
   quote=i[1]
   portfolioItems = [
       {
           'exchange': 'ftx',
           'base': base,
           'quote': quote,
           'amount': 0.01,
       },

   ]


   def init():

       username = us
       password = passwordVal
       initialise(clientId, clientSecret, us, password)


if __name__ == "__main__":
       init()
       result = construct_portfolio_with_params(us, portname, portfolioItems)
       print(result)

You need to initialize portfolioItems prior to the loop, and then you can add to it. Try replacing this snippet of code:

...
row=([y for y in cursor.fetchall()])

portfolioItems = []

for i in row:
   base=i[0]
   quote=i[1]
   portfolioItems.append(
       {
           'exchange': 'ftx',
           'base': base,
           'quote': quote,
           'amount': 0.01,
       }

   )
...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM