Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4aebaa0e33 |
@ -6,6 +6,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DigitalRuby.ExchangeSharp" Version="0.5.9" />
|
||||
<PackageReference Include="Peachpie.Runtime" Version="0.9.35" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@ -13,6 +14,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="Views\CcxtExchange\CcxtEditData.cshtml" />
|
||||
<Content Include="Views\Exchange\EditData.cshtml" />
|
||||
<Content Include="Views\PlaceOrder\EditData.cshtml" />
|
||||
</ItemGroup>
|
||||
@ -22,4 +24,11 @@
|
||||
<EmbeddedResource Include="Styles\**;Views\**;Scripts\**" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="PhpLib1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>ccxt-net\PhpLib1.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using BtcTransmuter.Abstractions.ExternalServices;
|
||||
using BtcTransmuter.Data.Entities;
|
||||
using BtcTransmuter.Data.Models;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
|
||||
namespace BtcTransmuter.Extension.Exchange.ExternalServices.CcxtExchange
|
||||
{
|
||||
[Route("exchange-plugin/external-services/ccxtexchange")]
|
||||
[Authorize]
|
||||
public class
|
||||
CcxtExchangeController : BaseExternalServiceController<CcxtExchangeController.EditExchangeExternalServiceDataViewModel>
|
||||
{
|
||||
public CcxtExchangeController(IExternalServiceManager externalServiceManager, UserManager<User> userManager,
|
||||
IMemoryCache memoryCache) : base(externalServiceManager, userManager, memoryCache)
|
||||
{
|
||||
}
|
||||
|
||||
protected override string ExternalServiceType => CcxtExchangeService.ExchangeServiceType;
|
||||
|
||||
protected override Task<EditExchangeExternalServiceDataViewModel> BuildViewModel(ExternalServiceData data)
|
||||
{
|
||||
return Task.FromResult(new EditExchangeExternalServiceDataViewModel(new CcxtExchangeService(data).GetData(),
|
||||
CcxtExchangeService.GetAvailableExchanges()));
|
||||
}
|
||||
|
||||
protected override async
|
||||
Task<(ExternalServiceData ToSave, EditExchangeExternalServiceDataViewModel showViewModel)>
|
||||
BuildModel(EditExchangeExternalServiceDataViewModel viewModel, ExternalServiceData mainModel)
|
||||
{
|
||||
//current External Service data
|
||||
var externalServiceData = mainModel;
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return (null,
|
||||
new EditExchangeExternalServiceDataViewModel(viewModel, CcxtExchangeService.GetAvailableExchanges()));
|
||||
}
|
||||
|
||||
//current External Service data
|
||||
externalServiceData.Set((ExchangeExternalServiceData) viewModel);
|
||||
var exchangeService = new CcxtExchangeService(externalServiceData);
|
||||
|
||||
if (!await exchangeService.TestAccess())
|
||||
{
|
||||
ModelState.AddModelError(String.Empty, "Could not connect with current settings");
|
||||
|
||||
|
||||
return (null,
|
||||
new EditExchangeExternalServiceDataViewModel(viewModel, CcxtExchangeService.GetAvailableExchanges()));
|
||||
}
|
||||
|
||||
return (externalServiceData, null);
|
||||
}
|
||||
|
||||
|
||||
public class EditExchangeExternalServiceDataViewModel : ExchangeExternalServiceData
|
||||
{
|
||||
public SelectList Exchanges { get; set; }
|
||||
|
||||
public EditExchangeExternalServiceDataViewModel(ExchangeExternalServiceData serviceData,
|
||||
IEnumerable<string> exchangeApis)
|
||||
{
|
||||
OverrideUrl = serviceData.OverrideUrl;
|
||||
ExchangeName = serviceData.ExchangeName;
|
||||
PublicKey = serviceData.PublicKey;
|
||||
PassPhrase = serviceData.PassPhrase;
|
||||
PrivateKey = serviceData.PrivateKey;
|
||||
LastCheck = serviceData.LastCheck;
|
||||
PairedDate = serviceData.PairedDate;
|
||||
Exchanges = new SelectList(exchangeApis,
|
||||
ExchangeName);
|
||||
}
|
||||
|
||||
public EditExchangeExternalServiceDataViewModel()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
|
||||
namespace BtcTransmuter.Extension.Exchange.ExternalServices.CcxtExchange
|
||||
{
|
||||
public class ExchangeExternalServiceData
|
||||
{
|
||||
public string PublicKey { get; set; }
|
||||
public string PrivateKey { get; set; }
|
||||
public string PassPhrase { get; set; }
|
||||
public string ExchangeName { get; set; }
|
||||
public string OverrideUrl { get; set; }
|
||||
|
||||
public DateTime? LastCheck { get; set; }
|
||||
public DateTime? PairedDate { get; set; }
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,50 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using BtcTransmuter.Abstractions.ExternalServices;
|
||||
using BtcTransmuter.Data.Entities;
|
||||
using ExchangeSharp;
|
||||
using Pchp.Core;
|
||||
|
||||
namespace BtcTransmuter.Extension.Exchange.ExternalServices.CcxtExchange
|
||||
{
|
||||
public class CcxtExchangeService : BaseExternalService<ExchangeExternalServiceData>
|
||||
{
|
||||
public const string ExchangeServiceType = "CcxtExchangeExternalService";
|
||||
public override string ExternalServiceType => ExchangeServiceType;
|
||||
|
||||
public override string Name => "Ccxt Exchange External Service";
|
||||
public override string Description => "Integrate from a wide variety of cryptocurrency exchanges";
|
||||
public override string ViewPartial => "ViewCcxtExchangeExternalService";
|
||||
protected override string ControllerName => "CcxtExchange";
|
||||
|
||||
|
||||
public CcxtExchangeService() : base()
|
||||
{
|
||||
}
|
||||
|
||||
public CcxtExchangeService(ExternalServiceData data) : base(data)
|
||||
{
|
||||
}
|
||||
|
||||
public static string[] GetAvailableExchanges()
|
||||
{
|
||||
return new ccxt.Exchange._statics().exchanges.GetArray().Values.Select(value => value.AsString(Context.CreateEmpty())).ToArray();
|
||||
}
|
||||
|
||||
|
||||
public ExchangeAPI ConstructClient()
|
||||
{
|
||||
var exchangeInstance = new ccxt.Exchange(Context.CreateEmpty());
|
||||
|
||||
var e = new ccxt.therock(Context.CreateEmpty(),
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task<bool> TestAccess()
|
||||
{
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,43 @@
|
||||
@model BtcTransmuter.Extension.Exchange.ExternalServices.CcxtExchange.CcxtExchangeController.EditExchangeExternalServiceDataViewModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Edit Ccxt Exchange External Service Data";
|
||||
}
|
||||
|
||||
<h2>@ViewData["Title"]</h2>
|
||||
|
||||
|
||||
<form method="post">
|
||||
<div asp-validation-summary="All" class="text-danger"></div>
|
||||
<div class="form-group">
|
||||
<label asp-for="ExchangeName" class="control-label"></label>
|
||||
<select asp-items="Model.Exchanges" asp-for="ExchangeName" class="form-control"></select>
|
||||
<span asp-validation-for="ExchangeName" class="text-danger"></span>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label asp-for="PublicKey" class="control-label"></label>
|
||||
<input asp-for="PublicKey" class="form-control"/>
|
||||
<span asp-validation-for="PublicKey" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="PrivateKey" class="control-label"></label>
|
||||
<input asp-for="PrivateKey" class="form-control"/>
|
||||
<span asp-validation-for="PrivateKey" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="PassPhrase" class="control-label"></label>
|
||||
<input asp-for="PassPhrase" class="form-control"/>
|
||||
<span asp-validation-for="PassPhrase" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="OverrideUrl" class="control-label"></label>
|
||||
<input asp-for="OverrideUrl" class="form-control"/>
|
||||
<span asp-validation-for="OverrideUrl" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="mt-2">
|
||||
|
||||
<button type="submit" class="btn btn-primary">Save</button>
|
||||
<a asp-action="GetServices" asp-controller="ExternalServices" class="btn btn-secondary">Back to recipe</a>
|
||||
</div>
|
||||
</form>
|
||||
@ -0,0 +1,39 @@
|
||||
@using BtcTransmuter.Extension.Exchange.ExternalServices.CcxtExchange
|
||||
@model BtcTransmuter.Data.Entities.ExternalServiceData
|
||||
|
||||
@{
|
||||
var service = new CcxtExchangeService(Model);
|
||||
var data = service.GetData();
|
||||
}
|
||||
|
||||
<dl class="dl-horizontal">
|
||||
<dt>
|
||||
Name
|
||||
</dt>
|
||||
<dd>
|
||||
@service.Name
|
||||
</dd>
|
||||
<dt>
|
||||
Exchange
|
||||
</dt>
|
||||
<dd>
|
||||
@data.ExchangeName
|
||||
</dd>
|
||||
@if (!string.IsNullOrEmpty(data.OverrideUrl))
|
||||
{
|
||||
<dt>
|
||||
OverrideUrl
|
||||
</dt>
|
||||
<dd>
|
||||
@data.OverrideUrl
|
||||
|
||||
</dd>
|
||||
}
|
||||
|
||||
<dt>
|
||||
Last checked
|
||||
</dt>
|
||||
<dd>
|
||||
@(data.LastCheck.HasValue? data.LastCheck.Value.ToString("g"): "Never")
|
||||
</dd>
|
||||
</dl>
|
||||
2417
BtcTransmuter.Extension.Exchange/ccxt-net/PhpLib1.deps.json
Normal file
2417
BtcTransmuter.Extension.Exchange/ccxt-net/PhpLib1.deps.json
Normal file
File diff suppressed because it is too large
Load Diff
7
BtcTransmuter.Tests/PlaceOrderDataActionHandlerTests.cs
Normal file
7
BtcTransmuter.Tests/PlaceOrderDataActionHandlerTests.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace BtcTransmuter.Tests
|
||||
{
|
||||
public class PlaceOrderDataActionHandlerTests
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user