예제 #1
0
        private void CreateConnection(CurrencyName instrument)
        {
            var config     = (BotcoinConfigSection)ConfigurationManager.GetSection("botcoin");
            var connection = config.FindConnectionElement("RestScheduler");
            var strAddr    = String.Format(connection.DomainName, instrument.ToString().ToLower());
            var ipAddr     = Dns.GetHostEntry(strAddr).AddressList.Where(a => a.AddressFamily == AddressFamily.InterNetwork).First();

            _log.WriteInfo(String.Format("{0} subscribed", instrument.ToString()));
            _connections.Add(new Tuple <CurrencyName, IPEndPoint>(instrument, new IPEndPoint(ipAddr, connection.Port)));
        }
예제 #2
0
 public BudgetInfo(DateTime period, double amount, CurrencyName currency, double percentage)
 {
     Period     = string.Format("{0:MM/yyyy}", period);
     Amount     = Math.Round(amount, 2);
     Currency   = currency.ToString();
     Percentage = Math.Round(percentage, 2);
 }
예제 #3
0
        public override OrderResponse PlaceOrder(double price, double amount, CurrencyName currency, OrderSide side, TradeOrderType type = TradeOrderType.Limit)
        {
            QuadrigaOrderResponse response = null;
            string path = side == OrderSide.BID ? "buy" : "sell";
            string book = currency.ToString().ToLower() + "_cad";

            if (type == TradeOrderType.Limit)
            {
                response = _client.PlaceLimitOrder(path, amount, book, price);
            }
            else if (type == TradeOrderType.Market)
            {
                response = _client.PlaceMarketOrder(path, amount, book, price);
            }
            else
            {
                throw new ArgumentException("Invalid order type");
            }

            return(response.Error == null
                ? new OrderResponse(response.Datetime, response.OrderId)
                : new OrderResponse()
            {
                ErrorReason = response.Error.Message
            });
        }
예제 #4
0
        public override OrderResponse PlaceOrder(double price, double amount, CurrencyName inst, OrderSide side, TradeOrderType type = TradeOrderType.Limit)
        {
            BitstampOrderResponse response = null;
            var symbol = inst.ToString().ToLower() + "usd";

            if (type == TradeOrderType.Limit)
            {
                response = Client.PlaceLimitOrder(side == OrderSide.BID ? "buy" : "sell", symbol, amount, price);
            }
            else
            {
                throw new ArgumentException("[Bitstamp] Invalid order type");
            }

            if (String.Compare(response.Status, "error", true) != 0)
            {
                return(new OrderResponse(response.Datetime, response.OrderId));
            }

            var str = new StringBuilder("[Bitstamp] PlaceOrder");

            foreach (var error in response.Reason.All)
            {
                str.AppendFormat(" {0}", error);
            }
            return(new OrderResponse()
            {
                ErrorReason = str.ToString()
            });
        }
예제 #5
0
        public void SubscribeTrade(CurrencyName instrument1, EventHandler <TradeEventArgs> handler = null, CurrencyName instrument2 = CurrencyName.USDT)
        {
            if (handler != null)
            {
                if (instrument1 == CurrencyName.BTC)
                {
                    _btcTradeHandler += handler;
                }
                if (instrument1 == CurrencyName.BCH)
                {
                    _bchTradeHandler += handler;
                }
                if (instrument1 == CurrencyName.LTC)
                {
                    _ltcTradeHandler += handler;
                }
                if (instrument1 == CurrencyName.ETH)
                {
                    _ethTradeHandler += handler;
                }
                if (instrument1 == CurrencyName.XRP)
                {
                    _xrpTradeHandler += handler;
                }
            }

            var channelName = String.Format(TradeChannel, instrument1.ToString().ToLower(), instrument2.ToString().ToLower());

            SendMessage(c => c.Send("{'event':'addChannel'," + channelName + "}"));
        }
예제 #6
0
        private void UnsubscribeTrade(CurrencyName instrument1, EventHandler <TradeEventArgs> handler, CurrencyName instrument2 = CurrencyName.USDT)
        {
            if (instrument1 == CurrencyName.BTC)
            {
                _btcTradeHandler -= handler;
            }
            if (instrument1 == CurrencyName.BCH)
            {
                _bchTradeHandler -= handler;
            }
            if (instrument1 == CurrencyName.LTC)
            {
                _ltcTradeHandler -= handler;
            }
            if (instrument1 == CurrencyName.ETH)
            {
                _ethTradeHandler -= handler;
            }
            if (instrument1 == CurrencyName.XRP)
            {
                _xrpTradeHandler -= handler;
            }

            var channelName = String.Format(TradeChannel, instrument1.ToString().ToLower(), instrument2.ToString().ToLower());

            SendMessage(c => c.Send("{'event':'removeChannel'," + channelName + "}"));
        }
