Exemplo n.º 1
0
        public async void Start()
        {
            _client = new DeribitV2Client(DeribitEndpointType.Productive);
            await _client.Connect();

            // Create a time, to refresh data that do not have a subscription.
            _timer = new DispatcherTimer {
                Interval = TimeSpan.FromMilliseconds(_updateInterval)
            };
            _timer.Tick += HandleTimerTick;
            _timer.Start();
            SubscribeSpot();
            SubscribeVolatility();
            FutureInstruments();
        }
Exemplo n.º 2
0
        public static async Task <int> Main(string[] args)
        {
            Console.CancelKeyPress += Console_CancelKeyPress;
            Console.Title           = "Deribit Development Playground";

            var confRoot = new ConfigurationBuilder()
                           //.SetBasePath(Directory.GetCurrentDirectory())
                           //.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                           .AddUserSecrets(Assembly.GetExecutingAssembly(), false, false)
                           .Build();

            var apiSettings = confRoot.GetSection("api_master");

            var clientId     = apiSettings["ClientId"];
            var clientSecret = apiSettings["ClientSecret"];

            const string logFilePath = @"D:\Temp\Serilog\test-log-.txt";

            Directory.CreateDirectory(Path.GetDirectoryName(logFilePath));

            //const string outputTemplateLongLevelName = "{Timestamp:yyyy-MM-dd HH:mm:ss.fffffff} [{Level,-11:u}] {Message:lj}{NewLine}{Exception}";
            const string outputTemplateShortLevelName = "{Timestamp:yyyy-MM-dd HH:mm:ss.fffffff} [{Level:u3}] {Message:lj}{NewLine}{Exception}";

            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Verbose()
                         //.WriteTo.Async(l => l.Trace(outputTemplate: outputTemplateShortLevelName))
                         .WriteTo.Async(l => l.Console(outputTemplate: outputTemplateShortLevelName, restrictedToMinimumLevel: LogEventLevel.Debug))
                         //.WriteTo.Async(l => l.File(logFilePath, rollingInterval: RollingInterval.Day, restrictedToMinimumLevel: LogEventLevel.Verbose))
                         .Destructure.ByTransforming <JsonRpcRequest>(JsonConvert.SerializeObject)
                         .Destructure.ByTransforming <JsonRpcResponse>(JsonConvert.SerializeObject)
                         .Destructure.ByTransforming <Notification>(JsonConvert.SerializeObject)
                         .Destructure.ByTransforming <Heartbeat>(JsonConvert.SerializeObject)
                         .CreateLogger();

            _client               = new DeribitV2Client(DeribitEndpointType.Testnet);
            _client.Connected    += OnConnected;
            _client.Disconnected += OnDisconnected;

            while (_client.State != WebSocketState.Open)
            {
                Log.Logger.Debug("SocketState: {State}", _client.State);
                try
                {
                    await _client.Connect();

                    var sig      = CryptoHelper.CreateSignature(clientSecret);
                    var loginRes = await _client.PublicAuth(new AuthParams { GrantType = GrantType.Signature, ClientId = clientId, Signature = sig });

                    var subToken = await _client.SubscribeBookChange(new BookChangeSubscriptionParams { InstrumentName = "BTC-PERPETUAL", Interval = "100ms" }, o =>
                    {
                        Log.Logger.Information($"HandleNotification: {o}");
                    });

                    var blub = 4;
                }
                catch (Exception ex)
                {
                    Log.Logger.Error(ex, "Error");
                    _client.PrivateLogout();
                    break;
                }

                DisconnectResetEvent.Wait();

                if (_client.CloseStatus == WebSocketCloseStatus.NormalClosure)
                {
                    Log.Logger.Information("Closed by client. Do not reconnect.");
                    break;
                }

                if (_client.Error != null)
                {
                    Log.Logger.Information("Closed by internal error. Reconnect in 5s");
                    Thread.Sleep(5000);
                }
                else
                {
                    Log.Logger.Information("Closed by host. Reconnect in 5s");
                    Thread.Sleep(5000);
                }
            }

            Log.Logger.Information("");
            Log.Logger.Information("");
            Log.Logger.Information("");
            Log.Logger.Information("Drücksch du Taschtä für fertig ...");
            Console.ReadKey();

            return(0);
        }