jkorf / coinex.net Goto Github PK
View Code? Open in Web Editor NEWA C# .netstandard client library for the CoinEx REST and Websocket Spot API focusing on clear usage and models
Home Page: https://jkorf.github.io/CoinEx.Net/
License: MIT License
A C# .netstandard client library for the CoinEx REST and Websocket Spot API focusing on clear usage and models
Home Page: https://jkorf.github.io/CoinEx.Net/
License: MIT License
Hello Jan,
Coinex Version 6.1.0 - 25 Feb 2024
In : CoinEx.Net.Objects.Sockets.Subscriptions.Orders
the class : internal class CoinExOrderSubscription
the method GetSubQuery(SocketConnection connection) builds a new object array around _symbols, therefore passing to the marketPlace Coinex an Array of Array as argument, instead of a simple array.
The log below illustrates this point :
[2024/02/26 18:07:42.201, (7, .)] INFO: 2024/02/26 18:07:42:201 | Trace | [Sckt 1] msg 6 - sending messsage: {"method":"order.subscribe","params":[["ZECUSDT"]],"id":5}
[2024/02/26 18:07:42.201, (7, .)] INFO: 2024/02/26 18:07:42:201 | Trace | [Sckt 1] msg 6 - Adding 58 bytes to send buffer
[2024/02/26 18:07:42.202, (10, .)] INFO: 2024/02/26 18:07:42:202 | Trace | [Sckt 1] msg 6 - sent 58 bytes
[2024/02/26 18:07:42.535, (14, .)] INFO: 2024/02/26 18:07:42:535 | Trace | [Sckt 1] received 78 bytes in single message
[2024/02/26 18:07:42.535, (14, .)] INFO: 2024/02/26 18:07:42:535 | Trace | [Sckt 1] 1 processor(s) matched to message with listener identifier 5
[2024/02/26 18:07:42.536, (10, .)] INFO: 2024/02/26 18:07:42:536 | Warning | [Sckt 1] failed to subscribe: [ServerError] 1: invalid argument
Kind Regards,
Philippe
Missing this Future: https://docs.coinex.com/api/v2/futures/market/http/list-market
I do not see this Future in API Coinex
Describe the bug
A clear and concise description of what the bug is.
--parameter source_id (number) misplaced with client_id (string)
To Reproduce
What endpoints and subscriptions are called.
--PlaceMarketOrderAsync
--/v1/order/market
Expected behavior
A clear and concise description of what you expected to happen.
--two different properties according to https://github.com/coinexcom/coinex_exchange_api/wiki/032market_order
client_id client_id is the custom id of order. Currently, it only supports uppercase and lowercase letters, numbers, hyphens and underlines, and it should be less than 32 bytes.
source_id user defines number and return
Debug logging
Add debug logging related to the issue. Enable Debug logging in the client options by settings LogVerbosity to Debug.
Hi M. Korf,
I was playing again with your API and would it be possible to change the object for the history to include the same information as the trade result or maybe put just the fees. That's what I need. I've changed my version to include the missing elements in the history object.
no big deal but a suggestion.
thanks
Coinex websocket does not working on blazor web assembly,
this error occurs when using this library on blazor web assembly "Cryptography algorithms is not supported on this platform".
Hi JKorf,
first, thanks for all this super work.
I notice a small issue when I try to withdraw from coinex. I got a signature error message. This seems to be du to the presence of a : char in the destination address.
According to the CoinEx signature sample here (class CoinExClient),, line 27, the signature should be calculated over a big string containing the parameters. Their is no escape of the parameter values.
var body = string.Join("&", sortedArgs.Select(p => $"{p.Key}={p.Value}"));
//calc md5
var md5 = MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(body));
But in your code, you use an Http Utility NameValueCollection, in ExtensionMethods.cs
NameValueCollection nameValueCollection = HttpUtility.ParseQueryString(string.Empty);
...
uriBuilder.Query = nameValueCollection.ToString();
This code replace the : char by %3a
This make the signature to be wrong.
I think you can reproduce with any method that accept a not letter or digit parameter value.
HTH,
Eric
Hi,
Can you update the CoinExchange.Net to the current one on nuget?
thanks
Hi @JKorf ,
I notice that the CoinExSocketOrderBook does not include the checksum field announced in the documentation.
And, as a consequence, the CoinExSymbolOrderBook does not seem to check it.
Do you plan to support this feature of CoinEx?
Thanks
Eric
Describe the bug
A clear and concise description of what the bug is.
To Reproduce
What endpoints and subscriptions are called.
Expected behavior
A clear and concise description of what you expected to happen.
Debug logging
Add debug logging related to the issue. Enable Debug logging in the client options by settings LogLevel to Debug.
Hi
I Call Stop-Limit Order Save Order in Coinex Maket but in C# Not Return Successfully.
Has an Error Parameters
Hi.
I want withdraw with coinex nuget and I have some questions
1- Symbol format (syntax) in withdraw command. e.g : "DOGE-USDT" or "DOGE/USDT" or ...
2- in withdraw i getting error ;
var TransferfromCoinexRes = await clientCoinex.WithdrawAsync("DOGE/USDT", addr,true,1);
{25: Signature Incorrect }
3-In parameters of withdraw,There is no parameter based on the type of network.
4- withdraw in coinex site It asks me for the topt password, but here's what we need to do.
Explain that I whitelisted the address
good luck thank you
Hi @JKorf ,
when I used the GetExecutedOrderDetails api on the client, I received a message with a null in the order_id field.
This cause an exception in the Desirialize.
I suggest you put the property
public long OrderId { get; set; }
in CoinExOrderTrade to nullable.
Somthing like
public long? OrderId { get; set; }
Eric
Hi
I get the following error after upgrading to version 3.0.2 by calling any of the client methods.
3: Server error: No such host is known
Hi,
When I'm trying to make a market buy order the server keeps saying insuff funds. If I manually buy them and do a market sell i have no problem. the buy order just won't work. Limit orders works both ways
Also tried with other currencies like XMRBTC and it does the same.
thanks
Prices for known Pairs like BTCUSDT or ETHBTC are correct but when I'm trying to fetch the orderbook for PGNBTC I'm not getting the Correct prices!
here is the best ask and bid price I'm getting it does not match with the prices I'm seeing on coinex orderbook right now!
Prices I'm getting from CoinExSymbolOrderBook for PGNBTC
0.000000010000 0.000000000000
Prices I'm seeing on exchange order book
0.0000000038 0.0000000035
These numbers should match the numbers I'm seeing on the exchange right?
var coinExSymbolOrderBook = new CoinExSymbolOrderBook("PGNBTC", new CoinExOrderBookOptions(){LogVerbosity = LogVerbosity.Debug});
coinExSymbolOrderBook.OnBestOffersChanged += tuple =>
Console.WriteLine("{0:0.000000000000} {1:0.000000000000}", coinExSymbolOrderBook.BestAsk.Price,coinExSymbolOrderBook.BestBid.Price);
coinExSymbolOrderBook.Start();
Here is the simplified code I'm using!;
Here is the log I'm getting as you can see it only fetches 1 bid price and
2021/02/11 16:28:04:164 | CoinEx | Debug | CoinEx order book PGNBTC starting
2021/02/11 16:28:04:169 | CoinEx | Info | CoinEx order book PGNBTC status changed: Disconnected => Connecting
2021/02/11 16:28:06:375 | CoinEx | Info | CoinEx order book PGNBTC status changed: Connecting => Syncing
2021/02/11 16:28:06:410 | CoinEx | Debug | CoinEx order book PGNBTC data set: 1 bids, 20 asks. #637486450864063088
2021/02/11 16:28:06:414 | CoinEx | Info | CoinEx order book PGNBTC status changed: Syncing => Synced
2021/02/11 16:28:07:191 | CoinEx | Debug | CoinEx order book PGNBTC update processed #637486450871870154-637486450871870154
Hi,
I want to get deposit address of coin?
Are you lack this function ?
After upgrade, I always get "Error deserializing data" when placing order. It seems there is deserializing issue for result parsing.
Run time environment:
CoinEx.Net version = 3.0.11
CryptoExchange.Net version = 3.0.14
.NetStandard version = 2.0 (It works)
.Net Framework version = 4.6.1 (Error deserializing data)
Please add perpetual endpoints
Hi @JKorf
I notice that for CoinEx, you forbid the setting of SocketSubscriptionsCombineTarget.
However, this should work according to CoinEx documentation.
Do you encounter specific problem in this area ?
Thanks.
Eric
Short Form of my issue:
*) My software keep receiving this error message when I want to retrieve my account balance:
First lets try if information of the provider itself is valid or not?
According to
https://github.com/coinexcom/coinex_exchange_api/wiki/012security_authorization
we need a authorization code, which is an MD5 to sign in, let see the process.
1- Sort all parameter, As I have only one: tonce
2- Generate String to sign, which means add access_id at the beginning and secret_key at the end
so:
access_id=123&tonce=1590000000000&secret_key=12345
This shall go to an MD5 hashing process, assuming it would be AaBbCc
It has to be upper cased then this will go to header:
authorization:AABBCC
Note that in their sample "?" does not exists.
The BaseURL is: https://api.coinex.com/v1/
and the folder/directory path is: balance/info
Complete request to GET is:
https://api.coinex.com/v1/balance/info?access_id=123&tonce=1590000000000&secret_key=12345
But I receive error:
{"code":25,"data":{},"message":"Signature error."}
Now my confusion starts
maybe "?" shall be added, maybe complete URL shall be MD5ed, maybe not base url but folder should be added only, maybe GET command also should be included, maybe all of it shall be upper cased, maybe lower cased! all with and without "?"
maybe I put only tonce for MD5 and access_id with secret_key in header, and this list goes on with more probabilities.
I sent "some" request to them for help, no success, so I am asking help here too.
My ((Sample)) code:
AnsiString BaseURL="https://api.coinex.com/v1/";
AnsiString Folder ="balance/info";
AnsiString QueMark="?";
AnsiString MyStr="access_id=123&tonce=1590000000000&secret_key=12345"
AnsiString AuthorizationCode=Md5(
//QueMark+ //that I try both ways
MyStr);
RESTClient1->Params->AddHeader("authorization", AuthorizationCode);
RESTClient1->Params->AddHeader("User-Agent","Mozilla/...as what they said...");
RESTClient1->Accept="application/json";
RESTClient1->AcceptCharset="UTF-8";
RESTClient1->AcceptEncoding="*";
RESTClient1->ContentType="application/x-www-form-urlencoded"
RESTClient1->AllowCookies=true;//false??
RESTClient1->AutoCreateParams=true;//false??
RESTClient1->BaseURL=BaseURL+Folder+QueMark+MyStr;
RESTRequest1->Execute();
MemoResult->Lines->Text=RESTResponse1->Content;
Occurs with latest update on GetMarketStatesAsync
Parameter name: name
Source=System
StackTrace:
at System.Net.WebHeaderCollection.ThrowOnRestrictedHeader(String headerName)
at System.Net.WebHeaderCollection.Set(String name, String value)
at System.Collections.Specialized.NameValueCollection.set_Item(String name, String value)
at CoinEx.Net.CoinExClient.ConstructRequest(Uri uri, String method, Dictionary2 parameters, Boolean signed) at CryptoExchange.Net.RestClient.<ExecuteRequest>d__24
1.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at CoinEx.Net.CoinExClient.<Execute>d__70
1.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at CoinEx.Net.CoinExClient.<GetMarketStatesAsync>d__32.MoveNext() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter
1.GetResult()
at <GetCoinEx_MarketStatesAsync>d__1.MoveNext() in C:
hi there
I see new version the CancelOrderAsync is not working, Please Check it.
thank you
Hi,
I have the following error when using the SubscribeToOrderUpdates method:
Error:invalid argument code:1
This is my code:
var symbols = new List();
symbols.Add("BTCUSDT");
var sub06 = ws.SubscribeToOrderUpdates(symbols, (updateType, data) => { });
if (!sub06.Success)
{
Console.WriteLine($"SubscribeToOrderUpdates Error:{sub06.Error.Message} code:{sub06.Error.Code}");
}
Thx.
Hi @JKorf ,
when I try to subscribe to order update, the call fails.
Here the log:
[2021/03/22 16:01:37.372, (19, 1)] INFO: 2021/03/22 16:01:37:372 | CoinEx | Debug | Socket 2 connected
[2021/03/22 16:01:37.388, (19, .)] INFO: 2021/03/22 16:01:37:388 | CoinEx | Debug | Socket 2 sending data: {"method":"server.sign","params":["5CC167B173DA4EFD84977E77EB2D0F50","D8DAD20312D59331970626728E3F88CE",1616428897376],"id":28}
[2021/03/22 16:01:37.708, (12, .)] INFO: 2021/03/22 16:01:37:708 | CoinEx | Debug | Socket 2 received data: {"error": null, "result": {"status": "success"}, "id": 28}
[2021/03/22 16:01:37.714, (12, .)] INFO: 2021/03/22 16:01:37:714 | CoinEx | Debug | Authorization completed
[2021/03/22 16:01:37.716, (13, .)] INFO: 2021/03/22 16:01:37:716 | CoinEx | Debug | Socket 2 sending data: {"method":"order.subscribe","params":[["ZECBTC"]],"id":19}
[2021/03/22 16:01:37.918, (28, .)] INFO: 2021/03/22 16:01:37:918 | CoinEx | Debug | Socket 2 received data: {"error": {"code": 1, "message": "invalid argument"}, "result": null, "id": 19}
[2021/03/22 16:01:37.920, (28, .)] INFO: 2021/03/22 16:01:37:920 | CoinEx | Debug | Failed to subscribe: 1 invalid argument
[2021/03/22 16:01:37.926, (23, 2)] INFO: 2021/03/22 16:01:37:926 | CoinEx | Debug | Socket 2 closing
My analyze is that in
return await Subscribe(new CoinExSocketRequest(NextId(), OrderSubject, SubscribeAction, symbols), null, true, internalHandler).ConfigureAwait(false);
symbols is an array of string, but in
public CoinExSocketRequest(int id, string subject, string action, params object[] parameters)
the parameters is an array of one element. And this element is an array of strings.
Hop it help.
Eric
Hi,
Thank you for your great libraries.
As CoinEx support team stated here the API documentation and specs are located at https://viabtc.github.io/coinex_api_en_doc/.
I figure it out that not all APIs are implemented yet, maybe it's because you are using an older version of document.
for example, there is an API for cancelling a stop order in CoinEx (here) which is not exists in the library.
Describe the bug
SubscribeToOrderUpdatesAsync returns invalid arguments (Error:1: invalid argument )
To Reproduce
var r=await socket.SubscribeToOrderUpdatesAsync(new[] { "DOGEUSDT" }, (updateType, data) =>
{
var actual = data;
});
Expected behavior
r.success must be true
Hi JKorf,
I notice a typo error:
Line 17 is
new KeyValuePair<OrderOption, string>(OrderOption.MakerOnly, "MAKEN_ONLY")
Should be
new KeyValuePair<OrderOption, string>(OrderOption.MakerOnly, "MAKER_ONLY")
Eric
Hi guys,
I want to see how to create 'PERPETUAL ORDER' with API.
Thanks for help me.
Hi,
first of all, I am a newbie here :) I managed to communicate with the coinex but in the last 2 or 3 days, GetBalancesAsync and GetUserTradesAsync functions were not working. all the codes which worked well in the last months are now out of work,
please check the issue
BR,
When I subscribe to the trade information, I received this warning:
"[2021/05/01 12:27:54.368, (36, .)] INFO: 2021/05/01 12:27:54:368 | CoinEx | Warning | Received unexpected data format for trade update. Expected 2 objects, received 3. Data: [ONESUSDT,[\r\n {\r\n "id": 2275032287,\r\n "order_id": 45397170793,\r\n "client_id": "",\r\n "time": 1619872074.354161,\r\n "type": "sell",\r\n "amount": "12.72533333",\r\n "price": "1.0500"\r\n }\r\n],True]",
"[2021/05/01 12:27:54.974, (36, .)] INFO: 2021/05/01 12:27:54:974 | CoinEx | Warning | Received unexpected data format for trade update. Expected 2 objects, received 3. Data: [ONESUSDT,[\r\n {\r\n "id": 2275032292,\r\n "order_id": 45397170793,\r\n "client_id": "",\r\n "time": 1619872074.629507,\r\n "type": "sell",\r\n "amount": "8.55734985",\r\n "price": "1.0500"\r\n }\r\n],True]",
Someone add a True a the end?
Eric
Hi @JKorf ,
when I subscribe to the asset stream, with SubscribeToBalanceUpdatesAsync
I received a two elements array. The second element is only a single zero.
I don't known why it is this way.
So the code in the handler throw an exception.
I suggest that you accept this case, with something like
if (data.Length != 1)
{
if (data.Length != 2 || (data.Length == 2 && data[1].ToString().Trim() != "0"))
{
log.Write(LogVerbosity.Warning, $"Received unexpected data format for balance update. Expected 1 objects, received {data.Length}. Data: [{string.Join(",", data.Select(s => s.ToString()))}]");
return;
}
}
Also, I may change the message, as it still refer to order update when it is balance update.
Eric
Hello, when i want buy coin i must input 2 data , in example write 50,.. , i write my amount of coins i want buy and in next i write price of coin and both of them are decimal, i use varible in c# for bouth of them but when i want buy a coin and for example amount of coin is 654435.23244 this code dont working and i must use this number in code with m to working, please help me
im getting an error on Withdraw - "25: Signature error."
maybe transfer_method parameter missing? https://github.com/coinexcom/coinex_exchange_api/wiki/062submit_withdraw
Hi Jan Korf, first of all I thank you for your labor, I am grateful for your efforts.I think it's time to add the futures feature.May I ask you to add futures to your package? I would like to give you a Cet token gift, because coinex is improving itself, and now there are tradingview charts on coinex. I don't know december you know, by the way, Coinex created the Coinex Smart Chain network .
by the way, I apologize for my bad English.
Hello ,
it seems stop-limit order type is not available in lib.
so I got the source and implement and also test it .
what is a right path to merge it into main lib ?
thanks
SubscribeToKlineUpdatesAsync
I try to get 5 minutes candles, TwoHour or other candles via SubscribeToKlineUpdatesAsync but I get this response:
listResult.Data
{
data : null,
Error: {
code : 4,
data : null,
message: "method not found"
},
Success: False
}
please help me to fix this problem.
using(var sockClient = new CoinExSocketClient())
{
var listResult = await sockClient.SubscribeToKlineUpdatesAsync("ADAUSDT", Objects.KlineInterval.TwoHour, (e )=> {
Console.WriteLine(e.Data.FirstOrDefault().Close);
});
Console.WriteLine(listResult);
}
Hi @JKorf ,
I got an error during call to GetDepositHistoryHistoryAsync. It seems that the "has_next" field was not expected.
Maybe we must use a CoinExPagedResult<IEnumerable<CoinExDeposit>>
or something similar?
The debug trace is below.
Eric
2021/05/23 11:41:10:952 | CoinEx | Debug | Client configuration: LogVerbosity: Debug, Writers: 2, Credentials: Set, BaseAddress: https://api.coinex.com/v1/, Proxy: -, RateLimiters: 0, RateLimitBehaviour: Wait, RequestTimeout: 00:00:30
2021/05/23 11:41:14:318 | CoinEx | Debug | [1] Creating request for https://api.coinex.com/v1/balance/coin/deposit
2021/05/23 11:41:14:333 | CoinEx | Debug | [1] Sending GET signed request to https://api.coinex.com/v1/balance/coin/deposit?access_id=5ZZZZZZZZZZZZZZZZZZZZZZZZZZZ&coin_type=ZEN&tonce=1621762874319
2021/05/23 11:41:14:813 | CoinEx | Debug | [1] Response received in 476ms: {"code": 0, "data": {"has_next": false, "curr_page": 1, "count": 1, "data": [{"coin_deposit_id": 6177984, "create_time": 1621630590, "amount": "4.1", "amount_display": "4.1", "actual_amount": "4.1", "actual_amount_display": "4.1", "confirmations": 20, "tx_id": "d09b829819f5bcd0de442b86f8381a52b4bd46a607c61729bae1e4e94d540b90", "tx_id_display": "d09b829819f5bcd0de442b86f8381a52b4bd46a607c61729bae1e4e94d540b90", "coin_address": "znYvvoaB383eCgAR8Fxpe6z9dXW8WBemvmr", "coin_address_display": "znYvvo****Bemvmr", "add_explorer": "https://explorer.zensystem.io/address/znYvvoaB383eCgAR8Fxpe6z9dXW8WBemvmr", "coin_type": "ZEN", "smart_contract_name": "", "transfer_method": "onchain", "status": "finish", "status_display": "finish", "remark": "", "explorer": "https://explorer.zensystem.io/tx/d09b829819f5bcd0de442b86f8381a52b4bd46a607c61729bae1e4e94d540b90"}], "total": 1, "total_page": 1}, "message": "Success"}
2021/05/23 11:41:14:831 | CoinEx | Error | [1] Deserialize JsonSerializationException: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.IEnumerable`1[CoinEx.Net.Objects.CoinExDeposit]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
Path 'data.has_next', line 1, position 32.
convert stopPrice to stop_price in PlaceOrderAsync Method
Firstly, thanks for such a great library!
I noticed that after some period of time, SymolOrderBook stop distributing data, at least it sends empty order book and after that - silence. Status is "Synced". Have check Coinex, but exchange sends data correctly, without outages.
Same problem with Kucoin symbol orderbook.
Thats short example
var orderbook = new CoinExSymbolOrderBook(symbol, new CoinExOrderBookOptions());
await orderBook.StartAsync().ConfigureAwait(false);
....
var updateNumber = instance.OrderBook.LastSequenceNumber;
while (!Token.IsCancellationRequested)
{
if (updateNumber != OrderBook.LastSequenceNumber)
{
OnOrderBook(orderBook); //Event
updateNumber = instance.OrderBook.LastSequenceNumber;
}
Thread.Sleep(100);
}
The CoinExAssetConfig class miss the asset and chain properties useful for deposit and withdraw.
I suggest you to add:
/// <summary>
/// Asset code
/// </summary>
[JsonProperty("asset")]
public string Asset { get; set; }
/// <summary>
/// Withdraw & Deposit asset chain
/// </summary>
[JsonProperty("chain")]
public string Chain { get; set; }
Thanks a lot.
Andrea
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.