コード例 #1
0
ファイル: Program.cs プロジェクト: oykd/CSE-api
 private static void exampleThreadLoop()
 {
     try
     {
         Console.WriteLine(" >>> Thread test >>> ");
         Console.WriteLine(" * get BTC price from various Stock Exchanges simultaneously (*10)");
         var binance = new Binance(String.Empty, String.Empty);
         var kucoin  = new Kucoin(String.Empty, String.Empty);
         var huobi   = new Huobi(String.Empty, String.Empty);
         var gate    = new Gate(String.Empty, String.Empty);
         for (int i = 0; i < 10; i++)
         {
             // Get OrderBooks
             binance.sendReq("GET /api/v1/depth !symbol=BTCUSDT&limit=50");
             kucoin.sendReq("GET /v1/open/orders symbol=BTC-USDT");
             huobi.sendReq("GET /market/depth symbol=btcusdt&type=step1");
             gate.sendReq("GET 1/orderBook/btc_usdt");
             while (isSomeStockWaiting(new dynamic[] { binance, kucoin, huobi, gate }))
             {
                 Thread.Sleep(1);
             }
             // Get best Purchase price for BTC from OrderBooks
             string result = $"{i}. ";
             result += $"Binance:{binance.responseData.getJsonValueAfterKeys(new string[] { "asks" }).getInnerFloat().ToString(" 0.00 ")} ";
             result += $"Kucoin:{kucoin.responseData.getJsonValueAfterKeys(new string[] { "data", "SELL" }).getInnerFloat().ToString(" 0.00 ")} ";
             result += $"Huobi:{huobi.responseData.getJsonValueAfterKeys(new string[] { "asks" }).getInnerFloat().ToString(" 0.00 ")} ";
             result += $"Gate:{gate.responseData.getJsonValueAfterKeys(new string[] { "asks" }).getInnerFloat(", ", helpers.way.reverse).ToString(" 0.00 ")} ";
             Console.WriteLine(result);
         }
         Console.WriteLine($" >>> End >>> ");
     }
     catch (Exception ex)
     {
         Console.WriteLine($"Error: {ex.Message}");
     }
     finally
     {
         exampleThread = null;
     }
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: oykd/CSE-api
        static void Main(string[] args)
        {
            try
            {
                Console.SetBufferSize(200, 1000);

                #region Console Text
                Console.WriteLine(" >>> Crypto Stock Exchanges console >>> ");
                Console.WriteLine("");
                Console.WriteLine("Set current Api-Key: \"key key-string\"");
                Console.WriteLine("Set current Api-Secret: \"secret secret-string\"");
                Console.WriteLine("Format of api-request: \"apiName method endpoint parameters\"");
                Console.WriteLine("Launch thread example: \"cycle\"");
                Console.WriteLine("Set nonce amendment: \"amendment IntValue\"");
                Console.WriteLine("");
                Console.WriteLine(" Examples: ");

                Console.WriteLine("binance GET /api/v3/ticker/price !symbol=BTCUSDT");
                Console.WriteLine("binance DELETE /api/v3/order symbol=ETHUSDT&orderId=1");
                Console.WriteLine("binance GET /api/v1/depth !symbol=ETHUSDT&limit=50");
                Console.WriteLine("binance POST /api/v3/order symbol=ETHUSDT&timeInForce=GTC&side=BUY&type=LIMIT&quantity=1&price=1");

                Console.WriteLine("gate GET 1/orderBook/eth_usdt");
                Console.WriteLine("gate POST 1/private/buy currencyPair=eth_usdt&amount=1&rate=1");
                Console.WriteLine("gate POST 1/private/balances");

                Console.WriteLine("huobi GET /market/trade symbol=btcusdt");
                Console.WriteLine("huobi GET /v1/order/orders symbol=ethusdt&states=filled");

                Console.WriteLine("kucoin GET /v1/open/currencies");
                Console.WriteLine("kucoin GET /v1/account/USDT/balance");
                Console.WriteLine("kucoin POST /v1/order?symbol=ETH-USDT amount=1&price=1&type=BUY");

                Console.WriteLine("hitbtc GET /api/2/public/orderbook/BTCUSD?limit=5");
                Console.WriteLine("hitbtc AUTH-GET /api/2/trading/balance");
                Console.WriteLine("hitbtc AUTH-POST /api/2/order {\"symbol\":\"ethbtc\",\"side\":\"sell\",\"quantity\":0.063,\"price\":0.046016}");

                Console.WriteLine("");
                Console.WriteLine("Enter empty string for exit");
                #endregion

                string line;

                // Set your api-key & api-secret here (for signature-type requests) or use console
                string key    = String.Empty;
                string secret = String.Empty;

                string response = String.Empty;
                Int64  noncAm   = 0;

                do
                {
                    line = Console.ReadLine();
                    var parts = line.Trim(new char[] { '\t', ' ' }).Split(' ');
                    parts[0] = parts[0].ToLower();
                    string content = parts.buildString(" ", 1);
                    switch (parts[0])
                    {
                    case "amendment":
                        noncAm = Convert.ToInt64(content);
                        break;

                    case "cycle":
                        exampleThread          = new Thread(exampleThreadLoop);
                        exampleThread.Priority = ThreadPriority.Highest;
                        exampleThread.Start();
                        break;

                    case "key":
                        key = content;
                        break;

                    case "secret":
                        secret = content;
                        break;

                    case "binance":
                        using (var binance = new Binance(key, secret))
                        {
                            binance.OnResponseReceived += Api_OnResponseReceived;
                            binance.nonceAmendment      = noncAm;
                            binance.sendReq(content);
                        }
                        break;

                    case "gate":
                        using (var gate = new Gate(key, secret))
                        {
                            gate.OnResponseReceived += Api_OnResponseReceived;
                            gate.sendReq(content);
                        }
                        break;

                    case "huobi":
                        using (var huobi = new Huobi(key, secret))
                        {
                            huobi.OnResponseReceived += Api_OnResponseReceived;
                            huobi.sendReq(content);
                        }
                        break;

                    case "kucoin":
                        using (var kucoin = new Kucoin(key, secret))
                        {
                            kucoin.OnResponseReceived += Api_OnResponseReceived;
                            kucoin.nonceAmendment      = noncAm;
                            kucoin.sendReq(content);
                        }
                        break;

                    case "hitbtc":
                        using (var hitbtc = new Hitbtc(key, secret))
                        {
                            hitbtc.OnResponseReceived += Api_OnResponseReceived;
                            hitbtc.sendReq(content);
                        }
                        break;

                    default:
                        Console.WriteLine("Wrong command");
                        break;
                    }
                } while (line.Length > 0);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
                Console.ReadLine();
            }
        }