Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: automated format #814

Merged
merged 4 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ root = true

[*.cs]
indent_style = tab
indent_size = 4
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
Expand Down
6 changes: 6 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"recommendations": [
"josefpihrt-vscode.roslynator",
"ms-dotnettools.csharp"
]
}
22 changes: 22 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"workbench.colorCustomizations": {
"activityBar.background": "#753ca1",
"activityBar.foreground": "#ffffff",
"activityBar.inactiveForeground": "#ffffff99",
"activityBarBadge.background": "#d211fd",
"activityBarBadge.foreground": "#ffffff",
"statusBar.noFolderBackground": "#642596",
"statusBar.background": "#753ca1",
"statusBar.foreground": "#ffffff",
"statusBarItem.hoverBackground": "#642596",
"titleBar.activeBackground": "#753ca1",
"titleBar.activeForeground": "#ffffff"
},
"[csharp]": {
"editor.tabSize": 2,
"editor.detectIndentation": false,
"editor.insertSpaces": false,
"editor.defaultFormatter": "ms-dotnettools.csharp"
},
"editor.renderWhitespace": "all"
}
101 changes: 50 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,67 +6,67 @@

## Overview

ExchangeSharp is a C# **framework/lib** and [console app](#Installing-the-CLI) for trading and communicating with [various](#Exchanges) exchange API end points for cryptocurrency assets. Many exchanges are supported, along with [web sockets](#Websockets), withdraws and more!
ExchangeSharp is a C# **framework/lib** and [console app](#installing-the-cli) for trading and communicating with [various](#exchanges) exchange API end points for cryptocurrency assets. Many exchanges are supported, along with [web sockets](#websockets), withdraws and more!

Feel free to visit the discord channel at https://discord.gg/58ktxXuTVK and chat with other developers.
Feel free to visit the discord channel at <https://discord.gg/58ktxXuTVK> and chat with other developers.

### Features