예제 #7
0
        public void SubscribeOrderBook(CurrencyName instrument1, EventHandler <OrderBookEventArgs> handler = null, CurrencyName instrument2 = CurrencyName.USDT)
        {
            string channelName = null;

            if (handler != null)
            {
                if (instrument1 == CurrencyName.BTC)
                {
                    _btcOrderBookHandler += handler;
                }
                else if (instrument1 == CurrencyName.BCH)
                {
                    _bchOrderBookHandler += handler;
                }
                else if (instrument1 == CurrencyName.LTC)
                {
                    _ltcOrderBookHandler += handler;
                }
                else if (instrument1 == CurrencyName.ETH)
                {
                    _ethOrderBookHandler += handler;
                }
                else if (instrument1 == CurrencyName.IOTA)
                {
                    _iotaOrderBookHandler += handler;
                }
            }

            channelName = String.Format(OrderBookChannel, instrument1.ToString(), instrument2.ToString()).ToLower();
            SendMessage(c => c.Send("{'event':'addChannel'," + channelName + "}"));
        }
예제 #8
0
        public void UnsubscribeOrderBook(CurrencyName instrument1, EventHandler <OrderBookEventArgs> handler, CurrencyName instrument2 = CurrencyName.USDT)
        {
            if (instrument1 == CurrencyName.BTC)
            {
                _btcOrderBookHandler -= handler;
            }
            if (instrument1 == CurrencyName.BCH)
            {
                _bchOrderBookHandler -= handler;
            }
            if (instrument1 == CurrencyName.LTC)
            {
                _ltcOrderBookHandler -= handler;
            }
            if (instrument1 == CurrencyName.ETH)
            {
                _ethOrderBookHandler -= handler;
            }
            if (instrument1 == CurrencyName.IOTA)
            {
                _iotaOrderBookHandler -= handler;
            }

            var channelName = String.Format(OrderBookChannel, instrument1.ToString().ToLower(), instrument2.ToString().ToLower());

            SendMessage(c => c.Send("{'event':'removeChannel'," + channelName + "}"));
        }
예제 #9
0
        public override OrderResponse PlaceOrder(double price, double amount, CurrencyName currency, DataType.OrderSide orderSide, TradeOrderType type = TradeOrderType.Limit)
        {
            if (!(currency == CurrencyName.BTC || currency == CurrencyName.BCH ||
                  currency == CurrencyName.ETH || currency == CurrencyName.LTC))
            {
                return(new OrderResponse {
                    ErrorReason = "Invalid instrument"
                });
            }
            var currencyName = currency.ToString();

            if (currency == CurrencyName.BCH)
            {
                currencyName = "BCC";
            }

            var symbol = currencyName + "USDT";
            var side   = orderSide == DataType.OrderSide.BID ? Binance.Net.Objects.OrderSide.Buy : Binance.Net.Objects.OrderSide.Sell;

            //"LIMIT", "LIMIT_MAKER", "MARKET", "STOP_LOSS_LIMIT", "TAKE_PROFIT_LIMIT"

            var result = _client.PlaceOrder(symbol, side, OrderType.Limit, TimeInForce.GoodTillCancel, amount, price);

            return(result.Success
                ? new OrderResponse(result.Data.TransactTime, result.Data.OrderId.ToString())
                : new OrderResponse {
                ErrorReason = result.Error.Message, ErrorCode = result.Error.Code
            });
        }
예제 #10
0
        private void CreateConnection(CurrencyName instrument)
        {
            var config     = (BotcoinConfigSection)ConfigurationManager.GetSection("botcoin");
            var connection = config.FindConnectionElement("RestScheduler");

#if true
            var subDomainName = instrument.ToString().ToLower();
            if (Dns.Resolve(Dns.GetHostName()).AddressList[0].ToString() == "185.226.113.60")
            {
                subDomainName += "-test";
            }
#endif
            var strAddr = String.Format("{0}.{1}", subDomainName, connection.DomainName);
            var ipAddr  = Dns.GetHostEntry(strAddr).AddressList.Where(a => a.AddressFamily == AddressFamily.InterNetwork).First();

            _log.WriteInfo(String.Format("{0} subscribed", instrument.ToString()));
            _connections.Add(new Tuple <CurrencyName, IPEndPoint>(instrument, new IPEndPoint(ipAddr, connection.Port)));
        }
