Merhaba,
Sanal para kütüphanecim ile biraz uğraşıyorum bu aralar. Şu anda web socketlerini eklemeye çalışıyorum.
short InitSocket(CallBack)( string name, string txName, string streamName, CallBack )
{
import std.uni : toLower;
string uniqStreamName = name.toLower() ~ txName.toLower() ~ "@" ~ streamName;
if ( uniqStreamName in sockets )
{
writeln( "Socket with unique name: ", uniqStreamName, " was already existed will return" );
return -1;
}
auto ws_url = URL("wss://stream.binance.com:9443/ws/" ~ uniqStreamName);
auto ws = connectWebSocket(ws_url);
if ( !ws.connected )
return -1;
sockets[uniqStreamName] = ws;
while (ws.waitForData())
{
try
{
Json result = parseJsonString(ws.receiveText);
callBackfunction(result);
}
catch ( std.json.JSONException e )
{
writeln("Exception was caught while making the binance socket call: ", e);
continue;
}
}
CloseSocket(name.toLower(), txName.toLower(), streamName);
writeln( "Socket will be closed reason was: ", ws.closeReason );
return ws.closeCode;
}
bool CloseSocket( string name, string txName, string streamName )
{
string uniqStreamName = name ~ txName ~ "@" ~ streamName;
return sockets.remove(uniqStreamName);
}
unittest
{
import vibe.core.sync;
import vibe.core.concurrency;
import vibe.core.core;
writeln( "***** BinanceHelper Tests *****" );
auto helper = new BinanceHelper();
void testFoo( Json json )
{
writeln(json);
}
// helper.InitSocket( "iota", "btc", "aggTrade", &testFoo ) Bu güzel çalışıyor fakat blokluyor başka hiç birşey yapamıyorum.
// Bloklanmamak için vibe'ın fiberlarını kullanmaya çalışıyorum.
vibe.core.concurrency.async( helper.InitSocket, "iota", "btc", "aggTrade", &testFoo );
//helper.CloseSocket( "eth", "btc", "aggTrade");
}
Yukarda yazdığım InitSocket dediğim method çalışıyor. Fakat bloklanıyorum yani başka bir iş yapamıyorum. Bu neden bu methodu vibe 'ın fiberleri ile derlemeye çalışıyorum fakat derleyemedim.
Error: cannot resolve type for helper.InitSocket(CallBack)(string name, string txName, string streamName, CallBack)
Bir fikriniz var mı acaba cağrıyı nasıl yapmam gerektiğini.
<https://github.com/kerdemdemir/DCryptoWrapper/blob/master/source/Client/ClientHelper/BinanceHelper.d
>Erdemdem
--
[ Bu gönderi, http://ddili.org/forum'dan dönüştürülmüştür. ]
Permalink
Reply