Skip to content

Commit

Permalink
style: format js codes (#332)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xmountaintop authored Sep 15, 2021
1 parent b4fba04 commit 35917d2
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 72 deletions.
6 changes: 3 additions & 3 deletions examples/js/RESTClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class RESTClient {
console.log("using REST API server: ", server);
this.client = axios.create({
baseURL: server,
timeout: 1000
timeout: 1000,
});
}

Expand All @@ -27,7 +27,7 @@ class RESTClient {
console.log("error:", resp.data);
return null;
}
let userInfo = (resp.data as unknown) as UserInfo;
let userInfo = resp.data as unknown as UserInfo;
//console.log('raw', resp.data, 'result', userInfo);
return userInfo;
}
Expand All @@ -44,7 +44,7 @@ class RESTClient {
}
) {
let resp = await this.client.get(`/internal_txs/${user_id}`, {
params: _.pickBy(params, _.identity)
params: _.pickBy(params, _.identity),
});
if (resp.status === 200) {
return resp.data;
Expand Down
18 changes: 11 additions & 7 deletions examples/js/bots/mm_external_price_bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
ORDER_SIDE_BID,
ORDER_SIDE_ASK,
ORDER_TYPE_LIMIT,
VERBOSE
VERBOSE,
} from "../config";
class PriceBotParams {}
class MMByPriceBot {
Expand Down Expand Up @@ -41,8 +41,12 @@ class MMByPriceBot {
// run every second
async tick(balance, oldOrders): Promise<{ reset; orders }> {
const VERBOSE = this.verbose;
const oldAskOrder = oldOrders.orders.find(elem => elem.order_side == "ASK");
const oldBidOrder = oldOrders.orders.find(elem => elem.order_side == "BID");
const oldAskOrder = oldOrders.orders.find(
(elem) => elem.order_side == "ASK"
);
const oldBidOrder = oldOrders.orders.find(
(elem) => elem.order_side == "BID"
);

// put a big buy order and a big sell order
//const price = await getPriceOfCoin(baseCoin, 5);
Expand Down Expand Up @@ -99,7 +103,7 @@ class MMByPriceBot {
}
return {
reset: false,
orders: []
orders: [],
};
}
//lastAskPrice = askPrice;
Expand All @@ -112,19 +116,19 @@ class MMByPriceBot {
order_side: ORDER_SIDE_BID,
order_type: ORDER_TYPE_LIMIT,
amount: bidAmount,
price: bidPrice
price: bidPrice,
};
const ask_order = {
user_id: this.user_id,
market: this.market,
order_side: ORDER_SIDE_ASK,
order_type: ORDER_TYPE_LIMIT,
amount: askAmount,
price: askPrice
price: askPrice,
};
return {
reset: true,
orders: [bid_order, ask_order]
orders: [bid_order, ask_order],
};
}
handleTrade(trade) {}
Expand Down
10 changes: 5 additions & 5 deletions examples/js/bots/run_bots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ import { defaultRESTClient, RESTClient } from "../RESTClient";
import {
defaultClient as defaultGrpcClient,
Client as grpcClient,
defaultClient
defaultClient,
} from "../client";
import { sleep, depositAssets, getPriceOfCoin } from "../util";
import {
ORDER_SIDE_BID,
ORDER_SIDE_ASK,
ORDER_TYPE_LIMIT,
VERBOSE
VERBOSE,
} from "../config";
import {
estimateMarketOrderSell,
estimateMarketOrderBuy,
execMarketOrderAsLimit_Sell,
execMarketOrderAsLimit_Buy,
rebalance,
printBalance
printBalance,
} from "./utils";
import { executeOrders } from "./executor";
async function initUser(): Promise<number> {
Expand All @@ -40,7 +40,7 @@ async function initUser(): Promise<number> {
let resp = await defaultGrpcClient.registerUser({
user_id: 0, // discard in server side
l1_address: acc.ethAddr,
l2_pubkey: acc.bjjPubKey
l2_pubkey: acc.bjjPubKey,
});
const t = Date.now();
console.log("register resp", resp);
Expand Down Expand Up @@ -79,7 +79,7 @@ async function main() {
null,
VERBOSE
);
bot.priceFn = async function(coin: string) {
bot.priceFn = async function (coin: string) {
return await getPriceOfCoin(coin, 5, "coinstats");
};
let count = 0;
Expand Down
14 changes: 7 additions & 7 deletions examples/js/bots/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { defaultRESTClient, RESTClient } from "../RESTClient";
import {
defaultClient as defaultGrpcClient,
Client as grpcClient,
defaultClient
defaultClient,
} from "../client";
import { sleep, depositAssets, getPriceOfCoin } from "../util";
import {
ORDER_SIDE_BID,
ORDER_SIDE_ASK,
ORDER_TYPE_LIMIT,
VERBOSE
VERBOSE,
} from "../config";

// TODO: add a similar function using quoteAmount. "i want to sell some eth to get 5000 usdt"
Expand Down Expand Up @@ -42,7 +42,7 @@ async function estimateMarketOrderSell(
quote: quoteAcc,
avgPrice: quoteAcc / baseAcc,
bestPrice,
worstPrice
worstPrice,
};
//console.log("estimateMarketOrderSell:", estimateResult);
return estimateResult;
Expand Down Expand Up @@ -77,7 +77,7 @@ async function estimateMarketOrderBuy(
quote: quoteAcc,
avgPrice: quoteAcc / tradeAmount,
bestPrice,
worstPrice
worstPrice,
};
//console.log("estimateMarketOrderBuy:", estimateResult);
return estimateResult;
Expand Down Expand Up @@ -182,13 +182,13 @@ async function printBalance(user_id, baseCoin, quoteCoin, market) {
console.log("------- BALANCE1:", {
quote: allQuote,
base: res.quote,
total: allQuote + res.quote
total: allQuote + res.quote,
});
console.log("------- BALANCE2:", {
quote: allQuote,
base: allBase * externalPrice,
total: allQuote + allBase * externalPrice,
totalInB: allQuote / externalPrice + allBase
totalInB: allQuote / externalPrice + allBase,
});
}

Expand All @@ -198,5 +198,5 @@ export {
execMarketOrderAsLimit_Sell,
execMarketOrderAsLimit_Buy,
rebalance,
printBalance
printBalance,
};
28 changes: 14 additions & 14 deletions examples/js/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
ORDER_SIDE_BID,
ORDER_SIDE_ASK,
ORDER_TYPE_LIMIT,
VERBOSE
VERBOSE,
} from "./config";

const file = "../../orchestra/proto/exchange/matchengine.proto";
Expand All @@ -14,7 +14,7 @@ const load = {
longs: String,
enums: String,
defaults: true,
oneofs: true
oneofs: true,
};

function fullPrec(d, p): Decimal {
Expand Down Expand Up @@ -57,7 +57,7 @@ class Client {
const allBalances = (
await this.client.BalanceQuery({ user_id: user_id, assets: [asset] })
).balances;
const balance = allBalances.find(item => item.asset_id == asset);
const balance = allBalances.find((item) => item.asset_id == asset);
let available = new Decimal(balance.available);
let frozen = new Decimal(balance.frozen);
let total = available.add(frozen);
Expand All @@ -76,7 +76,7 @@ class Client {
business_id,
delta,
detail: JSON.stringify(detail),
signature: ""
signature: "",
});
}
roundOrderInput(market, amount, price) {
Expand Down Expand Up @@ -130,7 +130,7 @@ class Client {
tokenSell,
tokenBuy,
totalSell,
totalBuy
totalBuy,
});
signature = this.accounts.get(user_id).signHashPacked(orderInput.hash());
}
Expand All @@ -143,7 +143,7 @@ class Client {
price: priceRounded,
taker_fee,
maker_fee,
signature
signature,
};
}
async orderPut(
Expand Down Expand Up @@ -183,7 +183,7 @@ class Client {
amount,
price,
taker_fee,
maker_fee
maker_fee,
} = o;
order_reqs.push(
await this.createOrder(
Expand All @@ -201,7 +201,7 @@ class Client {
return await this.client.batchOrderPut({
market,
reset,
orders: order_reqs
orders: order_reqs,
});
}

Expand Down Expand Up @@ -233,7 +233,7 @@ class Client {
}
let resp = (await this.client.MarketSummary({ markets })).market_summaries;
if (typeof req === "string") {
return resp.find(item => item.name === req);
return resp.find((item) => item.name === req);
}
return resp;
}
Expand Down Expand Up @@ -265,7 +265,7 @@ class Client {
amount: delta,
from,
from_nonce: nonce,
to
to,
});
signature = this.accounts.get(user_id).signHashPacked(tx.hash());
}
Expand All @@ -275,7 +275,7 @@ class Client {
asset,
delta,
memo,
signature
signature,
};
}

Expand All @@ -287,7 +287,7 @@ class Client {
token_id: this.assets.get(asset).inner_id,
amount: delta,
nonce: 0,
old_balance: 0 // TODO: Update `old_balance` with precision.
old_balance: 0, // TODO: Update `old_balance` with precision.
});
signature = this.accounts.get(account_id).signHashPacked(tx.hash());
}
Expand All @@ -298,7 +298,7 @@ class Client {
business_id,
delta: -delta,
detail: JSON.stringify(detail),
signature: signature
signature: signature,
};
}

