Update completed implementation
This commit is contained in:
@ -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
|
||||
|
||||
|
@ -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);
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
@ -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();
|
||||
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user