|
|
@@ -10,6 +10,7 @@ const apiKey = document.querySelector('#api-key') as HTMLInputElement;
|
|
|
if (storedApiKey)
|
|
|
apiKey.value = storedApiKey;
|
|
|
}
|
|
|
+const xitAct = document.querySelector('textarea#xit-act') as HTMLTextAreaElement;
|
|
|
document.querySelector('#fetch')!.addEventListener('click', async () => {
|
|
|
const supplyForDays = parseInt((document.querySelector('#days') as HTMLInputElement).value, 10);
|
|
|
const cx = (document.querySelector('#cx') as HTMLInputElement).value;
|
|
|
@@ -18,6 +19,9 @@ document.querySelector('#fetch')!.addEventListener('click', async () => {
|
|
|
localStorage.setItem('fio-username', username.value);
|
|
|
localStorage.setItem('fio-api-key', apiKey.value);
|
|
|
});
|
|
|
+document.querySelector('#copy-xit-act')!.addEventListener('click', () => {
|
|
|
+ navigator.clipboard.writeText(xitAct.value);
|
|
|
+});
|
|
|
setupPopover();
|
|
|
|
|
|
async function calculate(username: string, apiKey: string, supplyForDays: number, cx: string): Promise<void> {
|
|
|
@@ -59,9 +63,11 @@ async function calculate(username: string, apiKey: string, supplyForDays: number
|
|
|
}
|
|
|
materials.sort((a, b) => b.savings - a.savings);
|
|
|
|
|
|
+ const toBuy: Record<string, number> = {};
|
|
|
+ const priceLimits: Record<string, number> = {};
|
|
|
const tbody = document.querySelector('tbody')!;
|
|
|
tbody.innerHTML = '';
|
|
|
- const format= new Intl.NumberFormat(undefined, {maximumFractionDigits: 0}).format;
|
|
|
+ const format = new Intl.NumberFormat(undefined, {maximumFractionDigits: 0}).format;
|
|
|
for (const m of materials) {
|
|
|
const tr = document.createElement('tr');
|
|
|
const buyAmount = Math.max(m.amount - m.bids - m.have, 0);
|
|
|
@@ -74,11 +80,27 @@ async function calculate(username: string, apiKey: string, supplyForDays: number
|
|
|
<td>${format(m.spread)}</td>
|
|
|
<td>${format(m.savings)}</td>
|
|
|
`;
|
|
|
- if (m.bids === 0 && buyAmount > 0)
|
|
|
- tr.children[2].classList.add('red');
|
|
|
+ if (buyAmount > 0) {
|
|
|
+ if (m.bids === 0)
|
|
|
+ tr.children[2].classList.add('red');
|
|
|
+ toBuy[m.ticker] = buyAmount;
|
|
|
+ const bid = prices.get(m.ticker)!.Bid!;
|
|
|
+ const epsilon = 10 ** (Math.floor(Math.log10(bid)) - 2);
|
|
|
+ const limit = bid + 2 * epsilon;
|
|
|
+ priceLimits[m.ticker] = limit;
|
|
|
+ }
|
|
|
tbody.appendChild(tr);
|
|
|
}
|
|
|
|
|
|
+ xitAct.value = JSON.stringify({
|
|
|
+ 'actions': [
|
|
|
+ {'name': 'BuyItems', 'type': 'CX Buy', 'group': 'A1', 'exchange': 'IC1',
|
|
|
+ 'priceLimits': priceLimits, 'buyPartial': true, 'allowUnfilled': true, 'useCXInv': false},
|
|
|
+ ],
|
|
|
+ 'global': {'name': `buy orders for ${supplyForDays} days`},
|
|
|
+ 'groups': [{'type': 'Manual', 'name': 'A1', 'materials': toBuy}],
|
|
|
+ });
|
|
|
+
|
|
|
// deposits of current bids
|
|
|
orders.sort((a, b) => (b.Limit * b.Amount) - (a.Limit * a.Amount));
|
|
|
for (const order of orders) {
|