コード例 #1
0
        private async Task TryPrivateAPI(SxcContext context)
        {
            var currency       = "BTC";
            var marketCurrency = "USD";

            // List balances
            var listBalancesResult = await context.ListBalancesAsync();

            var currencyBalance = listBalancesResult.First(r => r.Currency == currency);

            if (currencyBalance == null)
            {
                throw new Exception($"No {currency} balance");
            }

            Console.WriteLine(currencyBalance);

            // Place order
            var orderCode = await context.PlaceOrderAsync(
                currency, marketCurrency,
                OrderType.Sell,
                (decimal)0.00000001,
                1000000);

            Console.WriteLine(orderCode);

            // List orders
            var listOrdersResult = await context.ListOrdersAsync();

            var order = listOrdersResult.First(r => r.Code == orderCode);

            if (order == null)
            {
                throw new Exception("Order not found");
            }

            Console.WriteLine(order);

            // Cancel order
            await context.CancelOrderAsync(orderCode);

            // Generate new address
            var address = await context.GenerateNewAddressAsync(currency);

            Console.WriteLine(address?.Address);

            // Withdraw
            // await context.WithdrawAsync(currency, address, DestinationType.CryptoAddress, currencyBalance.Available);

            // get LN Invoice
            var invoice = await context.GetLNInvoiceAsync(currency, (decimal)0.01);

            Console.WriteLine(invoice);
        }
コード例 #2
0
        private async Task RunAsync()
        {
            var context = new SxcContext("YOUR_API_KEY", "YOUR_API_SECRET");

            try
            {
                await TryPrivateAPI(context);
            }
            catch (SxcException e)
            {
                Console.WriteLine(e.Message);
            }

            InitializeWebSockets(context);
        }
コード例 #3
0
        private async Task RunAsync()
        {
            var context = new SxcContext("Your_API_Key", "Your_API_Secret");

            // List balances
            var listBalancesResult = await context.ListBalancesAsync();

            var limxBalance = listBalancesResult.First(r => r.Currency == "LIMX");

            if (limxBalance == null)
            {
                throw new Exception("No LIMX balance");
            }

            Console.WriteLine(limxBalance);

            // Place order
            var orderCode = await context.PlaceOrderAsync(
                "LIMX", "BTC",
                SouthXchange.Model.OrderType.Sell,
                limxBalance.Available,
                (decimal)99999);

            Console.WriteLine(orderCode);

            // List orders
            var listOrdersResult = await context.ListOrdersAsync();

            var order = listOrdersResult.First(r => r.Code == orderCode);

            if (order == null)
            {
                throw new Exception("Order not found");
            }

            Console.WriteLine(order);

            // Cancel order
            await context.CancelOrderAsync(orderCode);

            // Generate new address
            var address = await context.GenerateNewAddressAsync("LIMX");

            Console.WriteLine(address);

            // Withdraw
            await context.WithdrawAsync("LIMX", address, limxBalance.Available);
        }
コード例 #4
0
        private async Task RunAsync()
        {
            var context = new SxcContext("Your_API_Key", "Your_API_Secret");

            // List balances
            var listBalancesResult = await context.ListBalancesAsync();
            var limxBalance = listBalancesResult.First(r => r.Currency == "LIMX");
            
            if (limxBalance == null)
            {
                throw new Exception("No LIMX balance");
            }

            Console.WriteLine(limxBalance);

            // Place order
            var orderCode = await context.PlaceOrderAsync(
                "LIMX", "BTC",
                SouthXchange.Model.OrderType.Sell,
                limxBalance.Available,
                (decimal)99999);

            Console.WriteLine(orderCode);

            // List orders
            var listOrdersResult = await context.ListOrdersAsync();
            var order = listOrdersResult.First(r => r.Code == orderCode);

            if (order == null)
            {
                throw new Exception("Order not found");
            }

            Console.WriteLine(order);

            // Cancel order
            await context.CancelOrderAsync(orderCode);

            // Generate new address
            var address = await context.GenerateNewAddressAsync("LIMX");

            Console.WriteLine(address);

            // Withdraw
            await context.WithdrawAsync("LIMX", address, limxBalance.Available);
        }
コード例 #5
0
ファイル: AppContentController.cs プロジェクト: erw13n/2sxc
        public HttpResponseMessage GetContentBlockData()
        {
            Log.Add("get content block data");
            InitEavAndSerializer();
            // Important note: we are NOT supporting url-view switch at the moment for this
            // reason is, that this kind of data-access is fairly special
            // and not recommended for future use cases, where we have the query etc.
            // IF you want to support View-switching in this, do a deep review w/2dm first!
            // - note that it's really not needed, as you can always use a query or something similar instead
            // - not also that if ever you do support view switching, you will need to ensure security checks

            var dataHandler = new GetContentBlockDataLight(SxcContext);

            // must access engine to ensure pre-processing of data has happened,
            // especially if the cshtml contains a override void CustomizeData()
            SxcContext.GetRenderingEngine(InstancePurposes.PublishData);

            var    dataSource = SxcContext.Data;
            string json;

            if (dataSource.Publish.Enabled)
            {
                var publishedStreams = dataSource.Publish.Streams;
                var streamList       = publishedStreams.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                json = dataHandler.GetJsonFromStreams(dataSource, streamList);
            }
            else
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden)
                {
                    ReasonPhrase = dataHandler.GeneratePleaseEnableDataError(SxcContext.ModuleInfo.ModuleID,
                                                                             SxcContext.ModuleInfo.ModuleTitle)
                });
            }
            var response = Request.CreateResponse(HttpStatusCode.OK);

            response.Content = new StringContent(json, Encoding.UTF8, "application/json");
            return(response);
        }
コード例 #6
0
        private void InitializeWebSockets(SxcContext context)
        {
            context.RealTimeContext.OnConnected += (s, e) =>
            {
                Console.WriteLine("Connected");
                context.RealTimeContext.Request(7);
                context.RealTimeContext.Subscribe(7);
            };

            context.RealTimeContext.OnDisconnected += (s, e) =>
            {
                Console.WriteLine("Disconnected");
                Thread.Sleep(TimeSpan.FromSeconds(5));
                Console.WriteLine("Reconnecting");
                context.RealTimeContext.Connect();
            };

            context.RealTimeContext.OnMarketBook += (s, e) =>
            {
                e.Data.ToList().ForEach(book => {
                    Console.WriteLine($"book received for market id {book.MarketId}");
                    Console.WriteLine($"bid: {book.Book.OrderByDescending(b => b.Price).FirstOrDefault(b => b.IsBuy)?.Price}");
                    Console.WriteLine($"ask: {book.Book.OrderBy(b => b.Price).FirstOrDefault(b => !b.IsBuy)?.Price}");
                });
            };

            context.RealTimeContext.OnBookDeltaItem += (s, e) =>
            {
                e.Data.ToList().ForEach(b => Console.WriteLine($"price receieved: {b.Price}"));
            };

            context.RealTimeContext.OnTrade += (s, e) =>
            {
                e.Data.ToList().ForEach(b => Console.WriteLine($"trade receieved: {b.Price}"));
            };

            context.RealTimeContext.Connect();
        }