public bool Init() { bool bReturn = true; try { mtgoxV0.apiKey = MtGoxConfig.Key; mtgoxV0.apiSecret = MtGoxConfig.Secret; Currency = MtGoxConfig.Currency; userInfo = new UserInfo(); userInfo.Currency = Currency; historyFund = new HistoryInfo(); historyBtc = new HistoryInfo(); currentHistory = mtgoxV0.info(); if (currentHistory == null) { bReturn = false; return bReturn; } this.LoadHistory(); this.loadUserInfo(); this.loadOrders(); tickerTimer = new System.Threading.Timer(GetRealtimeTrade, null, Consts.DefaultRefreshTime * 1000, Consts.DefaultRefreshTime * 1000); formTimer = new System.Threading.Timer(BindRealtimeTrade, null, Consts.DefaultRefreshTime * 1000 + System.DateTime.Now.Month * 100 + System.DateTime.Now.Year, Consts.DefaultRefreshTime * 1000); this.GetRealtimeTrade(null); this.BindUserInfo(); } catch (Exception ex) { bReturn = false; Trace.WriteLine(string.Format("{0} \r\n stack:{1}", Utils.GetDetailedException(ex), Utils.GetStackTrace(ex))); } return bReturn; }
/// <summary> /// Parse the JSON data returned by the 0/info.php method /// </summary> public static MtGoxHistoryItem getObjects(string jsonDataStr) { string json = jsonDataStr; var serializer = new JavaScriptSerializer(); serializer.RegisterConverters(new[] { new DynamicJsonConverter() }); dynamic obj = serializer.Deserialize(json, typeof(object)); MtGoxHistoryItem item = new MtGoxHistoryItem(); item.Login = obj.Login.ToString(); item.Index = int.Parse(obj.Index.ToString()); item.Rights = new List<string>(); for (int i = 0; i < obj.Rights.Count; i++) { item.Rights.Add(obj.Rights[i].ToString()); } item.Language = obj.Language.ToString(); item.Created = DateTime.Parse(obj.Created.ToString()); item.Last_Login = DateTime.Parse(obj.Last_Login.ToString()); item.Wallets = new List<MtGoxWallet>(); try { item.Wallets.Add(MtGoxHistoryItem.BuildWallet("USD", obj.Wallets.USD)); } catch(Exception ex) { } // AUD try { item.Wallets.Add(MtGoxHistoryItem.BuildWallet("AUD", obj.Wallets.AUD)); } catch (Exception ex) { } // CAD try { item.Wallets.Add(MtGoxHistoryItem.BuildWallet("CAD", obj.Wallets.CAD)); } catch (Exception ex) { } // CHF try { item.Wallets.Add(MtGoxHistoryItem.BuildWallet("CHF", obj.Wallets.CHF)); } catch (Exception ex) { } // CNY try { item.Wallets.Add(MtGoxHistoryItem.BuildWallet("CNY", obj.Wallets.CNY)); } catch (Exception ex) { } // DKK try { item.Wallets.Add(MtGoxHistoryItem.BuildWallet("DKK", obj.Wallets.DKK)); } catch (Exception ex) { } // EUR try { item.Wallets.Add(MtGoxHistoryItem.BuildWallet("EUR", obj.Wallets.EUR)); } catch (Exception ex) { } // GBP try { item.Wallets.Add(MtGoxHistoryItem.BuildWallet("GBP", obj.Wallets.GBP)); } catch (Exception ex) { } // HKD try { item.Wallets.Add(MtGoxHistoryItem.BuildWallet("HKD", obj.Wallets.HKD)); } catch (Exception ex) { } // JPY try { item.Wallets.Add(MtGoxHistoryItem.BuildWallet("JPY", obj.Wallets.JPY)); } catch (Exception ex) { } // NZD try { item.Wallets.Add(MtGoxHistoryItem.BuildWallet("NZD", obj.Wallets.NZD)); } catch (Exception ex) { } // PLN try { item.Wallets.Add(MtGoxHistoryItem.BuildWallet("PLN", obj.Wallets.PLN)); } catch (Exception ex) { } // RUB try { item.Wallets.Add(MtGoxHistoryItem.BuildWallet("RUB", obj.Wallets.RUB)); } catch (Exception ex) { } // SEK try { item.Wallets.Add(MtGoxHistoryItem.BuildWallet("SEK", obj.Wallets.SEK)); } catch (Exception ex) { } // SGD try { item.Wallets.Add(MtGoxHistoryItem.BuildWallet("SGD", obj.Wallets.SGD)); } catch (Exception ex) { } // THB try { item.Wallets.Add(MtGoxHistoryItem.BuildWallet("THB", obj.Wallets.THB)); } catch (Exception ex) { } // BTC try { item.Wallets.Add(MtGoxHistoryItem.BuildWallet("BTC", obj.Wallets.BTC)); } catch (Exception ex) { } item.Trade_Fee = double.Parse(obj.Trade_Fee.ToString()); return item; }
/// <summary> /// Parse the JSON data returned by the 0/info.php method /// </summary> public static MtGoxHistoryItem getObjects(string jsonDataStr) { string json = jsonDataStr; var serializer = new JavaScriptSerializer(); serializer.RegisterConverters(new[] { new DynamicJsonConverter() }); dynamic obj = serializer.Deserialize(json, typeof(object)); MtGoxHistoryItem item = new MtGoxHistoryItem(); item.Login = obj.Login.ToString(); item.Index = int.Parse(obj.Index.ToString()); item.Rights = new List <string>(); for (int i = 0; i < obj.Rights.Count; i++) { item.Rights.Add(obj.Rights[i].ToString()); } item.Language = obj.Language.ToString(); item.Created = DateTime.Parse(obj.Created.ToString()); item.Last_Login = DateTime.Parse(obj.Last_Login.ToString()); item.Wallets = new List <MtGoxWallet>(); try { item.Wallets.Add(MtGoxHistoryItem.BuildWallet("USD", obj.Wallets.USD)); } catch (Exception ex) { } // AUD try { item.Wallets.Add(MtGoxHistoryItem.BuildWallet("AUD", obj.Wallets.AUD)); } catch (Exception ex) { } // CAD try { item.Wallets.Add(MtGoxHistoryItem.BuildWallet("CAD", obj.Wallets.CAD)); } catch (Exception ex) { } // CHF try { item.Wallets.Add(MtGoxHistoryItem.BuildWallet("CHF", obj.Wallets.CHF)); } catch (Exception ex) { } // CNY try { item.Wallets.Add(MtGoxHistoryItem.BuildWallet("CNY", obj.Wallets.CNY)); } catch (Exception ex) { } // DKK try { item.Wallets.Add(MtGoxHistoryItem.BuildWallet("DKK", obj.Wallets.DKK)); } catch (Exception ex) { } // EUR try { item.Wallets.Add(MtGoxHistoryItem.BuildWallet("EUR", obj.Wallets.EUR)); } catch (Exception ex) { } // GBP try { item.Wallets.Add(MtGoxHistoryItem.BuildWallet("GBP", obj.Wallets.GBP)); } catch (Exception ex) { } // HKD try { item.Wallets.Add(MtGoxHistoryItem.BuildWallet("HKD", obj.Wallets.HKD)); } catch (Exception ex) { } // JPY try { item.Wallets.Add(MtGoxHistoryItem.BuildWallet("JPY", obj.Wallets.JPY)); } catch (Exception ex) { } // NZD try { item.Wallets.Add(MtGoxHistoryItem.BuildWallet("NZD", obj.Wallets.NZD)); } catch (Exception ex) { } // PLN try { item.Wallets.Add(MtGoxHistoryItem.BuildWallet("PLN", obj.Wallets.PLN)); } catch (Exception ex) { } // RUB try { item.Wallets.Add(MtGoxHistoryItem.BuildWallet("RUB", obj.Wallets.RUB)); } catch (Exception ex) { } // SEK try { item.Wallets.Add(MtGoxHistoryItem.BuildWallet("SEK", obj.Wallets.SEK)); } catch (Exception ex) { } // SGD try { item.Wallets.Add(MtGoxHistoryItem.BuildWallet("SGD", obj.Wallets.SGD)); } catch (Exception ex) { } // THB try { item.Wallets.Add(MtGoxHistoryItem.BuildWallet("THB", obj.Wallets.THB)); } catch (Exception ex) { } // BTC try { item.Wallets.Add(MtGoxHistoryItem.BuildWallet("BTC", obj.Wallets.BTC)); } catch (Exception ex) { } item.Trade_Fee = double.Parse(obj.Trade_Fee.ToString()); return(item); }