我写了一个简单的C#函数,通过以下API调用从MtGox检索交易历史:
https://data.mtgox.com/api/1/BTCUSD/trades?since=<trade_id>
Run Code Online (Sandbox Code Playgroud)
记录在这里:https://en.bitcoin.it/wiki/MtGox/API/HTTP/v1#Multi_currency_trades
这是功能:
string GetTradesOnline(Int64 tid)
{
Thread.Sleep(30000);
// communicate
string url = "https://data.mtgox.com/api/1/BTCUSD/trades?since=" + tid.ToString();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string json = reader.ReadToEnd();
reader.Close();
reader.Dispose();
response.Close();
return json;
}
Run Code Online (Sandbox Code Playgroud)
我从tid = 0(交易ID)开始获取数据(从一开始).对于每个请求,我收到一个包含1000个交易详情的回复.我总是从前一个响应中发送交易ID以用于下一个请求.它适用于4个请求和响应.但在此之后,以下行抛出"System.Net.WebException",表示"操作已超时":
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Run Code Online (Sandbox Code Playgroud)
这是事实:
什么可能是错的?
示例:当使用Windows API获取Windows消息时,通常在循环中实现.
我知道有可能创建一个将无限期地进入递归的函数.我希望这会导致堆栈溢出.
无限循环错误的功能编程思维定势?
是操作系统的接口还是硬件的问题?
在我看来,功能程序/操作系统似乎不能单独运行
我在编写功能程序方面有一点经验,但这一直困扰着我.请分享您对这些问题的想法/见解
我在一个循环中启动4个线程.每个线程获取一个数组元素的引用来写入结果.
但是在我创建每个线程的行上,我得到了一个System.IndexOutOfRangeException.我很惊讶索引"i"超出了范围.
这是一个例子:
void ThreadsStarter()
{
double[] data = new double[4];
for(int i = 0; i < 4; i++)
{
Thread my_thread = new Thread(() => Work(data[i]));
my_thread.Start();
}
}
void Work(double data)
{
}
Run Code Online (Sandbox Code Playgroud)
为什么会这样?
我正在使用以下记录类型
type MyRecord =
{ x : int
; y : int
; z : int
}
let r =
{ x = 0
; y = 0
; z = 0
}
Run Code Online (Sandbox Code Playgroud)
以下编译
let r' =
{ r with x = r.x+1;
y = r.y+2
}
Run Code Online (Sandbox Code Playgroud)
但以下
let r' =
{ r with x = r.x+1
; y = r.y+2
}
Run Code Online (Sandbox Code Playgroud)
给出编译错误
error FS0010: Unexpected symbol ';' in expression. Expected '}' or other token.
error FS0604: Unmatched '{'
error …Run Code Online (Sandbox Code Playgroud)