Update completed implementation

This commit is contained in:
Lev
2021-06-13 13:46:04 -05:00
parent 7a913d8d4b
commit d74223f92a
6 changed files with 36 additions and 11 deletions

View File

@ -1,4 +1,4 @@
2020/03/17 17:01:24.884492,ETH/BTC,bid,0.021873a78,a.44564869
2020/03/17 17:01:24.884492,ETH/BTC,bid,0.02187a78,2.44564869
2020/03/17 17:01:24.884492,ETH/BTC,bid,0.02187308,7.44564869
2020/03/17 17:01:24.884492,ETH/BTC,bid,0.02187307,3.467434
2020/03/17 17:01:24.884492,ETH/BTC,bid,0.02187305,6.85567013
@ -202,11 +202,7 @@
2020/03/17 17:01:24.884492,BTC/USDT,bid,5323.83418,0.001
2020/03/17 17:01:24.884492,BTC/USDT,bid,5323.25277012,1.97008162
2020/03/17 17:01:24.884492,BTC/USDT,bid,5321.,3.35
2020/03/17 17:01:24.884492,BTC/USDT,bid,5319.450228,0.00020075
2020/03/17 17:01:24.884492,BTC/USDT,bid,5315.6477491,0.00027634
2020/03/17 17:01:24.884492,BTC/USDT,bid,5315.22320561,0.0064523
2020/03/17 17:01:24.884492,BTC/USDT,bid,5314.15443661,0.000268
@ -265,11 +261,7 @@
2020/03/17 17:01:24.884492,BTC/USDT,ask,5396.42871506,14.1318
2020/03/17 17:01:24.884492,BTC/USDT,ask,5400.,0.14371419
2020/03/17 17:01:24.884492,BTC/USDT,ask,5400.33151632,0.0384
2020/03/17 17:01:24.884492,BTC/USDT,ask,5405.41766912,0.69895055
2020/03/17 17:01:24.884492,BTC/USDT,ask,5405.41766915,0.00423615
2020/03/17 17:01:24.884492,BTC/USDT,ask,5406.30673519,0.01366
2020/03/17 17:01:24.884492,BTC/USDT,ask,5406.52042159,2.92760636

1 2020/03/17 17:01:24.884492 ETH/BTC bid 0.021873a78 0.02187a78 a.44564869 2.44564869
2 2020/03/17 17:01:24.884492 ETH/BTC bid 0.02187308 7.44564869
3 2020/03/17 17:01:24.884492 ETH/BTC bid 0.02187307 3.467434
4 2020/03/17 17:01:24.884492 ETH/BTC bid 0.02187305 6.85567013
202 2020/03/17 17:01:24.884492 BTC/USDT bid 5323.83418 0.001
203 2020/03/17 17:01:24.884492 BTC/USDT bid 5323.25277012 1.97008162
204 2020/03/17 17:01:24.884492 BTC/USDT bid 5321. 3.35
2020/03/17 17:01:24.884492 BTC/USDT bid 5319.450228 0.00020075
2020/03/17 17:01:24.884492 BTC/USDT bid 5315.6477491 0.00027634
205 2020/03/17 17:01:24.884492 BTC/USDT bid 5315.22320561 5319.450228 0.0064523 0.00020075
2020/03/17 17:01:24.884492 BTC/USDT bid 5314.15443661 0.000268
2020/03/17 17:01:24.884492 BTC/USDT bid 5309.56705166 0.00020075
206 2020/03/17 17:01:24.884492 BTC/USDT bid 5308.704103 5315.6477491 0.00161787 0.00027634
207 2020/03/17 17:01:24.884492 BTC/USDT bid 5307. 5315.22320561 0.00018862 0.0064523
208 2020/03/17 17:01:24.884492 BTC/USDT bid 5306.82904643 5314.15443661 0.01884365 0.000268
261 2020/03/17 17:01:24.884492 BTC/USDT ask 5405.41766915 5396.42871506 0.00423615 14.1318
262 2020/03/17 17:01:24.884492 BTC/USDT ask 5406.30673519 5400. 0.01366 0.14371419
263 2020/03/17 17:01:24.884492 BTC/USDT ask 5406.52042159 5400.33151632 2.92760636 0.0384
2020/03/17 17:01:24.884492 BTC/USDT ask 5408.85229981 0.0064523
2020/03/17 17:01:24.884492 BTC/USDT ask 5409.92702531 0.00762601
264 2020/03/17 17:01:24.884492 BTC/USDT ask 5411.99597199 5405.41766912 0.0074 0.69895055
2020/03/17 17:01:24.884492 BTC/USDT ask 5412. 0.005425
2020/03/17 17:01:24.884492 BTC/USDT ask 5413.10527511 0.00923684
265 2020/03/17 17:01:24.884492 BTC/USDT ask 5414. 5405.41766915 0.00018766 0.00423615
266 2020/03/17 17:01:24.884492 BTC/USDT ask 5418.51724799 5406.30673519 0.00072134 0.01366
267 2020/03/17 17:01:24.884492 BTC/USDT ask 5429.63426442 5406.52042159 0.0384 2.92760636

View File

@ -159,6 +159,10 @@ void MerkelMain::gotoNextTimeframe()
for (OrderBookEntry& sale : sales)
{
std::cout << "Sale price: " << sale.price << " amount " << sale.amount << std::endl;
if(sale.username == "simuser")
{
wallet.processSale(sale);
}
}
}
currentTime = orderBook.getNextTime(currentTime);

View File

@ -133,7 +133,7 @@ std::vector<OrderBookEntry> OrderBook::matchAsksToBids(std::string product, std:
// if bid.price >= ask.price # we have a match
if (bid.price >= ask.price)
{
std::cout << "bid price is right " << std::endl;
//std::cout << "bid price is right " << std::endl;
OrderBookEntry sale{ask.price, 0, timestamp, product, OrderBookType::asksale};
OrderBookType type = OrderBookType::asksale;
if(bid.username == "simuser")
@ -183,7 +183,7 @@ std::vector<OrderBookEntry> OrderBook::matchAsksToBids(std::string product, std:
// if bid.amount < ask.amount # bid is completely gone, slice the ask
if (bid.amount < ask.amount)
if (bid.amount < ask.amount && bid.amount != 0)
{
// sale.amount = bid.amount
sale.amount = bid.amount;

View File

@ -89,4 +89,30 @@ bool Wallet::canFulfillOrder(OrderBookEntry order)
return containsCurrency(currency, amount);
}
return false;
}
void Wallet::processSale(OrderBookEntry& sale)
{
std::vector<std::string> currs = CSVReader::tokenise(sale.product, '/');
// ask
if(sale.orderType == OrderBookType::asksale)
{
double outAmount = sale.amount;
std::string outCurrency = currs[0];
double incAmount = sale.amount * sale.price;
std::string incCurrency = currs[1];
currencies[incCurrency] += incAmount;
currencies[outCurrency] -= outAmount;
}
if(sale.orderType == OrderBookType::bidsale)
{
double incAmount = sale.amount;
std::string incCurrency = currs[0];
double outAmount = sale.amount * sale.price;
std::string outCurrency = currs[1];
currencies[incCurrency] += incAmount;
currencies[outCurrency] -= outAmount;
}
}

View File

@ -20,6 +20,9 @@ class Wallet
/** check if the wallet can cope with the ask or bid */
bool canFulfillOrder(OrderBookEntry order);
/** update the contents of the wallet * assumes the order was amade by the owner of the wallet */
void processSale(OrderBookEntry& sale);
/** generate a string representation of the wallet */
std::string toString();