I wrote a spagetti code like this but its too slow, even in working a good server. There are lots of if conditions to make processes true. For example,
if (ticker.PairSymbol == "BTCTRY") { btctryA = ticker.Ask; btctryB = ticker.Bid; }
if (ticker.PairSymbol == "DASHTRY") { dashtryA = ticker.Ask; dashtryB = ticker.Bid; }
if (ticker.PairSymbol == "EOSTRY"){ eostryA = ticker.Ask; eostryB = ticker.Bid;}
if (ticker.PairSymbol == "ETHTRY") { ethtryA = ticker.Ask; ethtryB = ticker.Bid; }
if (ticker.PairSymbol == "LINKTRY"){ linktryA = ticker.Ask; linktryB = ticker.Bid; }
if (ticker.PairSymbol == "LTCTRY") { ltctryA = ticker.Ask; ltctryB = ticker.Bid; }
if (ticker.PairSymbol == "NEOTRY") { neotryA = ticker.Ask; neotryB = ticker.Bid; }
if (ticker.PairSymbol == "USDTTRY") { usdttryA = ticker.Ask; usdttryB = ticker.Bid; }
if (ticker.PairSymbol == "XLMTRY") { xlmtryA = ticker.Ask; xlmtryB = ticker.Bid; }
if (ticker.PairSymbol == "XRPTRY") { xrptryA = ticker.Ask; xrptryB = ticker.Bid; }
if (ticker.PairSymbol == "ATOMTRY") { atomtryA = ticker.Ask; atomtryB = ticker.Bid; }
if (ticker.PairSymbol == "XTZTRY") { xtztryA = ticker.Ask; xtztryB = ticker.Bid; }
if (ticker.PairSymbol == "BTCUSDT") { btcusdtA = ticker.Ask; btcusdtB = ticker.Bid;
Console.ForegroundColor = ConsoleColor.Red;
string timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture);
Console.WriteLine($" {timestamp}"); }
if (ticker.PairSymbol == "DASHUSDT") { dashusdtA = ticker.Ask; dashusdtB = ticker.Bid; }
if (ticker.PairSymbol == "EOSUSDT") { eosusdtA = ticker.Ask; eosusdtB = ticker.Bid; }
if (ticker.PairSymbol == "ETHUSDT") { ethusdtA = ticker.Ask; ethusdtB = ticker.Bid;}
if (ticker.PairSymbol == "LINKUSDT") { linkusdtA = ticker.Ask; linkusdtB = ticker.Bid;}
if (ticker.PairSymbol == "LTCUSDT"){ ltcusdtA = ticker.Ask; ltcusdtB = ticker.Bid; }
if (ticker.PairSymbol == "NEOUSDT"){ neousdtA = ticker.Ask; neousdtB = ticker.Bid; }
if (ticker.PairSymbol == "XLMUSDT"){ xlmusdtA = ticker.Ask; xlmusdtB = ticker.Bid; }
if (ticker.PairSymbol == "XRPUSDT"){ xrpusdtA = ticker.Ask; xrpusdtB = ticker.Bid;}
if (ticker.PairSymbol == "XTZUSDT"){ xtzusdtA = ticker.Ask; xtzusdtB = ticker.Bid;}
if (ticker.PairSymbol == "ATOMUSDT"){ atomusdtA = ticker.Ask; atomusdtB = ticker.Bid; }
if (ticker.PairSymbol == "DASHBTC") { dashbtcA = ticker.Ask; dashbtcB = ticker.Bid; }
if (ticker.PairSymbol == "EOSBTC") { eosbtcA = ticker.Ask; eosbtcB = ticker.Bid;}
if (ticker.PairSymbol == "ETHBTC") { ethbtcA = ticker.Ask; ethbtcB = ticker.Bid;}
if (ticker.PairSymbol == "LINKBTC"){ linkbtcA = ticker.Ask; linkbtcB = ticker.Bid;}
if (ticker.PairSymbol == "LTCBTC"){ ltcbtcA = ticker.Ask; ltcbtcB = ticker.Bid;}
if (ticker.PairSymbol == "NEOBTC") { neobtcA = ticker.Ask; neobtcB = ticker.Bid; }
if (ticker.PairSymbol == "XLMBTC"){ xlmbtcA = ticker.Ask; xlmbtcB = ticker.Bid;}
if (ticker.PairSymbol == "XRPBTC") { xrpbtcA = ticker.Ask; xrpbtcB = ticker.Bid;}
if (ticker.PairSymbol == "XTZBTC"){ xtzbtcA = ticker.Ask; xtzbtcB = ticker.Bid;}
if (ticker.PairSymbol == "ATOMBTC"){ atombtcA = ticker.Ask; atombtcB = ticker.Bid; }
and like this
if (data.PairSymbol == "BTCTRY") { oldbtctryA = btctryAa; btctryAa = data.Asks[0].Amount; oldbtctryB = btctryBb; btctryBb = data.Bids[0].Amount; }
if (data.PairSymbol == "DASHTRY") { olddashtryA = dashtryAa; dashtryAa = data.Asks[0].Amount; olddashtryB = dashtryBb; dashtryBb = data.Bids[0].Amount; }
if (data.PairSymbol == "EOSTRY") { oldeostryA = eostryAa; eostryAa = data.Asks[0].Amount; oldeostryB = eostryBb; eostryBb = data.Bids[0].Amount; }
if (data.PairSymbol == "ETHTRY") { oldethtryA = ethtryAa; ethtryAa = data.Asks[0].Amount; oldethtryB = ethtryBb; ethtryBb = data.Bids[0].Amount; }
if (data.PairSymbol == "LINKTRY") { oldlinktryA = linktryAa; linktryAa = data.Asks[0].Amount; oldlinktryB = linktryBb; linktryBb = data.Bids[0].Amount; }
if (data.PairSymbol == "LTCTRY") { oldltctryA = ltctryAa; ltctryAa = data.Asks[0].Amount; oldltctryB = ltctryBb; ltctryBb = data.Bids[0].Amount; }
if (data.PairSymbol == "NEOTRY") { oldneotryA = neotryAa; neotryAa = data.Asks[0].Amount; oldneotryB = neotryBb; neotryBb = data.Bids[0].Amount; }
if (data.PairSymbol == "USDTTRY") { oldusdttryA = usdttryAa; usdttryAa = data.Asks[0].Amount; oldusdttryB = usdttryBb; usdttryBb = data.Bids[0].Amount; }
if (data.PairSymbol == "XLMTRY") { oldxlmtryA = xlmtryAa; xlmtryAa = data.Asks[0].Amount; oldxlmtryB = xlmtryBb; xlmtryBb = data.Bids[0].Amount; }
if (data.PairSymbol == "XRPTRY") { oldxrptryA = xrptryAa; xrptryAa = data.Asks[0].Amount; oldxrptryB = xrptryBb; xrptryBb = data.Bids[0].Amount; }
if (data.PairSymbol == "ATOMTRY") { oldatomtryA = atomtryAa; atomtryAa = data.Asks[0].Amount; oldatomtryB = atomtryBb; atomtryBb = data.Bids[0].Amount; }
if (data.PairSymbol == "XTZTRY") { oldxtztryA = xtztryAa; xtztryAa = data.Asks[0].Amount; oldxtztryB = xtztryBb; xtztryBb = data.Bids[0].Amount; }
if (data.PairSymbol == "BTCUSDT") { oldbtcusdtA = btcusdtA; btcusdtAa = data.Asks[0].Amount; oldbtcusdtB = btcusdtBb; btcusdtBb = data.Bids[0].Amount; }
if (data.PairSymbol == "DASHUSDT") { olddashusdtA = dashusdtA; dashusdtAa = data.Asks[0].Amount; olddashusdtB = dashusdtBb; dashusdtBb = data.Bids[0].Amount; }
if (data.PairSymbol == "EOSUSDT") { oldeosusdtA = eosusdtAa; eosusdtAa = data.Asks[0].Amount; oldeosusdtB = eosusdtBb; eosusdtBb = data.Bids[0].Amount; }
if (data.PairSymbol == "ETHUSDT") { oldethusdtA = ethusdtAa; ethusdtAa = data.Asks[0].Amount; oldethusdtB = ethusdtBb; ethusdtBb = data.Bids[0].Amount; }
if (data.PairSymbol == "LINKUSDT") { oldlinkusdtA = linkusdtAa; linkusdtAa = data.Asks[0].Amount; oldlinkusdtB = linkusdtBb; linkusdtBb = data.Bids[0].Amount; }
if (data.PairSymbol == "LTCUSDT") { oldltcusdtA = ltcusdtAa; ltcusdtAa = data.Asks[0].Amount; oldltcusdtB = ltcusdtBb; ltcusdtBb = data.Bids[0].Amount; }
if (data.PairSymbol == "NEOUSDT") { oldneousdtA = neousdtAa; neousdtAa = data.Asks[0].Amount; oldneousdtB = neousdtBb; neousdtBb = data.Bids[0].Amount; }
if (data.PairSymbol == "XLMUSDT") { oldxlmusdtA = xlmusdtAa; xlmusdtAa = data.Asks[0].Amount; oldxlmusdtB = xlmusdtBb; xlmusdtBb = data.Bids[0].Amount; }
if (data.PairSymbol == "XRPUSDT") { oldxrpusdtA = xrpusdtAa; xrpusdtAa = data.Asks[0].Amount; oldxrpusdtB = xrpusdtBb; xrpusdtBb = data.Bids[0].Amount; }
if (data.PairSymbol == "XTZUSDT") { oldxtzusdtA = xtzusdtAa; xtzusdtAa = data.Asks[0].Amount; oldxtzusdtB = xtzusdtBb; xtzusdtBb = data.Bids[0].Amount; }
if (data.PairSymbol == "ATOMUSDT") { oldatomusdtA = atomusdtAa; atomusdtAa = data.Asks[0].Amount; oldatomusdtB = atomusdtBb; atomusdtBb = data.Bids[0].Amount; }
if (data.PairSymbol == "DASHBTC") { olddashbtcA = dashbtcAa; dashbtcAa = data.Asks[0].Amount; olddashbtcB = dashbtcBb; dashbtcBb = data.Bids[0].Amount; }
if (data.PairSymbol == "EOSBTC") { oldeosbtcA = eosbtcAa; eosbtcAa = data.Asks[0].Amount; oldeosbtcB = eosbtcBb; eosbtcBb = data.Bids[0].Amount; }
if (data.PairSymbol == "ETHBTC") { oldethbtcA = ethbtcAa; ethbtcAa = data.Asks[0].Amount; oldethbtcB = ethbtcBb; ethbtcBb = data.Bids[0].Amount; }
if (data.PairSymbol == "LINKBTC") { oldlinkbtcA = linkbtcAa; linkbtcAa = data.Asks[0].Amount; oldlinkbtcB = linkbtcBb; linkbtcBb = data.Bids[0].Amount; }
if (data.PairSymbol == "LTCBTC") { oldltcbtcA = ltcbtcAa; ltcbtcAa = data.Asks[0].Amount; oldltcbtcB = ltcbtcBb; ltcbtcBb = data.Bids[0].Amount; }
if (data.PairSymbol == "NEOBTC") { oldneobtcA = neobtcAa; neobtcAa = data.Asks[0].Amount; oldneobtcB = neobtcBb; neobtcBb = data.Bids[0].Amount; }
if (data.PairSymbol == "XLMBTC") { oldxlmbtcA = xlmbtcAa; xlmbtcAa = data.Asks[0].Amount; oldxlmbtcB = xlmbtcBb; xlmbtcBb = data.Bids[0].Amount; }
if (data.PairSymbol == "XRPBTC") { oldxrpbtcA = xrpbtcAa; xrpbtcAa = data.Asks[0].Amount; oldxrpbtcB = xrpbtcBb; xrpbtcBb = data.Bids[0].Amount; }
if (data.PairSymbol == "XTZBTC") { oldxtzbtcA = xtzbtcAa; xtzbtcAa = data.Asks[0].Amount; oldxtzbtcB = xtzbtcBb; xtzbtcBb = data.Bids[0].Amount; }
if (data.PairSymbol == "ATOMBTC") { oldatombtcA = atombtcAa; atombtcAa = data.Asks[0].Amount; oldatombtcB = atombtcBb; atombtcBb = data.Bids[0].Amount; }
How can i pass this conditions in a fastest way.They are inside of loops, and variables changing via websocket. I know C# is not fast as C++ and C. But have to make on C#, any help appreciated.
Aucun commentaire:
Enregistrer un commentaire