抱歉,我可能会问一个愚蠢的问题,但我只是python和algotrading的初学者。我现在使用带有ib_insync的Python 3.7和ibapi尝试连接交易平台。但是,由于Python 3.7使用async作为关键字,因此当我尝试使用ib_insync进行编码时:
from ib_insync import *
ib = IB()
ib.connect('127.0.0.1', 7496, clientId=1)
contract = Forex('EURUSD')
bars = ib.reqHistoricalData(contract, endDateTime='', durationStr='30 D', barSizeSetting='1 hour', whatToShow='MIDPOINT', useRTH=True)
df = util.df(bars)
print(df['date', 'open', 'high', 'low', 'close'])
Run Code Online (Sandbox Code Playgroud)
它最终像这样:
from ib_insync import *
ib = IB()
ib.connect('127.0.0.1', 7496, clientId=1)
contract = Forex('EURUSD')
bars = ib.reqHistoricalData(contract, endDateTime='', durationStr='30 D', barSizeSetting='1 hour', whatToShow='MIDPOINT', useRTH=True)
df = util.df(bars)
print(df['date', 'open', 'high', 'low', 'close'])
Run Code Online (Sandbox Code Playgroud)
我知道我需要将异步名称更改为其他名称。我试图在ibapi中修改文件client.py,但似乎根本不起作用。为了使它起作用,我应该更改代码的哪一部分?
python algorithmic-trading python-3.x interactive-brokers ib-api
我如何使用 javascript 复制C:\folderA\myfile.txt到C:\folderB\myfile.txt?我也有检查,以确保myfile.txt不已经存在folderB。最后我不得不然后重命名新文件myfile.txt到myfile.bak。
我知道 javascript 不能真正用于本地文件系统,但如果可以,我将如何尽可能简单地编写此代码?
我试图了解python中的绑定方法,并实现了以下代码:
class Point:
def __init__(self, x,y):
self.__x=x
self.__y=y
def draw(self):
print(self.__x, self.__y)
def draw2(self):
print("x",self.__x, "y", self.__y)
p1=Point(1,2)
p2=Point(3,4)
p1.draw()
p2.draw()
p1.draw=draw2
p1.draw(p1)
Run Code Online (Sandbox Code Playgroud)
当我运行此代码时,会生成以下输出:
1 2
3 4
Traceback (most recent call last):
File "main.py", line 17, in <module>
p1.draw(p1)
File "main.py", line 10, in draw2
print("x",self.__x, "y", self.__y)
AttributeError: 'Point' object has no attribute '__x'
Run Code Online (Sandbox Code Playgroud)
为什么我不能在更改p1.draw()之后更改它以使其指向draw2?
我创建了一个空的char多维数组,但是当我尝试更改特定值时,它有时会复制到数组中的另一个空格.
例:
#include <iostream>
using namespace std;
char arr[2][2] = { 0 };
int main ()
{
arr[2][0] = 'A';
for(int i = 0; i < 3; ++i)
{
for(int j = 0; j < 3; ++j)
{
cout << "arr[" << i << "][" << j << "] = " << arr[i][j] << endl;
}
}
}
Run Code Online (Sandbox Code Playgroud)
输出:
arr[0][0] =
arr[0][1] =
arr[0][2] =
arr[1][0] =
arr[1][1] =
arr[1][2] = A
arr[2][0] = A
arr[2][1] =
arr[2][2] …Run Code Online (Sandbox Code Playgroud) 我正在尝试运行以下代码:
import matplotlib.pylab as plt
import numpy as np
import torch
import torch.nn as nn
class LSTM(nn.Module):
def __init__(self, input_shape, n_actions):
super(LSTM, self).__init__()
self.lstm = nn.LSTM(input_shape, 12)
self.hidden2tag = nn.Linear(12, n_actions)
def forward(self, x):
out = self.lstm(x)
out = self.hidden2tag(out)
return out
state = [(1,2,3,4,5),(2,3,4,5,6),(3,4,5,6,7),(4,5,6,7,8),(5,6,7,8,9),(6,7,8,9,0)]
device = torch.device("cuda")
net = LSTM(5, 3).to(device)
state_v = torch.FloatTensor(state).to(device)
q_vals_v = net(state_v.view(1, state_v.shape[0], state_v.shape[1]))
_, action = int(torch.max(q_vals_v, dim=1).item())
Run Code Online (Sandbox Code Playgroud)
并返回此错误:
import matplotlib.pylab as plt
import numpy as np
import torch
import torch.nn as nn …Run Code Online (Sandbox Code Playgroud) 为什么我不能将输入值插入另一个输入?以下示例不起作用:
document.getElementById("input").oninput = () => {
const input = document.getElementById('input');
const output = document.getElementById('output');
// Trying to insert text into 'output'.
output.innerText = input.value;
};Run Code Online (Sandbox Code Playgroud)
<input id="input" placeholder="enter value of temperature" />
<br>
<input id="output" />Run Code Online (Sandbox Code Playgroud)
谢谢!
注意:我找到了针对这个问题研究的解决方案。下一个犯这个错误的人希望在花太多时间在这个问题上之前发现这个问题。
我一直在尝试在Linux系统上实现TCP服务器。问题是我收到一条非常通用的错误消息,但没有揭示问题的原因:
$ gcc -Wall -Wextra main.c
$ ./a.out
bind: Cannot assign requested address
Run Code Online (Sandbox Code Playgroud)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
int main() {
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
if(sockfd == -1) {
fprintf(stderr, "socket: %s\n", strerror(errno));
return EXIT_FAILURE;
}
struct sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_port = 8080;
addr.sin_addr.s_addr = INADDR_LOOPBACK;
if(bind(sockfd, (const struct sockaddr*)&addr, sizeof(addr)) != 0) {
fprintf(stderr, "bind: %s\n", strerror(errno));
return EXIT_FAILURE;
}
if(close(sockfd) != 0) {
fprintf(stderr, …Run Code Online (Sandbox Code Playgroud) 请使用以下代码:
import csv
# import items with first row
inputfile = open('price.csv', 'r')
reader = csv.reader(inputfile)
rows1 = [row for row in reader] # here
# del first row
rows2 = rows1[1:]
print(rows2)
Run Code Online (Sandbox Code Playgroud)
更改
rows1 = [row for row in reader]
Run Code Online (Sandbox Code Playgroud)
成
rows1 = [row for row in inputfile]
Run Code Online (Sandbox Code Playgroud)
改变输出:
# with 'reader'
[['6004', '240'], ['6004', '350'], ['6004', '350']]
# with 'inputfile'
['6004,240\n', '6004,350\n', '6004,350\n']
Run Code Online (Sandbox Code Playgroud)
是什么造成的?或者说,原理是什么?
我正在学习Python并且遇到了可变参数.我不明白以下代码产生的输出:
_list = [11,2,3]
def print_list(*args):
for value in args:
a = value * 10
print(a)
print_list(_list)
Run Code Online (Sandbox Code Playgroud)
当我运行程序时,我得到:
[11, 2, 3, 11, 2, 3, 11, 2, 3, 11, 2, 3, 11, 2, 3, 11, 2, 3, 11, 2, 3, 11, 2, 3, 11, 2, 3, 11, 2, 3]
Run Code Online (Sandbox Code Playgroud)
根据我的理解,value从_list数组中保存一个单独的元素,将它乘以10将生成列表[110, 20, 30].为什么输出不同?
执行后如何退出命令行:
python manage.py run server 8080
Run Code Online (Sandbox Code Playgroud)
我已经尝试过Ctrl+C和Ctrl+Z但都没有奏效。使用 gitbash 而不是 cmd 没有任何改变。
我正在使用 Windows(64 位)。
Rob Pike 在 2011 年 (链接) 发表了关于 go 中的词法分析器的演讲,他在那里定义了一个这样的类型:
// stateFn represents the state of the scanner
// as a function that returns the next state.
type stateFn func() stateFn
Run Code Online (Sandbox Code Playgroud)
我想在 C++ 中实现相同的目标,但不知道如何:
// stateFn represents the state of the scanner
// as a function that returns the next state.
type stateFn func() stateFn
Run Code Online (Sandbox Code Playgroud)
注意:这个问题可能有关联(在 Rust 中也是一样)
编辑:
这是我想要实现的目标:
// 01: error C3861: 'statefn_t': identifier not found
typedef std::function<statefn_t()> statefn_t;
// 02: error C2371: 'statefn_t': redefinition; …Run Code Online (Sandbox Code Playgroud) 我有两个json数组和对象我想比较两个json并推送另一个对象
obj1 = ["user1", "user2"]
obj2 = [
{
"userName": "user1",
"id": "14"
},
{
"userName": "user2",
"id": "9",
},
{
"userName": "user3",
"id": "3",
},
{
"userName": "user4",
"id": "1",
}
]
Run Code Online (Sandbox Code Playgroud)
我想得到如下结果
[
{
"userName": "user1",
"id": "14"
},
{
"userName": "user2",
"id": "9",
}
]
Run Code Online (Sandbox Code Playgroud)
之后,我尝试比较两个数组并获得我需要的结果.
var obj1 = ["user1","user2"]
var obj2 = [
{
"userName": "user1",
"id": "14"
},
{
"userName": "user2",
"id": "9",
},
{
"userName": "user3",
"id": "3",
},
{
"userName": "user4",
"id": "1", …Run Code Online (Sandbox Code Playgroud)