2459 lines
49 KiB
JavaScript
2459 lines
49 KiB
JavaScript
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const Organizations = db.organizations;
|
|
|
|
const Instruments = db.instruments;
|
|
|
|
const Datasets = db.datasets;
|
|
|
|
const Candles = db.candles;
|
|
|
|
const Accounts = db.accounts;
|
|
|
|
const ReplaySessions = db.replay_sessions;
|
|
|
|
const Trades = db.trades;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const OrganizationsData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "Marie Curie",
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "Grace Hopper",
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"name": "Marie Curie",
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const InstrumentsData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"symbol": "EURUSD",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"name": "Euro / US Dollar",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"pip_size": 0.0001,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"quote_currency": "USD",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"symbol": "GBPUSD",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"name": "British Pound / US Dollar",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"pip_size": 0.0001,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"quote_currency": "USD",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"symbol": "USDJPY",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"name": "US Dollar / Japanese Yen",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"pip_size": 0.01,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"quote_currency": "JPY",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const DatasetsData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"title": "EURUSD 2021 January 1m",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"description": "One month of EURUSD tick-aligned 1 minute candles for January 2021",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"timeframe": "5m",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"source": "CSV Upload",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"candles_count": 44640,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "files" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"title": "GBPUSD 2020 5m sample",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"description": "Representative 5 minute sample for GBPUSD 2020",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"timeframe": "1m",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"source": "ForexTick",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"candles_count": 105120,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "files" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
"title": "USDJPY 2022 15m",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"description": "USDJPY 15 minute candles for 2022 full year",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"timeframe": "1m",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"source": "HistoricalProvider",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"candles_count": 35040,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "files" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const CandlesData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"index": 0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"time": new Date('2021-01-01T00:00:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"time_string": "2021-01-01 00:00",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"open": 1.221,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"high": 1.2215,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"low": 1.2205,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"close": 1.2212,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"volume": 120.5,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"index": 1,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"time": new Date('2021-01-01T00:01:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"time_string": "2021-01-01 00:01",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"open": 1.2212,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"high": 1.2218,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"low": 1.221,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"close": 1.2216,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"volume": 98.3,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"index": 2,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"time": new Date('2021-01-01T00:02:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"time_string": "2021-01-01 00:02",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"open": 1.2216,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"high": 1.222,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"low": 1.2214,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"close": 1.2219,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"volume": 130.0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const AccountsData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"name": "Alice Main",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"base_currency": "USD",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"balance": 10000.0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"equity": 10000.0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"risk_per_trade_percent": 1.0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"name": "Bob Research",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"base_currency": "USD",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"balance": 50000.0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"equity": 49820.5,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"risk_per_trade_percent": 0.5,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"name": "Carol Demo",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"base_currency": "USD",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"balance": 2500.0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"equity": 2500.0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"risk_per_trade_percent": 2.0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const ReplaySessionsData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"title": "Alice EURUSD Jan 1m Session",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"started_at": new Date('2021-02-01T09:30:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"current_index": 120,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"playback_speed": "10x",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_playing": true,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"title": "Bob GBPUSD Quick Scan",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"started_at": new Date('2020-06-01T08:00:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"current_index": 540,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"playback_speed": "1x",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_playing": true,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"title": "Carol Daily USDCAD Review",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"started_at": new Date('2021-01-05T00:00:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"current_index": 15,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"playback_speed": "10x",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_playing": false,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const TradesData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"entry_index": 2,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"entry_time": new Date('2021-01-01T00:02:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"entry_price": 1.2219,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"side": "long",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"stop_loss_price": 1.2205,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"take_profit_price": 1.224,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"size": 10000,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "closed",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"exit_index": 7,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"exit_time": new Date('2021-01-01T00:07:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"exit_price": 1.2226,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"pnl": 70.0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"label": "Alice demo long",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"entry_index": 10,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"entry_time": new Date('2020-06-01T00:50:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"entry_price": 1.2515,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"side": "long",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"stop_loss_price": 1.253,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"take_profit_price": 1.247,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"size": 50000,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "open",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"exit_index": 15,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"exit_time": new Date('2020-06-01T01:15:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"exit_price": 1.247,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"pnl": 2250.0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"label": "Bob breakout short",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"entry_index": 0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"entry_time": new Date('2021-01-01T00:00:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"entry_price": 1.2725,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"side": "long",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"stop_loss_price": 1.268,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"take_profit_price": 1.28,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"size": 1000,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "closed",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"exit_index": 9,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"exit_time": new Date('2020-01-01T00:00:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"exit_price": 2.68,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"pnl": 0.0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"label": "Carol swing trial",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
|
|
|
|
|
|
async function associateUserWithOrganization() {
|
|
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const User0 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (User0?.setOrganization)
|
|
{
|
|
await
|
|
User0.
|
|
setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const User1 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (User1?.setOrganization)
|
|
{
|
|
await
|
|
User1.
|
|
setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const User2 = await Users.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (User2?.setOrganization)
|
|
{
|
|
await
|
|
User2.
|
|
setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateInstrumentWithOrganization() {
|
|
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Instrument0 = await Instruments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (Instrument0?.setOrganization)
|
|
{
|
|
await
|
|
Instrument0.
|
|
setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Instrument1 = await Instruments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (Instrument1?.setOrganization)
|
|
{
|
|
await
|
|
Instrument1.
|
|
setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Instrument2 = await Instruments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (Instrument2?.setOrganization)
|
|
{
|
|
await
|
|
Instrument2.
|
|
setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateDatasetWithInstrument() {
|
|
|
|
const relatedInstrument0 = await Instruments.findOne({
|
|
offset: Math.floor(Math.random() * (await Instruments.count())),
|
|
});
|
|
const Dataset0 = await Datasets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (Dataset0?.setInstrument)
|
|
{
|
|
await
|
|
Dataset0.
|
|
setInstrument(relatedInstrument0);
|
|
}
|
|
|
|
const relatedInstrument1 = await Instruments.findOne({
|
|
offset: Math.floor(Math.random() * (await Instruments.count())),
|
|
});
|
|
const Dataset1 = await Datasets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (Dataset1?.setInstrument)
|
|
{
|
|
await
|
|
Dataset1.
|
|
setInstrument(relatedInstrument1);
|
|
}
|
|
|
|
const relatedInstrument2 = await Instruments.findOne({
|
|
offset: Math.floor(Math.random() * (await Instruments.count())),
|
|
});
|
|
const Dataset2 = await Datasets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (Dataset2?.setInstrument)
|
|
{
|
|
await
|
|
Dataset2.
|
|
setInstrument(relatedInstrument2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateDatasetWithOrganization() {
|
|
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Dataset0 = await Datasets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (Dataset0?.setOrganization)
|
|
{
|
|
await
|
|
Dataset0.
|
|
setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Dataset1 = await Datasets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (Dataset1?.setOrganization)
|
|
{
|
|
await
|
|
Dataset1.
|
|
setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Dataset2 = await Datasets.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (Dataset2?.setOrganization)
|
|
{
|
|
await
|
|
Dataset2.
|
|
setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateCandleWithDataset() {
|
|
|
|
const relatedDataset0 = await Datasets.findOne({
|
|
offset: Math.floor(Math.random() * (await Datasets.count())),
|
|
});
|
|
const Candle0 = await Candles.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (Candle0?.setDataset)
|
|
{
|
|
await
|
|
Candle0.
|
|
setDataset(relatedDataset0);
|
|
}
|
|
|
|
const relatedDataset1 = await Datasets.findOne({
|
|
offset: Math.floor(Math.random() * (await Datasets.count())),
|
|
});
|
|
const Candle1 = await Candles.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (Candle1?.setDataset)
|
|
{
|
|
await
|
|
Candle1.
|
|
setDataset(relatedDataset1);
|
|
}
|
|
|
|
const relatedDataset2 = await Datasets.findOne({
|
|
offset: Math.floor(Math.random() * (await Datasets.count())),
|
|
});
|
|
const Candle2 = await Candles.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (Candle2?.setDataset)
|
|
{
|
|
await
|
|
Candle2.
|
|
setDataset(relatedDataset2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateCandleWithOrganization() {
|
|
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Candle0 = await Candles.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (Candle0?.setOrganization)
|
|
{
|
|
await
|
|
Candle0.
|
|
setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Candle1 = await Candles.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (Candle1?.setOrganization)
|
|
{
|
|
await
|
|
Candle1.
|
|
setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Candle2 = await Candles.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (Candle2?.setOrganization)
|
|
{
|
|
await
|
|
Candle2.
|
|
setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateAccountWithUser() {
|
|
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Account0 = await Accounts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (Account0?.setUser)
|
|
{
|
|
await
|
|
Account0.
|
|
setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Account1 = await Accounts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (Account1?.setUser)
|
|
{
|
|
await
|
|
Account1.
|
|
setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Account2 = await Accounts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (Account2?.setUser)
|
|
{
|
|
await
|
|
Account2.
|
|
setUser(relatedUser2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateAccountWithOrganization() {
|
|
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Account0 = await Accounts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (Account0?.setOrganization)
|
|
{
|
|
await
|
|
Account0.
|
|
setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Account1 = await Accounts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (Account1?.setOrganization)
|
|
{
|
|
await
|
|
Account1.
|
|
setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Account2 = await Accounts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (Account2?.setOrganization)
|
|
{
|
|
await
|
|
Account2.
|
|
setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateReplaySessionWithUser() {
|
|
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const ReplaySession0 = await ReplaySessions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (ReplaySession0?.setUser)
|
|
{
|
|
await
|
|
ReplaySession0.
|
|
setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const ReplaySession1 = await ReplaySessions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (ReplaySession1?.setUser)
|
|
{
|
|
await
|
|
ReplaySession1.
|
|
setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const ReplaySession2 = await ReplaySessions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (ReplaySession2?.setUser)
|
|
{
|
|
await
|
|
ReplaySession2.
|
|
setUser(relatedUser2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function associateReplaySessionWithDataset() {
|
|
|
|
const relatedDataset0 = await Datasets.findOne({
|
|
offset: Math.floor(Math.random() * (await Datasets.count())),
|
|
});
|
|
const ReplaySession0 = await ReplaySessions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (ReplaySession0?.setDataset)
|
|
{
|
|
await
|
|
ReplaySession0.
|
|
setDataset(relatedDataset0);
|
|
}
|
|
|
|
const relatedDataset1 = await Datasets.findOne({
|
|
offset: Math.floor(Math.random() * (await Datasets.count())),
|
|
});
|
|
const ReplaySession1 = await ReplaySessions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (ReplaySession1?.setDataset)
|
|
{
|
|
await
|
|
ReplaySession1.
|
|
setDataset(relatedDataset1);
|
|
}
|
|
|
|
const relatedDataset2 = await Datasets.findOne({
|
|
offset: Math.floor(Math.random() * (await Datasets.count())),
|
|
});
|
|
const ReplaySession2 = await ReplaySessions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (ReplaySession2?.setDataset)
|
|
{
|
|
await
|
|
ReplaySession2.
|
|
setDataset(relatedDataset2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateReplaySessionWithOrganization() {
|
|
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const ReplaySession0 = await ReplaySessions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (ReplaySession0?.setOrganization)
|
|
{
|
|
await
|
|
ReplaySession0.
|
|
setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const ReplaySession1 = await ReplaySessions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (ReplaySession1?.setOrganization)
|
|
{
|
|
await
|
|
ReplaySession1.
|
|
setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const ReplaySession2 = await ReplaySessions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (ReplaySession2?.setOrganization)
|
|
{
|
|
await
|
|
ReplaySession2.
|
|
setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateTradeWithAccount() {
|
|
|
|
const relatedAccount0 = await Accounts.findOne({
|
|
offset: Math.floor(Math.random() * (await Accounts.count())),
|
|
});
|
|
const Trade0 = await Trades.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (Trade0?.setAccount)
|
|
{
|
|
await
|
|
Trade0.
|
|
setAccount(relatedAccount0);
|
|
}
|
|
|
|
const relatedAccount1 = await Accounts.findOne({
|
|
offset: Math.floor(Math.random() * (await Accounts.count())),
|
|
});
|
|
const Trade1 = await Trades.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (Trade1?.setAccount)
|
|
{
|
|
await
|
|
Trade1.
|
|
setAccount(relatedAccount1);
|
|
}
|
|
|
|
const relatedAccount2 = await Accounts.findOne({
|
|
offset: Math.floor(Math.random() * (await Accounts.count())),
|
|
});
|
|
const Trade2 = await Trades.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (Trade2?.setAccount)
|
|
{
|
|
await
|
|
Trade2.
|
|
setAccount(relatedAccount2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function associateTradeWithDataset() {
|
|
|
|
const relatedDataset0 = await Datasets.findOne({
|
|
offset: Math.floor(Math.random() * (await Datasets.count())),
|
|
});
|
|
const Trade0 = await Trades.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (Trade0?.setDataset)
|
|
{
|
|
await
|
|
Trade0.
|
|
setDataset(relatedDataset0);
|
|
}
|
|
|
|
const relatedDataset1 = await Datasets.findOne({
|
|
offset: Math.floor(Math.random() * (await Datasets.count())),
|
|
});
|
|
const Trade1 = await Trades.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (Trade1?.setDataset)
|
|
{
|
|
await
|
|
Trade1.
|
|
setDataset(relatedDataset1);
|
|
}
|
|
|
|
const relatedDataset2 = await Datasets.findOne({
|
|
offset: Math.floor(Math.random() * (await Datasets.count())),
|
|
});
|
|
const Trade2 = await Trades.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (Trade2?.setDataset)
|
|
{
|
|
await
|
|
Trade2.
|
|
setDataset(relatedDataset2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateTradeWithOrganization() {
|
|
|
|
const relatedOrganization0 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Trade0 = await Trades.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (Trade0?.setOrganization)
|
|
{
|
|
await
|
|
Trade0.
|
|
setOrganization(relatedOrganization0);
|
|
}
|
|
|
|
const relatedOrganization1 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Trade1 = await Trades.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (Trade1?.setOrganization)
|
|
{
|
|
await
|
|
Trade1.
|
|
setOrganization(relatedOrganization1);
|
|
}
|
|
|
|
const relatedOrganization2 = await Organizations.findOne({
|
|
offset: Math.floor(Math.random() * (await Organizations.count())),
|
|
});
|
|
const Trade2 = await Trades.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (Trade2?.setOrganization)
|
|
{
|
|
await
|
|
Trade2.
|
|
setOrganization(relatedOrganization2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await Organizations.bulkCreate(OrganizationsData);
|
|
|
|
|
|
|
|
|
|
await Instruments.bulkCreate(InstrumentsData);
|
|
|
|
|
|
|
|
|
|
await Datasets.bulkCreate(DatasetsData);
|
|
|
|
|
|
|
|
|
|
await Candles.bulkCreate(CandlesData);
|
|
|
|
|
|
|
|
|
|
await Accounts.bulkCreate(AccountsData);
|
|
|
|
|
|
|
|
|
|
await ReplaySessions.bulkCreate(ReplaySessionsData);
|
|
|
|
|
|
|
|
|
|
await Trades.bulkCreate(TradesData);
|
|
|
|
|
|
await Promise.all([
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
|
|
|
|
|
|
await associateUserWithOrganization(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateInstrumentWithOrganization(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateDatasetWithInstrument(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateDatasetWithOrganization(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateCandleWithDataset(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateCandleWithOrganization(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateAccountWithUser(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateAccountWithOrganization(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateReplaySessionWithUser(),
|
|
|
|
|
|
|
|
|
|
await associateReplaySessionWithDataset(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateReplaySessionWithOrganization(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateTradeWithAccount(),
|
|
|
|
|
|
|
|
|
|
await associateTradeWithDataset(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateTradeWithOrganization(),
|
|
|
|
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await queryInterface.bulkDelete('organizations', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('instruments', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('datasets', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('candles', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('accounts', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('replay_sessions', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('trades', null, {});
|
|
|
|
|
|
},
|
|
}; |