0% found this document useful (0 votes)
17 views2 pages

Price Comparison for SOPH_USDT

The document is a C# program that connects to two cryptocurrency exchanges, MEXC and Gate.io, to retrieve and compare the prices of a specific trading pair (SOPH_USDT). It uses WebSockets to subscribe to price updates and calculates the price spread between the two exchanges. The program continuously updates and displays the prices and the spread percentage in the console.

Uploaded by

Jeka Klu
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views2 pages

Price Comparison for SOPH_USDT

The document is a C# program that connects to two cryptocurrency exchanges, MEXC and Gate.io, to retrieve and compare the prices of a specific trading pair (SOPH_USDT). It uses WebSockets to subscribe to price updates and calculates the price spread between the two exchanges. The program continuously updates and displays the prices and the spread percentage in the console.

Uploaded by

Jeka Klu
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

using System;

using [Link];
using [Link];
using [Link];
using [Link];
using [Link];

class Program
{
static decimal? mexcPrice = null;
static decimal? gatePrice = null;

static async Task Main()


{
var mexcTask = ConnectToMexc("SOPH_USDT");
var gateTask = ConnectToGate("SOPH_USDT");

await [Link](mexcTask, gateTask);


}

static async Task ConnectToMexc(string _symbol)


{
var ws = new ClientWebSocket();
await [Link](new Uri("[Link]
[Link]);

string subscribeMessage = [Link](new


{
method = "[Link]",
param = new { symbol = _symbol }
});

await [Link]([Link](subscribeMessage),
[Link], true, [Link]);

var buffer = new byte[4096];


while (true)
{
var result = await [Link](new ArraySegment<byte>(buffer),
[Link]);
var json = [Link](buffer, 0, [Link]);

using var doc = [Link](json);


if ([Link]("data", out var data))
{
if ([Link]("lastPrice"))
if ([Link]("lastPrice", out var priceEl))
{
mexcPrice = [Link]();
PrintSpread();
}
}
}
}

static async Task ConnectToGate(string symbol)


{
var ws = new ClientWebSocket();
await [Link](new Uri("[Link]
[Link]);

string subscribeMessage = [Link](new


{
time = [Link](),
channel = "[Link]",
@event = "subscribe",
payload = new[] { symbol }
});

await [Link]([Link](subscribeMessage),
[Link], true, [Link]);

var buffer = new byte[4096];


while (true)
{
var result = await [Link](new ArraySegment<byte>(buffer),
[Link]);
var json = [Link](buffer, 0, [Link]);

using var doc = [Link](json);


if ([Link]("result", out var resultEl))
{
if ([Link]("mark_price"))
{
var ststt =
[Link](json).[Link]("result")
[0].GetProperty("last").GetString();
var last = [Link]([Link](".", ","));
gatePrice = last;
PrintSpread();
}
}
}
}

static void PrintSpread()


{
if ([Link] && [Link])
{
var avg = ([Link] + [Link]) / 2m;
var diff = [Link]([Link] - [Link]);
var spreadPercent = diff / avg * 100m;

[Link]();
[Link]($"MEXC Price: {mexcPrice:F2}");
[Link]($"Gate Price: {gatePrice:F2}");
[Link]($"Spread: {spreadPercent:F4}%");
}
}
}

You might also like