Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 58 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,11 +1,65 @@
PROJECT_NAME=FonXLog
#Monolog\Logger::DEBUG = 100
FINXLOG_DEBUG=100
FINXLOG_DOMAIN=localhost

FINXLOG_QUOTATION_SERVER_ADDRESS=198.211.118.180
FINXLOG_QUOTATION_SERVER_ADDRESS=178.62.145.164
#FINXLOG_QUOTATION_SERVER_ADDRESS=198.211.118.180
FINXLOG_QUOTATION_SERVER_PORT=10000

FINXLOG_AMQP_SERVER_ADDRESS=127.0.0.1
#FINXLOG_AMQP_SERVER_PORT=
FINXLOG_AMQP_TUBE_QUOTATION=finxlog_quotation
FINXLOG_AMQP_TUBE_QUOTATION_FAIL=finxlog_quotation_fail
FINXLOG_AMQP_TUBE_IMPORT=finxlog_quotation
FINXLOG_AMQP_TUBE_IMPORT_FAIL=finxlog_quotation_fail
FINXLOG_AMQP_TUBE_WS=finxlog_ws

FINXLOG_ELASTICO_PARAM={"host":"localhost"}
FINXLOG_ELASTICA_PARAM={"host":"localhost"}
#FINXLOG_ELASTICA_LOG_PARAM={"host":"localhost"}

FINXLOG_IMPORT_FILTER_OTHER=0

FINXLOG_ENV_JS="PROJECT_NAME FINXLOG_DOMAIN FINXLOG_WEBSOCKET_EXTARNAL_HOST FINXLOG_WEBSOCKET_EXTARNAL_PORT FINXLOG_WEBSOCKET_EXTARNAL_PATH FINXLOG_DEBUG"



##### WEBSOCKET BLOCK
#please, always use
# 1. not LISTEN public interface (use 127.0.0.1 or internal)
# 2. setup http proxy on vhost to websocket. nginx: http://nginx.org/ru/docs/http/websocket.html
# //DOMAIN/ws => ws://LISTEN_INTERFACE:LISTEN_PORT/____NOT____SERVICE_PATH
# //localhost/ws => ws://127.0.0.1:8080/ws

##### --------------------------------
###DEVELOPER MODE. is just for quick start. do not use
#is direct access for send any data to any users
FINXLOG_WEBSOCKET_LISTEN_INTERFACE=0.0.0.0
FINXLOG_WEBSOCKET_EXTARNAL_PORT=8080
FINXLOG_WEBSOCKET_SERVICE_FILTER_ADDR_REGEXP=^127\.

###PRODUCTION MODE:
#FINXLOG_WEBSOCKET_LISTEN_INTERFACE=127.0.0.1
#default EXTARNAL_PORT=80

###PRODUCTION CLOUD MODE with 10.0.3.0 intranet
#FINXLOG_WEBSOCKET_LISTEN_INTERFACE=10.0.0.0
#FINXLOG_WEBSOCKET_INTERNAL_HOST=10.0.3.x
#default EXTARNAL_PORT=80
##### --------------------------------




##### WEBSOCKET TYPICAL BLOCK
#required for internal service
FINXLOG_WEBSOCKET_LISTEN_PORT=8080

#markers for proxy: path or domain
FINXLOG_WEBSOCKET_EXTARNAL_PATH=/ws
#default: FINXLOG_DOMAIN
#FINXLOG_WEBSOCKET_EXTARNAL_HOST=localhost

#if empty(FILTER_ADDR_REGEXP) and proxy not acceptable. randomize it: for same secure
FINXLOG_WEBSOCKET_SERVICE_PATH=/service

#one of: Ratchet or ElephantIO. just for performance test
#FINXLOG_WEBSOCKET_SERVICE_LIB=Ratchet
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.idea/
vendor/
composer.lock
.env
www/js/config_autobuild.js
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright 2016 <BAGArt>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
21 changes: 21 additions & 0 deletions command/daemon/import/quotation_amqp2db.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/php
<?php

/**
* Always on service: load quotation from source
*/
require_once __DIR__ . '/../../../vendor/autoload.php';

$import = (new FinXLog\Module\ImportQuotation\SaveQuotation());

if (in_array('fail', $argv)) {
$import->setQueueConnector($import->getFailQueueConnector());
}
$count = null;
foreach ($argv as $a) {
if (is_numeric($a) && $a > 0) {
$count = $a;
}
}

$import->run($count);
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
/**
* Always on service: load quotation from source
*/
require_once __DIR__ . '/../../vendor/autoload.php';
require_once __DIR__ . '/../../../vendor/autoload.php';

$import = new FinXLog\Module\Import\LoadQuotation();
$import = new FinXLog\Module\ImportQuotation\LoadQuotation();

$import->run(
!empty($argv[1])
Expand Down
14 changes: 14 additions & 0 deletions command/daemon/import/quotation_exchange2amqp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
FINXLOG_ROOT_DIR=`dirname $0`/../../../;
#import .env
export $(cat $FINXLOG_ROOT_DIR.env | grep -P '^FINXLOG_(QUOTATION|AMQP)')

# check:
# export | grep FIN

# netcat > amqp
while :
do
netcat $FINXLOG_QUOTATION_SERVER_ADDRESS $FINXLOG_QUOTATION_SERVER_PORT \
| xargs -I {} beanstool put -t=$FINXLOG_AMQP_TUBE_IMPORT -b {}
done
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
/**
* Always on service: load quotation from source
*/
require_once __DIR__ . '/../../vendor/autoload.php';
require_once __DIR__ . '/../../../vendor/autoload.php';

$import = new FinXLog\Module\Import\LoadQuotation();
$import = new FinXLog\Module\ImportQuotation\LoadQuotation();

$import
->setWorkWithSwitch(false)
Expand Down
6 changes: 6 additions & 0 deletions command/daemon/import/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Description
this daemons for import exchange quotations

daemon: ex2db
or
daemon: ex2amqp->AMQP->amqp2db
15 changes: 0 additions & 15 deletions command/daemon/quotation_amqp2db.php

This file was deleted.

9 changes: 0 additions & 9 deletions command/daemon/quotation_exchange2amqp.sh

This file was deleted.

6 changes: 6 additions & 0 deletions command/daemon/ws/quotation_amqp2ws.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/php
<?php
require_once __DIR__ . '/../../../vendor/autoload.php';

(new FinXLog\Module\ClientQueue\SearchQuotation())
->run();
6 changes: 6 additions & 0 deletions command/daemon/ws/quotation_ws2client.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/php
<?php
require __DIR__ . '/../../../vendor/autoload.php';

(new \FinXLog\Module\Ratchet\QuotationServer())
->run();
37 changes: 37 additions & 0 deletions command/daemon/ws/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Description
this daemons to work with Browser WebSocket request from JS_APP

## 1st part

get quotations list(or agg like doji)

JS_App
->WebSocket (client)
->daemon: ws2client (listen)
->AMQP
->daemon: amqp2ws (listen)
->Elasticsearch
//back
->WebSocket (service)
->daemon: ws2client (listen)
->WebSocket (all)
->JS_App
->table
->JS_HighCharts



@todo:
2nd part
daemon:
import/ex2amqp (listen)
->AMQP
->import/amqp2db
->2db
->WebSocket (service)
->daemon: ws2client (listen)
->WebSocket (update)
->JS_App
->table
->JS_HighCharts

27 changes: 27 additions & 0 deletions command/setup/web_config_build.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/php
<?php
require_once __DIR__ . '/../../vendor/autoload.php';
$config_filename = getenv('FINXLOG_ROOT_PATH') . '/www/js/config_autobuild.js';
assert(strlen(getenv('FINXLOG_ENV_JS')));
$front_param_list = array_filter(
preg_split(
'~[\s,;]+~us',
getenv('FINXLOG_ENV_JS')
)
);

$front_param = [];
foreach ($front_param_list as $param) {
if (getenv($param) === false) {
continue;
}
$front_param[$param] = getenv($param);
}

file_put_contents(
$config_filename,
"//DO NOT EDIT THIS FILE.\n//Build it with composer update\n"
. "FinXLog.config ="
. json_encode($front_param, getenv('FINXLOG_DEBUG') ? JSON_PRETTY_PRINT : null)
. ";\nFinXLog.start();\n"
);
2 changes: 2 additions & 0 deletions command/stats/amqp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
beanstool stats
8 changes: 8 additions & 0 deletions command/test/get_quotation_agg.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/php
<?php
require_once __DIR__ . '/../../vendor/autoload.php';

var_export(
(new \FinXLog\Model\QuotationAgg)
->getAAPL('BTCUSD', 'day')
);
15 changes: 15 additions & 0 deletions command/test/ws/add_amqp_ws_subscribe.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/php
<?php
require_once __DIR__ . '/../../../vendor/autoload.php';

(new \FinXLog\Module\Connector\Queue(
getenv('FINXLOG_AMQP_TUBE_WS')
))
->put([
'quotation' => 'BTCUSD'
])
->put([
'quotation' => 'BTCUSD',
'agg_type' => 'AAPL',
'agg_period' => 'M1',
]);
7 changes: 7 additions & 0 deletions command/test/ws/add_amqp_ws_subscribe.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
FINXLOG_ROOT_DIR=`dirname $0`/../../../;
#import .env
export $(cat $FINXLOG_ROOT_DIR.env | grep -P '^FINXLOG_(QUOTATION|AMQP)')

beanstool put -t=$FINXLOG_AMQP_TUBE_WS -b '{"quotation":"BTCUSD"}';
beanstool put -t=$FINXLOG_AMQP_TUBE_WS -b '{"quotation":"BTCUSD","agg_type":"AAPL","agg_period":"M1"}';
38 changes: 38 additions & 0 deletions command/test/ws/add_ws_msg_client.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/php
<?php
/**
* native listener(simulate browser)
* @usage: command/test/add_ws_msg_client.php [count]
*/
//
//by default - listen

require_once __DIR__ . '/../../../vendor/autoload.php';

$listen_count = empty($argv[1]) ? 0 : $argv[1];

\Ratchet\Client\connect('ws://127.0.0.1:8080/ws')
->then(
function(\Ratchet\Client\WebSocket $conn)
use ($listen_count)
{
$conn->on(
'message',
function($msg) use ($conn, $listen_count)
{
echo "\nReceived: " . substr($msg, 0, 100). "...\n\n";
if ($listen_count) {
static $count = 0;
if (++$count >= $listen_count) {
$conn->close();
}
}
}
);

$conn->send('{"type": "quotations" }');
$conn->send('{"type":"subscribe","quotation":"_ALL"}');
$conn->send('{"type":"subscribe","quotation":"BTCUSD"}');
$conn->send('{"type":"subscribe","quotation":"BTCUSD","agg_period": "M1","agg_type":"AAPL"}');
}
);
43 changes: 43 additions & 0 deletions command/test/ws/add_ws_msg_service.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/php
<?php
require_once __DIR__ . '/../../../vendor/autoload.php';
$client = (new \FinXLog\Module\ClientQueue\SearchQuotation);

$client->addWsMessage('
{
"type":"send",
"quotation":"_ALL",
"quotations":[
{"S":"BTCUSD","T":"2016/06/11 04:05:51","B":568.151},
{"S":"TST","T":"2016/06/02 04:05:51","B":4}
]
}
');

$client->addWsMessage('
{
"type":"send",
"quotation":"BTCUSD",
"quotations":[
{"S":"BTCUSD","T":"2016/06/11 04:05:51","B":568.151},
{"S":"BTCUSD","T":"2016/06/11 04:05:51","B":568.151}
]
}
');

$client->addWsMessage('
{
"type":"send",
"quotation":"BTCUSD",
"agg_period":"M1",
"agg_type":"AAPL",
"AAPL":[
{"S":"BTCUSD","T":"2016/06/11 04:05:51","B":568.151},
{"S":"BTCUSD","T":"2016/06/11 04:05:51","B":568.151}
]
}
');

$client->addWsMessage(['type' => 'conn_count']);
$client->addWsMessage(['type' => 'all', 'xx' => 123]);
$client->addWsMessage(['type' => 'test']);
Loading