Author

Topic: [ANN/DEV] C#/.NET library for BTC-TC API (& demo-client) (Read 1801 times)

hero member
Activity: 765
Merit: 503
Some feedback.  .Net has a json Serializer built in, so you don't need newton. 

Check out my coinjar wrapper https://github.com/dugongsoftware/CoinJar.Net

Using generics, you can create a model class of the ticker object, then deserializer it

private Ticker parseTicker(JToken j) could use https://github.com/dugongsoftware/CoinJar.Net/blob/master/CoinJar.Net/Providers/JsonSerializer.cs instead.
hero member
Activity: 728
Merit: 500
Is it able to handle automated internal transfers?
Yes. The library is used by the auto-transfer-program that handles asset-transfers for Deprived Mining Speculation.

Quote
How does it deal with 2FA?
The BTC-TC API has 3 types of authentication levels for its requests:
- Open, no need to even have an account for these requests (market data, order books, etc...)
- API key, the API key listed on your Account page is required for these requests (portfolio, personal trade history, dividend history, etc... all read-only things)
- OAuth, the user needs to authenticate using OAuth for these requests. Once authenticated, OAuth tokens are valid as long as they are used at least once every 7 days (or until they are manually invalidated by the user on the BTC-TC website). OAuth-requests include order-submissions, transfers, etc... Things that can actually make or cost you coin.

To authenticate with OAuth, you are redirected to the BTC-TC website, where you have to grant access to the program. Your 2FA code is required at this stage (or pin-code if you don't use 2FA). Once access has been granted, the program can execute trades and transfers without any further authentication as long as the access token remains valid. Therefore it is important that the machine that runs the program is secure.

These properties are inherent to the structure of the BTC-TC API and not specific for this library. Any software using the BTC-TC API will have the same security considerations.
full member
Activity: 230
Merit: 100
This is really great, I will try it!

2 questions in advance:

Is it able to handle automated internal transfers?
How does it deal with 2FA?
legendary
Activity: 1106
Merit: 1026
So there are good reasons to switch to your own keypair, but if you just want to do some quick tests it's not essential.

That's true.

Now I feel like my statement can be misunderstood. Sorry, that wasn't my intention. Smiley

To be clear: even if you don't change the consumer key and secret as suggested above, Rannasha will not be able to do anything naughty, because the access token secret is not visible for the application issuer. There is no risk to use the demo application.
hero member
Activity: 728
Merit: 500
The visible source code is clean, though I advice anyone who wants to try the demo client to replace the predefined consumer key and secret with the OAuth data issued by yourself (BTCTC_MainWindow.cs, line 37+38). To do this head over to "Account" - "API Management" - "Create A New API Application".

It's not necessary per se to generate a new consumer key/secret pair, as this key-pair is not tied to an account. However, it is used to identify the application that is trying to access the API (if you attempt to run the code as it is, the BTC-TC website will ask you if you want to authorize "BTCTLink Demo Client"), so if you're going develop and distribute your own application, you may want to have it say something else. In addition, whoever generated the consumer key/secret can also withdraw the keypair. So I could randomly decide to remove the keypair that I included in the demo client and it will suddenly no longer be able to authenticate.

So there are good reasons to switch to your own keypair, but if you just want to do some quick tests it's not essential.
legendary
Activity: 1106
Merit: 1026
I see. Sneaky you. Creating a huge amount of SexCoin mining slaves. Grin

Just kidding, great job! Smiley

The visible source code is clean, though I advice anyone who wants to try the demo client to replace the predefined consumer key and secret with the OAuth data issued by yourself (BTCTC_MainWindow.cs, line 37+38). To do this head over to "Account" - "API Management" - "Create A New API Application".
hero member
Activity: 728
Merit: 500
BTCTLink - A library for communication with BTC-TC API

Introduction
BTCTLink is a C#/.NET library that handles the communication with the BTC-TC API. It can serve as a base to build applications on that interact with BTC-TC or Litecoin-Global (both exchanges and their APIs function exactly the same, for brevity I will only mention BTC-TC).

In addition to the class that handles communication and the associated utility-classes, a demo-client is also available that demonstrates the functionality. While this demo-client is fully functional, it is not intended as a substitute for the BTC-TC website in its current state (though developers may use it as a platform to add additional functionality).

Downloading & Using
The library and demo-client are available on GitHub:
Library: https://github.com/Rannasha/BTCTLink
Demo-client: https://github.com/Rannasha/BTCT-Client

The easiest way to get started is to open BTCT-Client.sln in Visual Studio and continue from there. If you already have a project, you can just include BTCTLink. The readme.md file in the BTCTLink repository has a brief description of how to setup a connection and submit API requests. The BTCT-Client code has examples for all API calls and how to handle response data.

Questions, comments, songs of praise
Please post any questions, comments, etc... here, send me a PM or submit an issue on GitHub. If you have improvements that you'd like to share, you're invited to fork the Git repo and create a pull request.

If this project has been to your liking, consider a donation:
1Gideon33Q7ANGhCbfkxPHpWoNGz5Lyskm
Thanks!

FAQ
Do you have a compiled version available?
No. This project is aimed at developers, not at end users. If you don't want to program, this isn't for you. If you are a developer, then you don't need a compiled version.

What could I do with this?
Some things I could imagine are a desktop-client for the exchange, offering more detailed information than what the website provides. A trade-bot is another interesting application. Or simply a basic ticker with possibility for price-alerts.

So it supports both BTC-TC and Litecoin-Global, how does that work?
The class that handles the communication has a parameter in its constructor that can be used to specify which exchange to use. This only affects the API-urls used, as both exchanges are identical in function. The demo-client is set to connect to BTC-TC by default, but it can be changed to LTC-Global in the source code.

Does this steal my wallet.dat?
Yes. In addition, it will mine SexCoins, bring world peace and fry your cat. But seriously, check the code for fishy things. Note that the BTCTLink repository includes a compiled version of the JSON.NET library by Newtonsoft. This library is available from the Visual Studio package manager, so you can replace the one from the repo by the files provided by VS.

Why does your code look so sloppy?
I'm a self-taught programmer who has worked in science, where the mantra is "If it compiles, good. If it gives the correct result, great. If it does so before I die of old age, perfect!" So with no formal experience in software development, my code may not satisfy all the accepted standards for well-written code (honestly, it's not that big a mess either, if I say so myself). Additionally, I used this project to learn C#/.NET, so I may not use everything the language/platform has to offer. Suggestions for improvements are welcome!

How well-tested is this, can I lose assets/coins?
All functions were tested under a variety of circumstances (parts of the library have handled hundreds of BTC worth of operations), but I can't make any guarantees. Before you use an application using this library in a live environment, run plenty of tests to ensure everything is as it should be.

Credits
Thanks to samo9789 (https://github.com/samo9789) for the sharpOAuth library, which handles most of the low-level OAuth stuff.
Thanks to Deprived (https://bitcointalksearch.org/user/deprived-40149) for testing & providing valuable feedback.
Jump to: