public override string DoOrder(CUtility.OrderType type, decimal?cost, decimal amount, ref string orderId, bool marketOrder) { //throw new NotImplementedException(); /* * potremmo evitare di fare ordini se non vengono smazzati gli eventuali precedenti */ return(""); try { if (cost.HasValue) { TradeType trade = type == CUtility.OrderType.Buy ? TradeType.Buy : TradeType.Sell; var result = _btceApi.Trade(currentPair, trade, cost.Value, amount); orderId = result.OrderId.ToString(CultureInfo.InvariantCulture); this.LastorderId = orderId; System.Console.WriteLine("Order success"); return(orderId); } else { System.Console.WriteLine("Order failed"); return(""); } } catch (Exception) { System.Console.WriteLine("Order error"); return(""); throw; } }
public override string DoOrder(CUtility.OrderType type, decimal?cost, decimal amount, ref string orderId, bool marketOrder) { //throw new NotImplementedException(); return(""); /* * potremmo evitare di fare ordini se non vengono smazzati gli eventuali precedenti */ IMtGoxExchange mtGoxExchange = new MtGoxExchange(); mtGoxExchange.APIKey = Api; mtGoxExchange.APISecret = Secret; OrderType ordertype = type == CUtility.OrderType.Buy ? OrderType.Bid : OrderType.Ask; OrderCreateResponse response = mtGoxExchange.CreateOrder(currency, ordertype, (double)amount, null); if (response.Result == ResponseResult.Success) { orderId = response.OID.ToString(); System.Console.WriteLine("Order success"); return(response.OID.ToString()); } else { orderId = ""; System.Console.WriteLine("Order failed"); return(""); } }
public override string DoOrder(CUtility.OrderType type, decimal?cost, decimal amount, ref string orderId, bool marketOrder) { decimal costReal; //throw new NotImplementedException(); if (type == CUtility.OrderType.Buy) { costReal = cost.HasValue ? cost.Value : this.Buy; this.TotMoney -= amount * costReal; var coins = amount * (1M - Fee); this.TotCoins += coins; orderId = System.Guid.NewGuid().ToString(); TotBids++; //this.TotValue = TotCoins * costReal + this.TotMoney; } else { costReal = cost.HasValue ? cost.Value : this.Sell; //throw new NotImplementedException(); var money = amount * costReal; this.TotCoins -= amount; this.TotMoney += money * (1M - Fee); //this.TotValue = TotCoins * costReal + this.TotMoney; TotAsks++; } // fissa eventuali negativi per arrotondamento if (this.TotCoins < 0) { this.TotCoins = 0; } if (this.TotMoney < 0) { this.TotMoney = 0; } this.AvgTimes++; this.AvgSum += this.TotValue; return(""); }
public override string DoOrder(CUtility.OrderType type, decimal?price, decimal amount, ref string orderId, bool isMarket) { if (price == null) { return(null); } amount = Math.Round(amount, 8); price = Math.Round(price.Value, this.Decimals); const string apiurl = "https://data.mtgox.com/api/2/"; const string path = "BTCUSD/money/order/add"; var client = new RestClient(apiurl + path); var request = new RestRequest(); _nonce = getNonce(); // DateTime.Now.Ticks; var data = "nonce=" + _nonce; var amountInt = (Math.Round(amount, 8) * 100000000).ToString(CultureInfo.InvariantCulture); // Bid/ask string orderType = "bid"; if (type == CUtility.OrderType.Sell) { orderType = "ask"; } var parameters = new NameValueCollection { { "amount_int", amountInt }, { "type", orderType } }; //if (price != null) { if (!isMarket) { var priceInt = (Math.Round((double)price, 5) * 100000).ToString(CultureInfo.InvariantCulture); parameters.Add("price_int", priceInt); } } var sign = getHash(Secret, path + Convert.ToChar(0) + data + ToQueryString(parameters)); request.AddHeader("Rest-Key", Apikey); request.AddHeader("Rest-Sign", sign); request.Method = Method.POST; request.AddParameter("nonce", _nonce); foreach (string key in parameters.Keys) { request.AddParameter(key, parameters[key]); } var response = client.Execute <JsonOrderResponse>(request); CUtility.Log(response.Content); try { var result = response.Data.Result == "success" ? response.Data.Data : null; if (result != null) { orderId = response.Data.Data; //this.OnDoOrder(type, price, amount, orderId,r2); //OrdersInThisIteration++; } return(result); } catch (Exception e) { CUtility.Log(e.Message); return(null); } }
//public CandleMaker CandleMakerDaily; // bubbles è l'elenco delle bolle nel mercato //private readonly List<CBubble> _bubbles = new List<CBubble>(); //public List<CBubble> Bubbles { get { return _bubbles; } } // effettua un ordine public abstract string DoOrder(CUtility.OrderType type, decimal?cost, decimal amount, ref string orderId, bool marketOrder);
public override string DoOrder(CUtility.OrderType type, decimal?cost, decimal amount, ref string orderId, bool marketOrder) { //we dont do orders throw new NotImplementedException(); }