GMX v2 - Trading (#7)
* Move PrivateKeys.cs * Update gitignore * Update gitignore * updt * Extract GmxServiceTests.cs * Refact * update todo * Update code * Fix hashdata * Replace static token hashed datas * Set allowance * Add get orders * Add get orders tests * Add ignore * add close orders * revert * Add get gas limit * Start increasePosition. Todo: Finish GetExecutionFee and estimateGas * little refact * Update gitignore * Fix namespaces and clean repo * Add tests samples * Add execution fee * Add increase position * Handle backtest on the frontend * Add tests * Update increase * Test increase * fix increase * Fix size * Start get position * Update get positions * Fix get position * Update rpc and trade mappers * Finish close position * Fix leverage
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using Managing.Application.Abstractions;
|
||||
using Managing.Application.Abstractions.Repositories;
|
||||
using Managing.Domain.Backtests;
|
||||
using Managing.Infrastructure.Databases.MongoDb;
|
||||
using Managing.Infrastructure.Databases.MongoDb.Abstractions;
|
||||
@@ -35,4 +35,4 @@ public class BacktestRepository : IBacktestRepository
|
||||
{
|
||||
_backtestRepository.InsertOne(MongoMappers.Map(backtest));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
using Managing.Infrastructure.Databases.MongoDb;
|
||||
using Managing.Application.Abstractions.Repositories;
|
||||
using Managing.Domain.Bots;
|
||||
using Managing.Infrastructure.Databases.MongoDb;
|
||||
using Managing.Infrastructure.Databases.MongoDb.Abstractions;
|
||||
using Managing.Infrastructure.Databases.MongoDb.Collections;
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
using InfluxDB.Client.Writes;
|
||||
using InfluxDB.Client.Api.Domain;
|
||||
using InfluxDB.Client.Writes;
|
||||
using Managing.Application.Abstractions.Repositories;
|
||||
using Managing.Core;
|
||||
using Managing.Domain.Candles;
|
||||
using Managing.Infrastructure.Databases.InfluxDb;
|
||||
using Managing.Infrastructure.Databases.InfluxDb.Abstractions;
|
||||
using Managing.Infrastructure.Databases.InfluxDb.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using static Managing.Common.Enums;
|
||||
@@ -30,14 +32,14 @@ public class CandleRepository : ICandleRepository
|
||||
var results = await _influxDbRepository.QueryAsync(async query =>
|
||||
{
|
||||
var flux = $"from(bucket:\"{_priceBucket}\") " +
|
||||
$"|> range(start: {start:s}Z) " +
|
||||
$"|> filter(fn: (r) => r[\"exchange\"] == \"{exchange}\")" +
|
||||
$"|> filter(fn: (r) => r[\"ticker\"] == \"{ticker}\")" +
|
||||
$"|> filter(fn: (r) => r[\"timeframe\"] == \"{timeframe}\")" +
|
||||
$"|> pivot(rowKey:[\"_time\"], columnKey: [\"_field\"], valueColumn: \"_value\")";
|
||||
$"|> range(start: {start:s}Z) " +
|
||||
$"|> filter(fn: (r) => r[\"exchange\"] == \"{exchange}\")" +
|
||||
$"|> filter(fn: (r) => r[\"ticker\"] == \"{ticker}\")" +
|
||||
$"|> filter(fn: (r) => r[\"timeframe\"] == \"{timeframe}\")" +
|
||||
$"|> pivot(rowKey:[\"_time\"], columnKey: [\"_field\"], valueColumn: \"_value\")";
|
||||
|
||||
var prices = await query.QueryAsync<PriceDto>(flux, _influxDbRepository.Organization);
|
||||
return prices.Select(price => PriceHelpers.Map(price)).ToList();
|
||||
return prices.Select(price => PriceHelpers.Map(price)).ToList();
|
||||
});
|
||||
|
||||
return results;
|
||||
@@ -51,13 +53,13 @@ public class CandleRepository : ICandleRepository
|
||||
var results = await _influxDbRepository.QueryAsync(async query =>
|
||||
{
|
||||
var flux = $"from(bucket:\"{_priceBucket}\") " +
|
||||
$"|> range(start: {start:s}Z, stop: now()) " +
|
||||
$"|> filter(fn: (r) => r[\"_measurement\"] == \"price\")" +
|
||||
$"|> filter(fn: (r) => r[\"exchange\"] == \"{exchange}\")" +
|
||||
$"|> filter(fn: (r) => r[\"timeframe\"] == \"{timeframe}\")" +
|
||||
$"|> keep(columns: [\"ticker\"])" +
|
||||
$"|> distinct()";
|
||||
|
||||
$"|> range(start: {start:s}Z, stop: now()) " +
|
||||
$"|> filter(fn: (r) => r[\"_measurement\"] == \"price\")" +
|
||||
$"|> filter(fn: (r) => r[\"exchange\"] == \"{exchange}\")" +
|
||||
$"|> filter(fn: (r) => r[\"timeframe\"] == \"{timeframe}\")" +
|
||||
$"|> keep(columns: [\"ticker\"])" +
|
||||
$"|> distinct()";
|
||||
|
||||
var tickers = new List<Ticker>();
|
||||
var records = await query.QueryAsync(flux, _influxDbRepository.Organization);
|
||||
records.ForEach(table =>
|
||||
@@ -65,7 +67,8 @@ public class CandleRepository : ICandleRepository
|
||||
var fluxRecords = table.Records;
|
||||
fluxRecords.ForEach(fluxRecord =>
|
||||
{
|
||||
tickers.AddItem(MiscExtensions.ParseEnum<Ticker>(fluxRecord.GetValueByKey("ticker").ToString()));
|
||||
tickers.AddItem(
|
||||
MiscExtensions.ParseEnum<Ticker>(fluxRecord.GetValueByKey("ticker").ToString()));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -82,7 +85,7 @@ public class CandleRepository : ICandleRepository
|
||||
PriceDto price = PriceHelpers.Map(candle);
|
||||
write.WriteMeasurement(
|
||||
price,
|
||||
InfluxDB.Client.Api.Domain.WritePrecision.Ns,
|
||||
WritePrecision.Ns,
|
||||
_priceBucket,
|
||||
_influxDbRepository.Organization);
|
||||
});
|
||||
@@ -95,11 +98,11 @@ public class CandleRepository : ICandleRepository
|
||||
var point = PointData.Measurement("");
|
||||
PriceDto price = PriceHelpers.Map(candle);
|
||||
point.Tag("", "");
|
||||
point.Timestamp(price.OpenTime, InfluxDB.Client.Api.Domain.WritePrecision.Ns);
|
||||
point.Timestamp(price.OpenTime, WritePrecision.Ns);
|
||||
write.WritePoint(
|
||||
point,
|
||||
_priceBucket,
|
||||
_influxDbRepository.Organization);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using InfluxDB.Client;
|
||||
|
||||
namespace Managing.Infrastructure.Databases;
|
||||
namespace Managing.Infrastructure.Databases.InfluxDb.Abstractions;
|
||||
|
||||
public interface IInfluxDbRepository
|
||||
{
|
||||
@@ -8,4 +8,4 @@ public interface IInfluxDbRepository
|
||||
|
||||
Task<T> QueryAsync<T>(Func<QueryApi, Task<T>> action);
|
||||
void Write(Action<WriteApi> action);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
namespace Managing.Infrastructure.Databases.Abstractions;
|
||||
namespace Managing.Infrastructure.Databases.InfluxDb.Abstractions;
|
||||
|
||||
public interface IInfluxDbSettings
|
||||
{
|
||||
string Url { get; set; }
|
||||
string Token { get; set; }
|
||||
string Organization { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
using InfluxDB.Client;
|
||||
using Managing.Infrastructure.Databases.Abstractions;
|
||||
using Managing.Infrastructure.Databases.InfluxDb.Abstractions;
|
||||
|
||||
namespace Managing.Infrastructure.Databases.InfluxDb;
|
||||
|
||||
@@ -10,7 +10,7 @@ public class InfluxDbRepository : IInfluxDbRepository
|
||||
public string Organization { get; set; }
|
||||
|
||||
public InfluxDbRepository(IInfluxDbSettings settings)
|
||||
{
|
||||
{
|
||||
_token = settings.Token;
|
||||
_url = settings.Url;
|
||||
Organization = settings.Organization;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using Managing.Infrastructure.Databases.Abstractions;
|
||||
using Managing.Infrastructure.Databases.InfluxDb.Abstractions;
|
||||
|
||||
namespace Managing.Infrastructure.Databases.InfluxDb.Models;
|
||||
|
||||
public class InfluxDbSettings : IInfluxDbSettings
|
||||
{
|
||||
public string Url { get ; set; }
|
||||
public string Url { get; set; }
|
||||
public string Token { get; set; }
|
||||
public string Organization { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
namespace Managing.Infrastructure.Databases.MongoDb
|
||||
namespace Managing.Infrastructure.Databases.MongoDb.Configurations
|
||||
{
|
||||
public interface IManagingDatabaseSettings
|
||||
{
|
||||
string ConnectionString { get; set; }
|
||||
string DatabaseName { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace Managing.Infrastructure.Databases.MongoDb;
|
||||
namespace Managing.Infrastructure.Databases.MongoDb.Configurations;
|
||||
|
||||
public class ManagingDatabaseSettings : IManagingDatabaseSettings
|
||||
{
|
||||
public string ConnectionString { get; set; }
|
||||
public string DatabaseName { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using Managing.Domain.Accounts;
|
||||
using Managing.Domain.Backtests;
|
||||
using Managing.Domain.Bots;
|
||||
using Managing.Domain.Candles;
|
||||
using Managing.Domain.MoneyManagements;
|
||||
using Managing.Domain.Scenarios;
|
||||
|
||||
Reference in New Issue
Block a user