예제 #11
0
        public override OrderResponse PlaceOrder(double price, double amount, CurrencyName currency, OrderSide side, TradeOrderType type = TradeOrderType.Limit)
        {
            string market = currency.ToString().ToLower() + "uah";
            var    order  = _client.PlaceOrder(market, side == OrderSide.BID ? "buy" : "sell", amount, price);

            return(order.Error == null
                ? new OrderResponse(order.CreatedAt, order.Id)
                : new OrderResponse {
                ErrorReason = order.Error.Message
            });
        }
예제 #12
0
        public KunaOrdersHistory[] GetOrdersHistory(CurrencyName inst)
        {
            var args = CreateSignHeaders("trades/my", "GET", new SortedDictionary <string, string>
            {
                { "market", inst.ToString().ToLower() + "uah" }
            });

            var response = UserQuery("trades/my", HttpMethod.Get, null, UrlEncode(args));

            return(JsonConvert.DeserializeObject <KunaOrdersHistory[]>(response.Content));
        }
예제 #13
0
        public OrderBook GetOrderBook(CurrencyName ins)
        {
            string insName = ins.ToString();

            if (ins == CurrencyName.BCH)
            {
                insName = "BCC";
            }
            if (ins == CurrencyName.DSH)
            {
                insName = "DASH";
            }

            var json      = GetQuery(String.Format("{0}public/getorderbook?market=USDT-{1}&type=both", BaseUri, insName));
            var response  = JsonConvert.DeserializeObject <BittrexOrderBook>(json);
            var orderBook = new OrderBook {
                Currency = ins
            };

            int askLen = response.Result.Sell.Length;

            if (askLen > OrderBookLimit)
            {
                askLen = OrderBookLimit;
            }

            orderBook.Asks = new Order[askLen];
            for (int i = 0; i < orderBook.Asks.Length; i++)
            {
                var ask = response.Result.Sell[i];
                orderBook.Asks[i] = new Order {
                    Price = ask.Rate, Amount = ask.Quantity
                };
            }

            int bidLen = response.Result.Buy.Length;

            if (bidLen > OrderBookLimit)
            {
                bidLen = OrderBookLimit;
            }

            orderBook.Bids = new Order[bidLen];
            for (int i = 0; i < orderBook.Bids.Length; i++)
            {
                var bid = response.Result.Buy[i];
                orderBook.Bids[i] = new Order {
                    Price = bid.Rate, Amount = bid.Quantity
                };
            }

            return(orderBook);
        }
예제 #14
0
        public OrderBook GetOrderBook(CurrencyName currency, CurrencyName instrument)
        {
            string instrumentName = instrument.ToString().ToLower();

            if (instrument == CurrencyName.BCH)
            {
                instrumentName = "bcc";
            }
            if (instrument == CurrencyName.DSH)
            {
                instrumentName = "dash";
            }

            var json      = GetQuery(String.Format("{0}PUBLIC/{1}{2}/orderbook.json", BaseUri, instrumentName, currency.ToString().ToLower()));
            var response  = JsonConvert.DeserializeObject <BitbayOrderBook>(json);
            var orderBook = new OrderBook {
                Currency = currency
            };

            var count = response.Asks.Length;

            if (count > OrderBookLimit)
            {
                count = OrderBookLimit;
            }
            orderBook.Asks = new Order[count];

            count = response.Bids.Length;
            if (count > OrderBookLimit)
            {
                count = OrderBookLimit;
            }
            orderBook.Bids = new Order[count];

            for (int i = 0; i < orderBook.Asks.Length; i++)
            {
                orderBook.Asks[i] = new Order {
                    Price = response.Asks[i][0], Amount = response.Asks[i][1]
                }
            }
            ;

            for (int i = 0; i < orderBook.Bids.Length; i++)
            {
                orderBook.Bids[i] = new Order {
                    Price = response.Bids[i][0], Amount = response.Bids[i][1]
                }
            }
            ;

            return(orderBook);
        }
예제 #15
0
 private void UnsubscribeOrderBook(CurrencyName currency)
 {
     SendMessage(c => c.Send(JsonConvert.SerializeObject(new XBtcUnsubscribeRequest
     {
         Id      = DateTime.Now.Ticks.ToString(),
         Request = "FeedSubscribe",
         Params  = new XBtcUnsubscribeRequestArgs {
             Unsubscribe = new string[1] {
                 currency.ToString() + "USD"
             }
         }
     })));
 }