- Many exchanges supported with public, private and web socket API
- Many [exchanges](/src//ExchangeSharp/API/Exchanges/) supported with public, private and web socket API
- Easy to use code and API
- Optional global market symbol normalization, since each exchange has their own way of doing market symbols
- Runs anywhere .NET runs. (Windows, Mac, Linux, Containers, Serverless, iOS, Android, [etc.](https://docs.microsoft.com/en-us/dotnet/core/about))
- Can be used from [many different C# platforms](https://github.com/dotnet/standard/blob/master/docs/versions/netstandard2.0.md#platform-support)
- Has a great [CLI](#Installing-the-CLI) that enables you to use all features from all exchanges right from your command line.
- Has a great [CLI](#installing-the-cli) that enables you to use all features from all exchanges right from your command line.

### Exchanges

The following cryptocurrency exchanges are supported:
(Web socket key: T = tickers, R = trades, B = orderbook / delta orderbook, O = private orders, U = user data)

| Exchange Name | Public REST | Private REST | Web Socket | Notes |
| -------------- | ----------- | ------------ | ---------- | ---------------------------------------- |
| ApolloX | x | x | T R B O U |
| Aquanow | wip | x | |
| Binance | x | x | T R B O U |
| Binance Jersey | x | x | T R B O U | Ceased operations
| Binance.US | x | x | T R B O U |
| Binance DEX | | | R |
| Bitbank | x | x | |
| Bitfinex | x | x | T R O |
| Bitflyer | | | R |
| Bithumb | x | | R |
| BitMEX | x | x | R O |
| Bitstamp | x | x | R |
| Bittrex | x | x | T R |
| BL3P | x | x | R B | Trades stream does not send trade's ids. |
| Bleutrade | x | x | |
| BtcTurk | | | R |
| BTSE | x | x | |
| Bybit | x | x | R | Has public method for Websocket Positions
| Coinbase | x | x | T R O U |
| Coincheck | | | R |
| Coinmate | x | x | |
| Crypto.com | | | R |
| Digifinex | x | x | R B |
| Dydx | | | R |
| FTX | x | x | T R |
| FTX.us | x | x | T R |
| gate.io | x | x | R |
| Gemini | x | x | T R B |
| HitBTC | x | x | R |
| Huobi | x | x | R B |
| Kraken | x | x | R | Dark order symbols not supported |
| KuCoin | x | x | T R |
| LBank | x | x | R |
| Livecoin | x | x | |
| NDAX | x | x | T R |
| OKCoin | x | x | R B |
| OKEx | x | x | T R B O |
| Poloniex | x | x | T R B |
| UPbit | | | R |
| YoBit | x | x | |
| ZB.com | wip | | R |
| Exchange Name | Public REST | Private REST | Web Socket | Notes |
| ----------------------- | ----------- | ------------ | ------------- | ------------------------------------------- |
| ApolloX | x | x | T R B O U | |
| Aquanow | wip | x | | |
| Binance | x | x | T R B O U | |
| ~~Binance Jersey~~ | ~~x~~ | ~~x~~ | ~~T R B O U~~ | Ceased operations |
| Binance.US | x | x | T R B O U | |
| Binance DEX | | | R | |
| Bitbank | x | x | | |
| Bitfinex | x | x | T R O | |
| Bitflyer | | | R | |
| Bithumb | x | | R | |
| BitMEX | x | x | R O | |
| Bitstamp | x | x | R | |
| Bittrex | x | x | T R | |
| BL3P | x | x | R B | Trades stream does not send trade's ids. |
| Bleutrade | x | x | | |
| BtcTurk | | | R | |
| BTSE | x | x | | |
| Bybit | x | x | R | Has public method for Websocket Positions |
| Coinbase (Pro) | x | x | T R O U | |
| Coincheck | | | R | |
| Coinmate | x | x | | |
| Crypto.com | | | R | |
| Digifinex | x | x | R B | |
| Dydx | | | R | |
| FTX | x | x | T R | |
| FTX.us | x | x | T R | |
| gate.io | x | x | R | |
| Gemini | x | x | T R B | |
| HitBTC | x | x | R | |
| Huobi | x | x | R B | |
| Kraken | x | x | R | Dark order symbols not supported |
| KuCoin | x | x | T R | |
| LBank | x | x | R | |
| Livecoin | x | x | | |
| NDAX | x | x | T R | |
| OKCoin | x | x | R B | |
| OKEx | x | x | T R B O | |
| Poloniex | x | x | T R B | |
| UPbit | | | R | |
| YoBit | x | x | | |
| ZB.com | wip | | R | |

The following cryptocurrency services are supported:

Expand Down Expand Up @@ -169,7 +169,7 @@ Please read the [contributing guideline](CONTRIBUTING.md) **before** submitting

### Consulting

I'm happy to make customizations to the software for you and keep in private repo, email exchangesharp@digitalruby.com.
I'm happy to make customizations to the software for you and keep in private repo, email <exchangesharp@digitalruby.com>.

### Donations Gratefully Accepted

Expand All @@ -189,9 +189,8 @@ Donation totals:
Thanks for visiting!

Jeff Johnson
jeff@digitalruby.com
http://www.digitalruby.com
<jeff@digitalruby.com>
<http://www.digitalruby.com>

[nuget]: https://www.nuget.org/packages/DigitalRuby.ExchangeSharp/
[websocket4net]: https://github.com/kerryjiang/WebSocket4Net

4 changes: 2 additions & 2 deletions src/ExchangeSharp.Forms/Forms/PlotForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions src/ExchangeSharp.Forms/Forms/PlotForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ public PlotForm()
InitializeComponent();
}

public void SetPlotPoints(List<List<KeyValuePair<float, float>>> points, List<KeyValuePair<float, float>> buyPrices = null, List<KeyValuePair<float, float>> sellPrices = null)
public void SetPlotPoints(
List<List<KeyValuePair<float, float>>> points,
List<KeyValuePair<float, float>> buyPrices = null,
List<KeyValuePair<float, float>> sellPrices = null
)
{
// clear the chart
PlotChart.Series.Clear();
Expand Down Expand Up @@ -152,10 +156,7 @@ public static class PlotFormExtensions
{
public static void ShowPlotForm(this Trader trader)
{
PlotForm form = new PlotForm
{
WindowState = FormWindowState.Maximized
};
PlotForm form = new PlotForm { WindowState = FormWindowState.Maximized };
form.SetPlotPoints(trader.PlotPoints, trader.BuyPrices, trader.SellPrices);
form.ShowDialog();
}
Expand Down
38 changes: 20 additions & 18 deletions src/ExchangeSharp/API/Common/APIException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,24 @@ The above copyright notice and this permission notice shall be included in all c

namespace ExchangeSharp
{
/// <summary>
/// Exception class for API calls
/// </summary>
public class APIException : Exception
{
/// <summary>
/// Constructor
/// </summary>
/// <param name="message">Message</param>
public APIException(string message) : base(message) { }
/// <summary>
/// Exception class for API calls
/// </summary>
public class APIException : Exception
{
/// <summary>
/// Constructor
/// </summary>
/// <param name="message">Message</param>
public APIException(string message)
: base(message) { }

/// <summary>
/// Constructor
/// </summary>
/// <param name="message"></param>
/// <param name="innerException">Inner exception</param>
public APIException(string message, Exception innerException) : base(message, innerException) { }
}
}
/// <summary>
/// Constructor
/// </summary>
/// <param name="message"></param>
/// <param name="innerException">Inner exception</param>
public APIException(string message, Exception innerException)
: base(message, innerException) { }
}
}
46 changes: 34 additions & 12 deletions src/ExchangeSharp/API/Common/APIRequestMaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ public sealed class APIRequestMaker : IAPIRequestMaker
public static IWebProxy? Proxy
{
get => ClientHandler.Proxy;
set
{
ClientHandler.Proxy = value;
}
set { ClientHandler.Proxy = value; }
}
public static readonly HttpClient Client = new HttpClient(ClientHandler);

Expand Down Expand Up @@ -105,7 +102,6 @@ public int ReadWriteTimeout
set => Timeout = value;
}


public Task WriteAllAsync(byte[] data, int index, int length)
{
Request.Content = new ByteArrayContent(data, index, length);
Expand Down Expand Up @@ -139,7 +135,10 @@ public Dictionary<string, IReadOnlyList<string>> Headers
{
get
{
return response.Headers.ToDictionary(x => x.Key, x => (IReadOnlyList<string>)x.Value.ToArray());
return response.Headers.ToDictionary(
x => x.Key,
x => (IReadOnlyList<string>)x.Value.ToArray()
);
}
}
}
Expand All @@ -162,7 +161,12 @@ public APIRequestMaker(IAPIRequestHandler api)
/// The encoding of payload is API dependant but is typically json.</param>
/// <param name="method">Request method or null for default. Example: 'GET' or 'POST'.</param>
/// <returns>Raw response</returns>
public async Task<IAPIRequestMaker.RequestResult<string>> MakeRequestAsync(string url, string? baseUrl = null, Dictionary<string, object>? payload = null, string? method = null)
public async Task<IAPIRequestMaker.RequestResult<string>> MakeRequestAsync(
string url,
string? baseUrl = null,
Dictionary<string, object>? payload = null,
string? method = null
)
{
await new SynchronizationContextRemover();
await api.RateLimit.WaitToProceedAsync();
Expand All @@ -189,20 +193,29 @@ public APIRequestMaker(IAPIRequestHandler api)
using var cancel = new CancellationTokenSource(request.Timeout);
try
{
RequestStateChanged?.Invoke(this, RequestMakerState.Begin, uri.AbsoluteUri);// when start make a request we send the uri, this helps developers to track the http requests.
RequestStateChanged?.Invoke(this, RequestMakerState.Begin, uri.AbsoluteUri); // when start make a request we send the uri, this helps developers to track the http requests.
response = await Client.SendAsync(request.Request, cancel.Token);
if (response == null)
{
throw new APIException("Unknown response from server");
}
responseString = await response.Content.ReadAsStringAsync();

if (response.StatusCode != HttpStatusCode.OK && response.StatusCode != HttpStatusCode.Created)
if (
response.StatusCode != HttpStatusCode.OK
&& response.StatusCode != HttpStatusCode.Created
)
{
// 404 maybe return empty responseString
if (string.IsNullOrWhiteSpace(responseString))
{
throw new APIException(string.Format("{0} - {1}", response.StatusCode.ConvertInvariant<int>(), response.StatusCode));
throw new APIException(
string.Format(
"{0} - {1}",
response.StatusCode.ConvertInvariant<int>(),
response.StatusCode
)
);
}

throw new APIException(responseString);
Expand All @@ -225,12 +238,21 @@ public APIRequestMaker(IAPIRequestHandler api)
{
response?.Dispose();
}
return new IAPIRequestMaker.RequestResult<string>() { Response = responseString, HTTPHeaderDate = response.Headers.Date };
return new IAPIRequestMaker.RequestResult<string>()
{
Response = responseString,
HTTPHeaderDate = response.Headers.Date
};
}

/// <summary>
/// An action to execute when a request has been made (this request and state and object (response or exception))
/// </summary>
public Action<IAPIRequestMaker, RequestMakerState, object>? RequestStateChanged { get; set; }
public Action<
IAPIRequestMaker,
RequestMakerState,
object
>? RequestStateChanged
{ get; set; }
}
}
Loading