Exemplo n.º 1
0
        public BitfinexService()
        {
            string uri = "wss://api.bitfinex.com/ws";
            //websocket bitfinex
            //BitfinexOrderSend bitstampOrderSend = new BitfinexOrderSend
            //{
            //    Event = "subscribe",
            //    Channel = "book",
            //    Pair = "BTCUSD",
            //    Prec = "P0",
            //    Freq = "F0"
            //};
            //BitfinexOrdersrWS bitfinexOrdersrWS = new BitfinexOrdersrWS(bitstampOrderSend);

            BitfinexSubscribeTicker asset = new BitfinexSubscribeTicker
            {
                channel = "ticker",
                Event   = "subscribe",
                symbol  = "tBTCUSD"
            };

            ws              = new WebSocketApi();
            ws.TickerEvent += GetRatesFromService;
            ws.WebSocketSubscribe(uri, asset);
        }
Exemplo n.º 2
0
        public GdaxService()
        {
            string uri = "wss://ws-feed.gdax.com";
            GdaxSubscribeTicker gdaxSubscribeTicker = new GdaxSubscribeTicker
            {
                Type       = "subscribe",
                ProductIds = new string[] {
                    "BTC-USD"
                },
                Channels = new object[]
                {
                    new channels
                    {
                        name        = "ticker",
                        product_ids = new string[]
                        {
                            "BTC-USD"
                        }
                    }
                }
            };

            ws              = new WebSocketApi();
            ws.TickerEvent += GetRatesFromService;
            ws.WebSocketSubscribe(uri, gdaxSubscribeTicker);
        }
Exemplo n.º 3
0
        private FriendService(WebSocketApi webSocket, ILogger logger)
        {
            _webSocket = webSocket;
            _logger    = logger;

            _updateTimer = new Timer(new TimerCallback((o) => UpdateFriendList()), null, UpdateIntervalInMs, UpdateIntervalInMs);
        }
Exemplo n.º 4
0
        public WebSocketAdminTestsSetup()
        {
            var address         = new Uri("ws://localhost:" + this.WsPort);
            var clientWebSocket = new ClientWebSocket();

            clientWebSocket.ConnectAsync(address, CancellationToken.None).Wait();
            SocketApi = new WebSocketApi(clientWebSocket);
        }
Exemplo n.º 5
0
        public static void Test()
        {
/*
 *                      // Sell
 *                      {
 *                              var priceUsd = 245 * 99999;
 *                              var CIY2USD = 0.1611;
 *
 *                              var client1 = new OKCoinAPI(ApiKey, ApiSecret);
 *                              var responce = client1.PlaceOrder((double)(priceUsd / CIY2USD), -(double)2.5,
 *                                      OKCoinAPI.MarketType.BTCCNY);
 *                              Console.WriteLine(responce);
 *                      }
 */


            using (var wsApi = new WebSocketApi())
            {
                wsApi.OrdersDepthReceived += OnOrdersDepth;
                wsApi.Start();
                Console.ReadLine();
                wsApi.Stop();
            }

            var ticker = OKCoinAPI.GetTicker();

            Console.WriteLine("ticker.Last: " + ticker.Last);

            var orderBook = OKCoinAPI.GetOrderBook(33);

            Console.WriteLine("orderBook.Asks.Count=" + orderBook.Asks.Count);

            var client = new OKCoinAPI(ApiKey, ApiSecret);

            var info = client.GetUserInfo();

            Console.WriteLine("FreeBtc= " + info.Free.Btc);

            var orderId = client.TradeSell(300, 0.08M);

            Console.WriteLine("orderId: " + orderId);

            var orders = client.GetActiveOrders();

            Console.WriteLine("Active orders: " + orders.Count());

            var cancelResult = client.CancelOrder(orderId);

            Console.WriteLine("cancelResult: " + cancelResult);
        }
Exemplo n.º 6
0
 public WebSocketAdminTests(WebSocketAdminTestsSetup setup) : base(setup)
 {
     this.Api = setup.SocketApi;
 }
