Пример #1
0
        public OrderManager()
        {
            Console.Title = "AbacasX Exchange Service";

            _exchangeBook = new ExchangeBook();

            _exchangeBook.NotifyOrderAdded      = NotifyOrderLegAdded;
            _exchangeBook.NotifyOrderLegMatched = NotifyOrderLegMatched;
            _exchangeBook.NotifyOrderLegFilled  = NotifyOrderLegFilled;

            var tokenRateList = _exchangeBook.rateServiceClient.GetTokenRateList();

            for (int i = 0; i < tokenRateList.Count(); i++)
            {
                TokenRates.TryAdd(tokenRateList[i].TokenId, tokenRateList[i]);
            }

            var result = CreateKeyPair();

            KeyPairData KeyPair = new KeyPairData();

            KeyPair.privateKey = result.Item1;
            KeyPair.publicKey  = result.Item2;

            KeyPairs.TryAdd(0, KeyPair);

            result = CreateKeyPair();

            KeyPair.privateKey = result.Item1;
            KeyPair.publicKey  = result.Item2;

            KeyPairs.TryAdd(1, KeyPair);

            _timer = new Timer(FillOpenOrders, null, _updateInterval, _updateInterval);
        }
Пример #2
0
        public string GenerateNewClientKey(int ClientId)
        {
            KeyPairData KeyPair;

            if (KeyPairs.TryGetValue(ClientId, out KeyPair) == true)
            {
                return(KeyPair.publicKey);
            }
            else
            {
                var result = CreateKeyPair();
                KeyPair            = new KeyPairData();
                KeyPair.privateKey = result.Item1;
                KeyPair.publicKey  = result.Item2;
                KeyPairs.TryAdd(ClientId, KeyPair);
                return(KeyPair.publicKey);
            }
        }
Пример #3
0
        private void addTransferToBlockChain(AssetTransferData transferRequest)
        {
            BlockChainData blockChainRecord = new BlockChainData();
            KeyPairData    KeyPair          = new KeyPairData();

            lock (BlockChainTransactionsLock)
            {
                blockChainRecord = new BlockChainData();

                blockChainRecord.Date        = DateTime.Now.ToShortDateString();
                blockChainRecord.BlockNumber = blockCount++;
                blockChainRecord.OrderId     = orderCount++;
                blockChainRecord.clientId    = transferRequest.clientId;

                if (transferRequest.transferType == TransferTypeEnum.Deposit)
                {
                    blockChainRecord.PayReceive  = "Receive";
                    blockChainRecord.TokenAmount = transferRequest.tokenAmount;
                    blockChainRecord.TokenId     = transferRequest.tokenId;
                }
                else
                {
                    blockChainRecord.PayReceive  = "Pay";
                    blockChainRecord.TokenAmount = transferRequest.tokenAmount;
                    blockChainRecord.TokenId     = transferRequest.tokenId;
                }

                if (KeyPairs.TryGetValue(1, out KeyPair) == true)
                {
                    blockChainRecord.Address = KeyPair.publicKey;
                }

                blockChainRecord.TransactionHash = HashOrder(blockChainRecord);
                BlockChainTransactions.TryAdd(blockChainRecord.BlockNumber, blockChainRecord);
            }
        }
Пример #4
0
        private void UpdateBlockChain(OrderLeg orderLegRecord, OrderFilledData orderFilledData)
        {
            BlockChainData blockChainRecord = new BlockChainData();
            KeyPairData    KeyPair          = new KeyPairData();

            //Console.WriteLine("Writing Order Flows to blockchain");

            lock (BlockChainTransactionsLock)
            {
                if (orderLegRecord.BuySellType == OrderLegBuySellEnum.Buy)
                {
                    blockChainRecord = new BlockChainData();

                    blockChainRecord.clientId = orderLegRecord.Order.ClientId;

                    blockChainRecord.Date        = orderFilledData.FilledDateTime.ToShortDateString();
                    blockChainRecord.BlockNumber = blockCount++;
                    blockChainRecord.OrderId     = orderLegRecord.OrderId;
                    blockChainRecord.PayReceive  = "Receive";
                    blockChainRecord.TokenAmount = orderFilledData.Token1Amount;
                    blockChainRecord.TokenId     = orderFilledData.Token1Id;

                    if (KeyPairs.TryGetValue(1, out KeyPair) == true)
                    {
                        blockChainRecord.Address = KeyPair.publicKey;
                    }
                    else
                    {
                        //blockChainRecord.Address = GenerateNewClientKey(orderLegRecord.Order.ClientId);
                    }

                    blockChainRecord.TransactionHash = HashOrder(blockChainRecord);
                    BlockChainTransactions.TryAdd(blockChainRecord.BlockNumber, blockChainRecord);


                    blockChainRecord             = new BlockChainData();
                    blockChainRecord.clientId    = orderLegRecord.Order.ClientId;
                    blockChainRecord.Date        = DateTime.Now.ToShortDateString();
                    blockChainRecord.BlockNumber = blockCount++;
                    blockChainRecord.OrderId     = orderFilledData.OrderLegId;
                    blockChainRecord.PayReceive  = "Pay";
                    blockChainRecord.TokenAmount = orderFilledData.Token2Amount;
                    blockChainRecord.TokenId     = orderFilledData.Token2Id;

                    if (KeyPairs.TryGetValue(0, out KeyPair) == true)
                    {
                        blockChainRecord.Address = KeyPair.publicKey;
                    }
                    else
                    {
                        //blockChainRecord.Address = GenerateNewClientKey(orderLegRecord.Order.ClientId);
                    }

                    blockChainRecord.TransactionHash = HashOrder(blockChainRecord);
                    BlockChainTransactions.TryAdd(blockChainRecord.BlockNumber, blockChainRecord);
                }
                else
                {
                    blockChainRecord      = new BlockChainData();
                    blockChainRecord.Date = DateTime.Now.ToShortDateString();

                    blockChainRecord.clientId    = orderLegRecord.Order.ClientId;
                    blockChainRecord.BlockNumber = blockCount++;
                    blockChainRecord.OrderId     = orderLegRecord.OrderId;
                    blockChainRecord.PayReceive  = "Pay";
                    blockChainRecord.TokenAmount = orderFilledData.Token1Amount;
                    blockChainRecord.TokenId     = orderFilledData.Token1Id;

                    if (KeyPairs.TryGetValue(0, out KeyPair) == true)
                    {
                        blockChainRecord.Address = KeyPair.publicKey;
                    }
                    else
                    {
                    }

                    blockChainRecord.TransactionHash = HashOrder(blockChainRecord);
                    BlockChainTransactions.TryAdd(blockChainRecord.BlockNumber, blockChainRecord);

                    blockChainRecord      = new BlockChainData();
                    blockChainRecord.Date = DateTime.Now.ToShortDateString();

                    blockChainRecord.clientId    = orderLegRecord.Order.ClientId;
                    blockChainRecord.BlockNumber = blockCount++;
                    blockChainRecord.OrderId     = orderLegRecord.OrderId;
                    blockChainRecord.PayReceive  = "Receive";
                    blockChainRecord.TokenAmount = orderFilledData.Token2Amount;
                    blockChainRecord.TokenId     = orderFilledData.Token2Id;
                    if (KeyPairs.TryGetValue(1, out KeyPair) == true)
                    {
                        blockChainRecord.Address = KeyPair.publicKey;
                    }
                    else
                    {
                    }

                    blockChainRecord.TransactionHash = HashOrder(blockChainRecord);
                    BlockChainTransactions.TryAdd(blockChainRecord.BlockNumber, blockChainRecord);
                }
            }
        }