private void mtgoxTrade(Advice advice) { if (advice.Group == GroupBy.hour) { MtGoxAPIV0 v0 = new MtGoxAPIV0(); v0.apiKey = ConfigurationManager.AppSettings["mtgoxAPIKey"]; v0.apiSecret = ConfigurationManager.AppSettings["mtgoxAPISecret"]; List <MtGoxOrder> orders = v0.getOrders(MtGoxOrderType.Buy, MtGoxOrderStatus.Invalid); orders.AddRange(v0.getOrders(MtGoxOrderType.Buy, MtGoxOrderStatus.Active)); orders.AddRange(v0.getOrders(MtGoxOrderType.Buy, MtGoxOrderStatus.NotSufficientFunds)); orders.AddRange(v0.getOrders(MtGoxOrderType.Buy, MtGoxOrderStatus.Pending)); orders.AddRange(v0.getOrders(MtGoxOrderType.Sell, MtGoxOrderStatus.Active)); orders.AddRange(v0.getOrders(MtGoxOrderType.Sell, MtGoxOrderStatus.NotSufficientFunds)); orders.AddRange(v0.getOrders(MtGoxOrderType.Sell, MtGoxOrderStatus.Pending)); orders.AddRange(v0.getOrders(MtGoxOrderType.Sell, MtGoxOrderStatus.Invalid)); foreach (MtGoxOrder order in orders) { v0.cancelOrder(order.oid, order.type); } decimal adjustedPrice = decimal.MaxValue; if (advice.Action == TradeAction.Buy) { MtGoxHistoryItem funds = v0.info(); double cashOnHand = 0; foreach (MtGoxWallet wall in funds.Wallets) { if (wall.name == MtGoxCurrencySymbol.USD) { cashOnHand = wall.balance.value; } } adjustedPrice = advice.Price * (decimal)(1 - funds.Trade_Fee); v0.buyBTC(cashOnHand, MtGoxCurrencySymbol.USD, (double)adjustedPrice); } else if (advice.Action == TradeAction.Sell) { MtGoxHistoryItem funds = v0.info(); double cashOnHand = 0; foreach (MtGoxWallet wall in funds.Wallets) { if (wall.name == MtGoxCurrencySymbol.BTC) { cashOnHand = wall.balance.value; } } adjustedPrice = advice.Price * (decimal)(1 + funds.Trade_Fee); v0.sellBTC(21, MtGoxCurrencySymbol.USD, (double)adjustedPrice); } } }
/// <summary> /// 0/info.php /// </summary> public MtGoxHistoryItem info() { try { string url = (this.baseURL) + "0/info.php"; string postData = ""; string responseStr = (new MtGoxNetTools()).DoAuthenticatedAPIPost(url, apiKey, apiSecret, postData); return(MtGoxHistoryItem.getObjects(responseStr)); } catch (Exception ex) { return(null); } }