xlwings很难在Windows中运行,因为没有名为“ win32api”的模块

时间:2018-07-06 21:58:28

标签: python pycharm xlwings

我的代码在Mac系统中运行良好。但是我在Windows操作系统中运行xlwings遇到麻烦。它给了我关于“没有名为“ win32api”的模块的错误。我已经在Pycharm中安装了'comtype'和'pywin32'软件包。我不知道为什么我仍然收到此错误。我在Pycharm中的代码如下:

导入pprint 将xlwings导入为xw 将熊猫作为pd导入 将numpy导入为np 从deribit_api导入RestClient

def getdata():

access_key = "6wvUvxmVSoJq"
access_secret = "HQQ7ZTU2ZESOR2UELLVSHCRWSHPP2VYE"
url = "https://test.deribit.com"
client = RestClient(access_key, access_secret, url)
client.index()
positions = client.positions()
account = client.account()

dfp = pd.DataFrame(columns=['Kind', 'Expiry Date', 'Direction', 'Underlying', 'Delta', 'Size in contracts', 'P&L in BTC', 'Average_Price'], index=range(len(positions)))
for i in range(len(positions)):
    dfp.loc[i]['Kind'] = positions[i]['kind']
    dfp.loc[i]['Expiry Date'] = positions[i]['instrument']
    dfp.loc[i]['Direction'] = positions[i]['direction']
    dfp.loc[i]['Underlying'] = positions[i]['indexPrice']
    dfp.loc[i]['Delta'] = positions[i]['delta']
    dfp.loc[i]['Size in contracts'] = positions[i]['size']
    dfp.loc[i]['P&L in BTC'] = positions[i]['profitLoss']
    dfp.loc[i]['Average_Price'] = positions[i]['averagePrice']

wb = xw.Book.caller()

wb.sheets[0].range('A2').value = dfp

wb.sheets[0].range('A15').value = 'Total Delta'
wb.sheets[0].range('B15').value = 'Options Delta'
wb.sheets[0].range('C15').value = 'Options Gamma'
wb.sheets[0].range('D15').value = 'Options Theta'
wb.sheets[0].range('E15').value = 'Options Vega'
wb.sheets[0].range('F15').value = 'Account Balance in BTC'
wb.sheets[0].range('G15').value = 'P&L in BTC'

wb.sheets[0].range('A16').value = account['deltaTotal']
wb.sheets[0].range('B16').value = account['optionsD']
wb.sheets[0].range('C16').value = account['optionsG']
wb.sheets[0].range('D16').value = account['optionsTh']
wb.sheets[0].range('E16').value = account['optionsV']
wb.sheets[0].range('F16').value = account['balance']
wb.sheets[0].range('G16').value = account['PNL']

def execute_order():

access_key = "6wvUvxmVSoJq"
access_secret = "HQQ7ZTU2ZESOR2UELLVSHCRWSHPP2VYE"
url = "https://test.deribit.com"
client = RestClient(access_key, access_secret, url)
wb = xw.Book.caller()
order1 = client.buy(wb.sheets[0].range('N9').value, wb.sheets[0].range('M9').value, wb.sheets[0].range('O9').value)
wb.sheets[0].range('T9').value = order1['order']['orderId']
order2 = client.sell(wb.sheets[0].range('N10').value, wb.sheets[0].range('M10').value, wb.sheets[0].range('O10').value)
wb.sheets[0].range('T10').value = order2['order']['orderId']

def Orderstate():

access_key = "6wvUvxmVSoJq"
access_secret = "HQQ7ZTU2ZESOR2UELLVSHCRWSHPP2VYE"
url = "https://test.deribit.com"
client = RestClient(access_key, access_secret, url)
wb = xw.Book.caller()
openorder1 = client.getopenorders(orderId=wb.sheets[0].range('T9').value)
if openorder1 == []:
    wb.sheets[0].range('S9').value = "filled"
else:
    wb.sheets[0].range('S9').value = "open"
openorder2 = client.getopenorders(orderId=wb.sheets[0].range('T10').value)
if openorder2 == []:
    wb.sheets[0].range('S10').value = "filled"
else:
    wb.sheets[0].range('S10').value = "open"

def Cancel():

access_key = "6wvUvxmVSoJq"
access_secret = "HQQ7ZTU2ZESOR2UELLVSHCRWSHPP2VYE"
url = "https://test.deribit.com"
client = RestClient(access_key, access_secret, url)
wb = xw.Book.caller()
if wb.sheets[0].range('S9').value == "filled":
    wb.sheets[0].range('U9').value = "No"
else:
    client.cancel(orderId=wb.sheets[0].range('T9').value)
    wb.sheets[0].range('U9').value = "Yes"

if wb.sheets[0].range('S10').value == "filled":
    wb.sheets[0].range('U10').value = "No"
else:
    client.cancel(orderId=wb.sheets[0].range('T10').value)
    wb.sheets[0].range('U10').value = "Yes"

0 个答案:

没有答案