예제 #16
0
        private CategoryStatistics GetCategoryStatistics(IEnumerable <Operation> operations, CurrencyName currency)
        {
            var statistics = new CategoryStatistics();
            var info       = new List <CategoryInfo>();
            var categories = operations.UsedCategories();

            foreach (var category in categories)
            {
                info.Add(GetCategoryInfo(operations, category, currency));
            }
            statistics.Currency = currency.ToString();
            statistics.Info     = info.OrderByDescending(x => x.Persentage);
            return(statistics);
        }
예제 #17
0
 private void SubscribeOrderBook(CurrencyName currency)
 {
     SendMessage(c => c.Send(JsonConvert.SerializeObject(new XBtcSubscribeRequest
     {
         Id      = DateTime.Now.Ticks.ToString(),
         Request = "FeedSubscribe",
         Params  = new XBtcSubscribeRequestArgs
         {
             Subscribe = new XBtcRequestItem[1]
             {
                 new XBtcRequestItem {
                     Symbol = currency.ToString() + "USD", BookDepth = 10
                 }
             }
         }
     })));
 }
예제 #18
0
        private CategoryInfo GetCategoryInfo(IEnumerable <Operation> operations, OperationCategory category, CurrencyName currency)
        {
            var categorized       = operations.ByCategory(category);
            var amountTotal       = operations.ByType(category.Type).Sum(x => x.Amount);
            var amountCategorized = categorized.Sum(x => x.Amount);
            var iterations        = categorized.Count();
            var persentage        = amountTotal > 0 ? amountCategorized * 100 / amountTotal : 0;

            return(new CategoryInfo()
            {
                Name = category.Name,
                Amount = amountCategorized,
                Iterations = iterations,
                Persentage = Math.Round(persentage, 1),
                BaseCurrency = currency.ToString()
            });
        }
예제 #19
0
        public void Disconnect(CurrencyName instrument)
        {
            if (!_started)
            {
                return;
            }

            _counter = 0;
            TimerAction(false);

            lock (_obj)
            {
                var connection = _connections.Where(p => p.Item1 == instrument).SingleOrDefault();
                _connections.Remove(connection);
                _log.WriteInfo(String.Format("{0} unsubscribed", instrument.ToString()));
                TimerAction(_connections.Count > 0);
            }
        }
예제 #20
0
        public BitBayPlaceOrder PlaceOrder(string type, CurrencyName instrument, double amount, CurrencyName currency, double price)
        {
            string message;
            var    headers = CreateHeaders(new Dictionary <string, string>()
            {
                { "type", type },
                { "currency", instrument.ToString() },
                { "amount", amount.ToString(CultureInfo.InvariantCulture) },
                { "payment_currency", currency.ToString() },
                { "rate", price.ToString(CultureInfo.InvariantCulture) },
                { "method", "trade" },
                { "moment", DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString() }
            },
                                           out message);

            var response = UserQuery("Trading/tradingApi.php", HttpMethod.Post, headers, message);

            return(JsonConvert.DeserializeObject <BitBayPlaceOrder>(response.Content));
        }
예제 #21
0
        private void UnsubscribeOrderBook(CurrencyName currency)
        {
            var name = currency.ToString();

            if (currency == CurrencyName.DSH)
            {
                name = "DASH";
            }

            SendMessage(c => c.Send(JsonConvert.SerializeObject(new CexOrderBookRequest
            {
                e    = "order-book-unsubscribe",
                data = new CexOrderBookRequest.CexOrderBookData
                {
                    pair = new string[] { name, "USD" }
                },
                oid = "1435927928274_4_order-book-unsubscribe"
            })));
        }
예제 #22
0
        public override OrderResponse PlaceOrder(double price, double amount, CurrencyName inst, OrderSide side, TradeOrderType type = TradeOrderType.Limit)
        {
            OkExOrderResponse response = null;
            var symbol = inst.ToString().ToLower() + "_usd";

            if (type == TradeOrderType.Limit)
            {
                response = _client.PlaceLimitOrder(side == OrderSide.BID ? "buy" : "sell", symbol, amount, price);
            }
            else
            {
                throw new ArgumentException("Invalid order type");
            }

            return(response.Result
                ? new OrderResponse(DateTime.UtcNow, response.OrderId)
                : new OrderResponse()
            {
                ErrorReason = String.Format("[OkEx] {0}", response.ErrorCode)
            });
        }