Expand Down Expand Up @@ -340,7 +340,7 @@ class Client {
return await this.client.RegisterUser({
user_id: user.id || user.user_id, // legacy reasons
l1_address: user.l1_address,
l2_pubkey: user.l2_pubkey
l2_pubkey: user.l2_pubkey,
});
}
}
Expand Down
6 changes: 3 additions & 3 deletions examples/js/kafka_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class KafkaConsumer {
const brokers = process.env.KAFKA_BROKERS;
const kafka = new Kafka.Kafka({
brokers: (brokers || "127.0.0.1:9092").split(","),
logLevel: Kafka.logLevel.WARN
logLevel: Kafka.logLevel.WARN,
});
const consumer = kafka.consumer({ groupId: "test-group" });
this.consumer = consumer;
Expand All @@ -31,11 +31,11 @@ export class KafkaConsumer {
partition,
offset: message.offset,
key: message.key.toString(),
value: message.value.toString()
value: message.value.toString(),
});
}
this.messages.get(topic).push(message.value.toString());
}
},
});
}
Reset() {
Expand Down
8 changes: 4 additions & 4 deletions examples/js/multi_market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async function initAccounts() {
await client.client.RegisterUser({
userId,
l1_address: acc.ethAddr,
l2_pubkey: acc.bjjPubKey
l2_pubkey: acc.bjjPubKey,
});
}

Expand All @@ -32,10 +32,10 @@ async function orderTest() {
"ETH_USDT",
"LINK_USDT",
"MATIC_USDT",
"UNI_USDT"
"UNI_USDT",
]);
let orders = await Promise.all(
markets.map(market =>
markets.map((market) =>
client
.orderPut(
userId,
Expand All @@ -47,7 +47,7 @@ async function orderTest() {
fee,
fee
)
.then(o => [market, o.id])
.then((o) => [market, o.id])
)
);
console.log(orders);
Expand Down
2 changes: 1 addition & 1 deletion examples/js/print_orders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async function main() {
assert.equal(ticker.quote_volume, 4.4);
}
}
main().catch(function(e) {
main().catch(function (e) {
console.log(e);
process.exit(1);
//throw e;
Expand Down
Loading

0 comments on commit 35917d2

Please sign in to comment.