Skip to content

Commit 7b6e897

Browse files
Johnny A. dos Santosjjxtra
authored andcommitted
New terminal interface implementation (#467)
* Migration to new CLI * Migration of a few commands * Fix keys utility command * Migrate ws orderbook and remove logger usage * Make GetExchangeAPI ignore casing * Migrate last ws commands * Inline and refactor last commands from the old CLI * Remove unused nuget package * Fix exit code on exception when connecting to WS
1 parent af442f4 commit 7b6e897

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1549
-1273
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,3 +451,6 @@ modules.xml
451451
*.log*
452452
launchSettings.json
453453
**/PublishProfiles/*
454+
455+
## Project specific
456+
**/keys.bin

ExchangeSharp/API/Common/BaseAPI.cs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ public async Task<object> GenerateNonceAsync()
313313
{
314314
await OnGetNonceOffset();
315315
}
316-
316+
317317
object nonce;
318318

319319
while (true)
@@ -430,17 +430,26 @@ public async Task<object> GenerateNonceAsync()
430430
/// <param name="encryptedFile">Encrypted file to load keys from</param>
431431
public void LoadAPIKeys(string encryptedFile)
432432
{
433-
SecureString[] strings = CryptoUtility.LoadProtectedStringsFromFile(encryptedFile);
434-
if (strings.Length < 2)
435-
{
436-
throw new InvalidOperationException("Encrypted keys file should have at least a public and private key, and an optional pass phrase");
437-
}
438-
PublicApiKey = strings[0];
439-
PrivateApiKey = strings[1];
440-
if (strings.Length > 2)
441-
{
442-
Passphrase = strings[2];
443-
}
433+
if (string.IsNullOrWhiteSpace(encryptedFile))
434+
throw new ArgumentNullException(nameof(encryptedFile));
435+
if (!File.Exists(encryptedFile))
436+
throw new ArgumentException("Invalid key file.", nameof(encryptedFile));
437+
438+
var strings = CryptoUtility.LoadProtectedStringsFromFile(encryptedFile);
439+
440+
if (strings.Length < 2)
441+
{
442+
throw new InvalidOperationException(
443+
"Encrypted keys file should have at least a public and private key, and an optional pass phrase"
444+
);
445+
}
446+
447+
PublicApiKey = strings[0];
448+
PrivateApiKey = strings[1];
449+
if (strings.Length > 2)
450+
{
451+
Passphrase = strings[2];
452+
}
444453
}
445454

446455
/// <summary>

ExchangeSharp/API/Exchanges/_Base/ExchangeAPI.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -289,21 +289,19 @@ public static IExchangeAPI GetExchangeAPI(string exchangeName)
289289
// find an API with the right name
290290
foreach (Type type in typeof(ExchangeAPI).Assembly.GetTypes().Where(type => type.IsSubclassOf(typeof(ExchangeAPI)) && !type.IsAbstract))
291291
{
292-
api = Activator.CreateInstance(type) as IExchangeAPI;
293-
if (api.Name == exchangeName)
292+
api = (IExchangeAPI) Activator.CreateInstance(type);
293+
if (api.Name.Equals(exchangeName, StringComparison.OrdinalIgnoreCase))
294294
{
295295
// found one with right name, add it to the API dictionary
296296
apis[exchangeName] = api;
297297

298298
// break out, we are done
299299
break;
300300
}
301-
else
302-
{
303-
// name didn't match, dispose immediately to stop timers and other nasties we don't want running, and null out api variable
304-
api.Dispose();
305-
api = null;
306-
}
301+
302+
// name didn't match, dispose immediately to stop timers and other nasties we don't want running, and null out api variable
303+
api.Dispose();
304+
api = null;
307305
}
308306
}
309307
return api;
@@ -788,7 +786,7 @@ public virtual async Task<ExchangeWithdrawalResponse> WithdrawAsync(ExchangeWith
788786
withdrawalRequest.Currency = NormalizeMarketSymbol(withdrawalRequest.Currency);
789787
return await OnWithdrawAsync(withdrawalRequest);
790788
}
791-
789+
792790
/// <summary>
793791
/// Gets the withdraw history for a symbol
794792
/// </summary>
@@ -832,7 +830,7 @@ public virtual async Task<ExchangeCloseMarginPositionResult> CloseMarginPosition
832830
return await OnCloseMarginPositionAsync(NormalizeMarketSymbol(marketSymbol));
833831
}
834832

835-
833+
836834

837835
#endregion REST API
838836

ExchangeSharp/Utility/DataProtector.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ private static byte[] CryptOperationWindows(bool protect, byte[] data, byte[] op
151151
#region Non-Windows
152152

153153
//
154-
// ManagedProtection.cs -
154+
// ManagedProtection.cs -
155155
// Protect (encrypt) data without (user involved) key management
156156
//
157157
// Author:
@@ -166,10 +166,10 @@ private static byte[] CryptOperationWindows(bool protect, byte[] data, byte[] op
166166
// distribute, sublicense, and/or sell copies of the Software, and to
167167
// permit persons to whom the Software is furnished to do so, subject to
168168
// the following conditions:
169-
//
169+
//
170170
// The above copyright notice and this permission notice shall be
171171
// included in all copies or substantial portions of the Software.
172-
//
172+
//
173173
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
174174
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
175175
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -189,7 +189,7 @@ internal static class ManagedProtection
189189
{
190190
private static readonly RSA user;
191191
private static readonly RSA machine;
192-
192+
193193
static ManagedProtection()
194194
{
195195
try
@@ -307,7 +307,7 @@ public static byte[] Protect(byte[] userData, byte[] optionalEntropy, DataProtec
307307
return result;
308308
}
309309

310-
// FIXME [KeyContainerPermission (SecurityAction.Assert, KeyContainerName = "DAPI",
310+
//TODO: FIXME [KeyContainerPermission (SecurityAction.Assert, KeyContainerName = "DAPI",
311311
// Flags = KeyContainerPermissionFlags.Open | KeyContainerPermissionFlags.Decrypt)]
312312
public static byte[] Unprotect(byte[] encryptedData, byte[] optionalEntropy, DataProtectionScope scope)
313313
{
@@ -529,7 +529,7 @@ public static byte[] Unprotect(byte[] data, byte[] optionalEntropy = null, DataP
529529
else
530530
{
531531
return ManagedProtection.Unprotect(data, optionalEntropy, scope);
532-
}
532+
}
533533
}
534534
}
535535

ExchangeSharpConsole/Console/ExchangeSharpConsole_Convert.cs

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)