Exemplo n.º 7
0
        private static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var mutex = new Mutex(true, AppName, out bool createdNew);

            //Only one instance
            if (!createdNew)
            {
                MsgBox.ShowMessage(
                    $@"""Celeste Fan Project Launcher"" v{
                            Assembly.GetEntryAssembly()?.GetName().Version
                        } already running!", "Celeste Fan Project",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                return;
            }

            //
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

            //Load UserConfig
            try
            {
                if (File.Exists(UserConfigFilePath))
                {
                    UserConfig = UserConfig.Load(UserConfigFilePath);
                }
            }
            catch (Exception)
            {
                //
            }

            try
            {
                if (string.IsNullOrWhiteSpace(UserConfig.GameFilesPath))
                {
                    UserConfig.GameFilesPath = GameScannerManager.GetGameFilesRootPath();
                }
            }
            catch (Exception)
            {
                //
            }

            //Check if Steam Version
            try
            {
                UserConfig.IsSteamVersion = Assembly.GetEntryAssembly()?.Location
                                            .EndsWith("AOEOnline.exe", StringComparison.OrdinalIgnoreCase) ?? false;
            }
            catch (Exception)
            {
                //
            }

            //SslFix (invalid cert)
            InternetUtils.SslFix();

            //Init WebSocketApi
            WebSocketApi = new WebSocketApi(UserConfig.ServerUri);

            //Start Gui
            Application.Run(new MainForm());

            GC.KeepAlive(mutex);
        }
Exemplo n.º 8
0
        public static void Main(string[] args)
        {
            var clientId     = "4f11c777-3d31-468b-a099-5577438112ef";
            var clientSecret = "9316a61a51f27b6be744c39d348490b1f5cd56ab8ab9b939b3c4f806d296dbd7";
            var pinCode      = "491169";
            var sessionId    = "bda2c4ad-f1d3-4c56-998e-ac4e31af2d62";

            var pinToken =
                "hMr9RJqbYWXgYGrv0h8xzDJg1kQ1JRqrm+dwIyWrvJ8TQUsbR5iwS+iIc4g1H9G1eKwndi6D4SIddnOJJaI+EoX0GglT347gRBNNIckOfQnEA6BuOCoDIBCrBSWbXrUetaj5K6wtUrhN6m9ZvOolJiXlJZOmTAvs3AiLTDogBGU=";
            var privateKey = @"-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQCgJGu8uYH6p63W0WQxt7mxc8U3Sn9oyetp+gpd1FDkoCRR/kO2
bwai6RVtR+76HubanG2yHoigVqd5reIyOqn5+Ws71tEoTLv//2UH0j+1QSROryPk
8GwVoix03UImm8PN6ulebpquxdpuiN/eQDd+veVMeVkWFxDiZ9FaQb6UzwIDAQAB
AoGBAJhcDmSv2gowHiSTc1AaDIHYM3o3VqDL+z4ItnQu3AeolOWtk56uYxH70Hb4
SVWOsPSsf3FHu5VQ3GXYGazQQ4YWXY1SewL4BTQ15dYaxuxBDVQUfh08Tncega3x
Dhbvm0GZhur0azBPPKepMU8Uqviwoxe7ZxNm9X0mn1OutdiBAkEA+9BDJo6n2eLC
VNPIpY6uGS2gHRFbJsCAUo9OqOASWmdN4oQk3UNrkJngiU7KKMpga/l0zczbxasH
RDsJbcTrJQJBAKLN/6bU5+Z/dLxk6+AKqwYX1cfuNCYdrOgdELZWWmxhWznTgKpH
R7KreOMmsJwlycsCE9mJaHEGUthRsQIu1+MCQB0TI9281PacbxG6Tk2HVuTDVtxk
V6D20xo1P8DR9myHxv9jgJonobDVg453EXJ6Q33UFL96atm88J7ZLjKFbR0CQDXE
asYiUmQhe+AsRGo9m7XrcUMSPE7KRixyTO6rHjnk/UffvgJ+gANV9hqu0G0BXd+Z
1AxoAQIy4HFoqVjbN5kCQQCE732gDMW85Y0PSrMetwYOQFKY5bWUNqEJ6iQTFGay
2gmfqy4hCcbZAJL0vEROJ6XoUjQFQoUigmSRiKvWwpRk
-----END RSA PRIVATE KEY-----";

            var CNB_ASSET_ID = "965e5c6e-434c-3fa9-b780-c50f43cd955c";


            var ws = new WebSocketApi(clientId, sessionId, privateKey)
            {
                onCloseDelegate = (sender, eventArgs) => { Console.WriteLine("closed " + eventArgs.ToString()); },
                onErrorDelegate = (sender, eventArgs) => { Console.WriteLine("Error " + eventArgs.ToString()); }
            };

            ws.onMessageDelegate = (sender, eventArgs, message) =>
            {
                var data = JsonConvert.DeserializeObject <Message>(message);

                if (!string.IsNullOrEmpty(data.Error))
                {
                    Console.WriteLine($"Error occured: {data.Error}");
                    return;
                }

                string action = data.Action;

                var supportedOperations = new List <string>
                {
                    "ACKNOWLEDGE_MESSAGE_RECEIPT", "CREATE_MESSAGE", "LIST_PENDING_MESSAGES"
                };
                if (!supportedOperations.Contains(action))
                {
                    Console.WriteLine("Unknown Action");
                    return;
                }

                if (action == "ACKNOWLEDGE_MESSAGE_RECEIPT")
                {
                    return;
                }

                if (action == "CREATE_MESSAGE")
                {
                    var payload         = data.Data;
                    var messageId       = payload.MessageId;
                    var messageType     = payload.Type;
                    var messageCategory = payload.Category;
                    var userId          = payload.UserId;
                    var conversationId  = payload.ConversationId;
                    var payloadData     = payload.DataData;


                    string messageContent = ws.Base64Decode(payloadData);
                    ws.AckMessage(messageId);


                    if (messageCategory == "PLAIN_TEXT" && messageType == "message")
                    {
                        if (messageContent == "1")
                        {
                            ws.SendUserContactCard(conversationId, userId, clientId);
                        }
                        else if (messageContent == "2")
                        {
                            ws.SendUserAppButton(conversationId, userId, "https://google.com", "打开链接");
                        }
                        else if (messageContent == "3")
                        {
                            ws.SendUserPayAppButton(conversationId, userId, "打钱", CNB_ASSET_ID, "100");
                        }
                        else
                        {
                            ws.SendUserPlainText(conversationId, userId, "尝试发送数字 1 或者 2");
                        }
                    }
                }
            };
            ws.Run();
            Thread.Sleep(Timeout.Infinite);
        }
        public static void InitializeLegacyComponents()
        {
            Logger.Information("Initializing bootstrapper");
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // TODO: Move this to app.xaml.cs
            var mutex = new Mutex(true, AppName, out bool createdNew);

            //Only one instance
            if (!createdNew)
            {
                Logger.Information("Launcher is already started, will exit");
                GenericMessageDialog.Show(Properties.Resources.LauncherAlreadyRunningMessage, DialogIcon.Warning, DialogOptions.Ok);
                return;
            }

            //
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

            //Load UserConfig
            try
            {
                if (File.Exists(UserConfigFilePath))
                {
                    UserConfig = UserConfig.Load(UserConfigFilePath);
                    Logger.Information("User config loaded from {@Path}", UserConfigFilePath);
                }
                else
                {
                    Logger.Information("No user config loaded, path {@Path} does not exist", UserConfigFilePath);
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, ex.Message);
            }

            try
            {
                if (string.IsNullOrWhiteSpace(UserConfig.GameFilesPath))
                {
                    UserConfig.GameFilesPath = GameScannerManager.GetGameFilesRootPath();
                    Logger.Information("Game path set to {@Path}", UserConfigFilePath);
                }
                else
                {
                    Logger.Information("No game path is set");
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, ex.Message);
            }

            //Check if Steam Version
            try
            {
                UserConfig.IsSteamVersion = Assembly.GetEntryAssembly().Location
                                            .EndsWith("AOEOnline.exe", StringComparison.OrdinalIgnoreCase);

                Logger.Information("IsSteamVersion: {@IsSteamVersion}", UserConfig.IsSteamVersion);
            }
            catch (Exception ex)
            {
                Logger.Error(ex, ex.Message);
            }

            //Init WebSocketApi
            WebSocketApi = new WebSocketApi(UserConfig.ServerUri);
            Logger.Information("Initialized web socket");

            GC.KeepAlive(mutex);

            Logger.Information("Initializing fingerprint provider");
            FingerPrintProvider.Initialize();

            SetUILanguage();

            Logger.Information("Bootstrapper initialized");
        }
        public static void InitializeLegacyComponents()
        {
            if (!FileSystem.IsWritableDirectory(AppDomain.CurrentDomain.BaseDirectory))
            {
                MessageBox.Show(string.Format(Properties.Resources.InstallationPathForbidden, AppDomain.CurrentDomain.BaseDirectory), "Celeste Launcher", MessageBoxButtons.OK, MessageBoxIcon.Error);
                System.Windows.Application.Current.Shutdown();
                return;
            }

            Logger.Information("Initializing bootstrapper");
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // TODO: Move this to app.xaml.cs
            var mutex = new Mutex(true, AppName, out bool createdNew);

            //Only one instance
            if (!createdNew)
            {
                Logger.Information("Launcher is already started, will exit");
                GenericMessageDialog.Show(Properties.Resources.LauncherAlreadyRunningMessage, DialogIcon.Warning, DialogOptions.Ok);
                return;
            }

            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

            LoadUserConfig();

            try
            {
                if (string.IsNullOrWhiteSpace(UserConfig.GameFilesPath))
                {
                    UserConfig.GameFilesPath = GameScannerManager.GetGameFilesRootPath();
                    Logger.Information("Game path set to {@Path}", UserConfigFilePath);
                }
                else
                {
                    Logger.Information("No game path is set");
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, ex.Message);
            }

            //Check if Steam Version
            try
            {
                var isSteamVersion = Assembly.GetEntryAssembly().Location
                                     .EndsWith("AOEOnline.exe", StringComparison.OrdinalIgnoreCase);

                if (UserConfig.IsSteamVersion != isSteamVersion)
                {
                    UserConfig.IsSteamVersion = isSteamVersion;
                    UserConfig.Save(UserConfigFilePath);
                }

                Logger.Information("IsSteamVersion: {@IsSteamVersion}", UserConfig.IsSteamVersion);
            }
            catch (Exception ex)
            {
                Logger.Error(ex, ex.Message);
            }

            //Init WebSocketApi
            WebSocketApi = new WebSocketApi(UserConfig.ServerUri);
            Logger.Information("Initialized web socket");

            GC.KeepAlive(mutex);

            Logger.Information("Initializing fingerprint provider");
            FingerPrintProvider.Initialize();

            SetUILanguage();

            Logger.Information("Bootstrapper initialized");
        }