Skip to content

Commit

Permalink
Merge pull request #11 from moconnell/small-delta
Browse files Browse the repository at this point in the history
Small delta
  • Loading branch information
moconnell authored Dec 19, 2021
2 parents 04f9664 + cd382bd commit fe75333
Show file tree
Hide file tree
Showing 17 changed files with 765 additions and 22 deletions.
3 changes: 1 addition & 2 deletions src/YoloAbstractions/Config/YoloConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public class YoloConfig
public decimal? NominalCash { get; init; }
public AssetPermissions AssetPermissions { get; init; } = AssetPermissions.SpotAndPerp;
public string BaseAsset { get; init; }
public RebalanceMode RebalanceMode { get; init; } =
RebalanceMode.Slow;
public RebalanceMode RebalanceMode { get; init; } = RebalanceMode.Slow;
public decimal SpreadSplit { get; init; } = 0.5m;
}
5 changes: 4 additions & 1 deletion src/YoloAbstractions/Trade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ public record Trade(
AssetType AssetType,
decimal Amount,
decimal? LimitPrice = null,
DateTime? Expiry = null);
DateTime? Expiry = null)
{
public bool IsTradeable => Amount != 0;
}
1 change: 1 addition & 0 deletions src/YoloBroker.Ftx/Config/FtxConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ public class FtxConfig
public string ApiKey { get; init; }
public string Secret { get; init; }
public string BaseAddress { get; init; }
public bool? PostOnly { get; init; }
public string? SubAccount { get; init; }
}
5 changes: 5 additions & 0 deletions src/YoloBroker.Ftx/FtxBroker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ public FtxBroker(FtxConfig config)
BaseAddress = config.BaseAddress,
SubaccountName = config.SubAccount
});

PostOnly = config.PostOnly;
}

private bool? PostOnly { get; }

public void Dispose()
{
Expand All @@ -69,6 +73,7 @@ public async IAsyncEnumerable<TradeResult> PlaceTradesAsync(
orderType,
quantity,
trade.LimitPrice,
postOnly: PostOnly,
ct: ct);

yield return new TradeResult(
Expand Down
1 change: 1 addition & 0 deletions src/YoloKonsole/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"FTX": {
"ApiKey": "",
"Secret": "",
"PostOnly": true,
"BaseAddress": "https://ftx.com/api",
"SubAccount": ""
}
Expand Down
10 changes: 10 additions & 0 deletions src/YoloTrades/LoggerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,14 @@ public static partial void WithinTradeBuffer(
decimal currentWeight,
decimal constrainedTargetWeight,
decimal delta);

[LoggerMessage(
EventId = TradeEventIds.DeltaTooSmall,
Level = LogLevel.Information,
Message =
"({Token}): no action - delta too small to trade (delta: {Delta:0.0000})")]
public static partial void DeltaTooSmall(
this ILogger logger,
string token,
decimal delta);
}
15 changes: 11 additions & 4 deletions src/YoloTrades/TradeFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,12 @@ IEnumerable<Trade> RebalancePositions(Weight w)
var currentProjectedPosition = projectedPositions[trade.AssetName];
var newProjectedPosition = currentProjectedPosition + trade;
projectedPositions[trade.AssetName] = newProjectedPosition;
yield return trade;
if (trade.IsTradeable)
yield return trade;
else
{
_logger.DeltaTooSmall(token, remainingDelta);
}
remainingDelta = remainingDeltaPostTrade;
}
}
Expand Down Expand Up @@ -205,16 +210,18 @@ AssetType.Spot when weight + remainingDelta < 0 &&
var factor = isBuy ? SpreadSplit : 1 - SpreadSplit;
var spread = market.Ask!.Value - market.Bid!.Value;
var rawLimitPrice = market.Bid!.Value + spread * factor;
var limitPrice = Math.Floor(rawLimitPrice / market.PriceStep) * market.PriceStep;
var limitPriceSteps = rawLimitPrice / market.PriceStep;
var limitPrice = (isBuy ? Math.Floor(limitPriceSteps) : Math.Ceiling(limitPriceSteps)) * market.PriceStep;
var trade = new Trade(market.Name, market.AssetType, size, limitPrice);

_logger.GeneratedTrade(token, delta, trade);
if (trade.IsTradeable)
_logger.GeneratedTrade(token, delta, trade);

remainingDelta -= delta;

yield return (trade, remainingDelta);

if (restart)
if (restart || remainingDelta == 0)
{
break;
}
Expand Down
1 change: 1 addition & 0 deletions src/YoloTrades/WellKnown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public static class TradeEventIds
internal const int WithinTradeBuffer = 110;
internal const int GeneratedTrade = 111;
internal const int MarketPositions = 112;
internal const int DeltaTooSmall = 113;
internal const int NoMarkets = 151;
internal const int MultiplePositions = 152;
internal const int NoAsk = 152;
Expand Down
Loading

0 comments on commit fe75333

Please sign in to comment.