예제 #23
0
 public Models.CustomerResponse Deposit([FromBody] Models.WithdrawRequest withdrawRequest)
 {
     Models.CustomerResponse res = new CustomerResponse();
     Chilindo.BAL.BALModels.ProcessedResponse result = new BAL.BALModels.ProcessedResponse();
     try
     {
         Chilindo.BAL.CustomerAccountManager objAccountDetails = new BAL.CustomerAccountManager();
         APICurrency = ConfigurationManager.AppSettings["APICURRENCY"];
         CurrencyName curr = (CurrencyName)Enum.Parse(typeof(CurrencyName), withdrawRequest.Currency.ToString());
         result = objAccountDetails.Deposit(withdrawRequest.AccountNumber, withdrawRequest.Amount, APICurrency, curr.ToString());
         res    = new CustomerResponse {
             AccountNumber = result.AccountNumber, Balance = result.Balance, Currency = result.Currency, Message = result.Message, Successful = true
         };
     }
     catch (Exception ex)
     {
         res = new CustomerResponse {
             AccountNumber = result.AccountNumber, Balance = result.Balance, Currency = result.Currency, Message = string.Format("API Error :{0} / Stack Trace {1}", result.Message, ex.StackTrace), Successful = true
         };
     }
     return(res);
 }
예제 #24
0
        public override OrderResponse[] GetActiveOrders(CurrencyName currency = CurrencyName.Undefined)
        {
            var currencyPair = currency.ToString().ToLower() + "usd";

            return(Client.GetActiveOrders(currencyPair).Select(o => new OrderResponse(o)).ToArray());
        }
예제 #25
0
        public OrderBook GetOrderBook(CurrencyName instrument, CurrencyName currency)
        {
            var json     = GetQuery(String.Format("{0}order_book?book={1}_{2}", BaseUri, instrument.ToString().ToLower(), currency.ToString().ToLower()));
            var response = JsonConvert.DeserializeObject <QuadrigaOrderBook>(json);

            if (response.Error != null)
            {
                throw new System.Net.WebException(response.Error.Message);
            }

            var orderBook = new OrderBook {
                Currency = currency, Timestamp = response.Timestamp
            };

            orderBook.Asks = new Order[response.Asks.Length];
            orderBook.Bids = new Order[response.Bids.Length];

            for (int i = 0; i < orderBook.Asks.Length; i++)
            {
                orderBook.Asks[i] = new Order {
                    Price = response.Asks[i][0], Amount = response.Asks[i][1]
                }
            }
            ;

            for (int i = 0; i < orderBook.Bids.Length; i++)
            {
                orderBook.Bids[i] = new Order {
                    Price = response.Bids[i][0], Amount = response.Bids[i][1]
                }
            }
            ;

            return(orderBook);
        }
예제 #26
0
        public OrderBook GetOrderBook(CurrencyName instrument, CurrencyName currency)
        {
            var json     = GetQuery(String.Format("{0}depth.do?symbol={1}_{2}", BaseUri, instrument.ToString().ToLower(), currency.ToString().ToLower()));
            var response = JsonConvert.DeserializeObject <OrderBook>(json);

            SortAsks(response);

            return(response);
        }
예제 #27
0
        public override OrderResponse[] GetActiveOrders(CurrencyName currency = CurrencyName.Undefined)
        {
            var orders = _client.GetActiveOrders(currency.ToString().ToLower() + "_cad");

            return(orders.Select(o => new OrderResponse(o)).ToArray());
        }
예제 #28
0
    public override string ToString()
    {
        var  sb      = new StringBuilder("PaidCallCurrencyExchangeRate(");
        bool __first = true;

        if (CurrencyCode != null && __isset.currencyCode)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("CurrencyCode: ");
            CurrencyCode.ToString(sb);
        }
        if (CurrencyName != null && __isset.currencyName)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("CurrencyName: ");
            CurrencyName.ToString(sb);
        }
        if (CurrencySign != null && __isset.currencySign)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("CurrencySign: ");
            CurrencySign.ToString(sb);
        }
        if (__isset.preferred)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("Preferred: ");
            Preferred.ToString(sb);
        }
        if (CoinRate != null && __isset.coinRate)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("CoinRate: ");
            CoinRate.ToString(sb);
        }
        if (CreditRate != null && __isset.creditRate)
        {
            if (!__first)
            {
                sb.Append(", ");
            }
            __first = false;
            sb.Append("CreditRate: ");
            CreditRate.ToString(sb);
        }
        sb.Append(")");
        return(sb.ToString());
    }
예제 #29
0
 public BudgetSummary(CurrencyName currency, IEnumerable <BudgetInfo> items)
 {
     Currency = currency.ToString();
     Items    = items;
 }
예제 #30
0
        public double MinOrderSize(CurrencyName currency)
        {
            int index = MinimumOrder.IndexOf(currency.ToString());

            return(Double.Parse(MinimumOrder.Substring(0, index).Trim()));
        }