Skip to content
This repository has been archived by the owner on Feb 21, 2019. It is now read-only.

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
bitsha256 committed Aug 19, 2014
2 parents 6ad7a47 + 1a197ef commit 949f878
Show file tree
Hide file tree
Showing 20 changed files with 403 additions and 192 deletions.
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ if( WIN32 )

# Probably cmake has a bug and vcxproj generated for executable in Debug conf. has disabled debug info
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /DEBUG")

# On windows tcl should be installed to the directory pointed by setenv.bat script
SET(TCL_INCLUDE_PATH $ENV{TCL_ROOT}/include)
MESSAGE(STATUS "tcl INCLUDE PATH: ${TCL_INCLUDE_PATH}")

FIND_PACKAGE(TCL)
MESSAGE(STATUS "tcl_library: ${TCL_LIBRARY}")

SET(TCL_LIBS "optimized;${TCL_LIBRARY};debug;")
get_filename_component(TCL_LIB_PATH "${TCL_LIBRARY}" PATH)
get_filename_component(TCL_LIB_NAME "${TCL_LIBRARY}" NAME_WE)
get_filename_component(TCL_LIB_EXT "${TCL_LIBRARY}" EXT)

SET(TCL_LIBS "${TCL_LIBS}${TCL_LIB_PATH}/${TCL_LIB_NAME}g${TCL_LIB_EXT}")
SET(TCL_LIBRARY ${TCL_LIBS})
else( WIN32 )
# Apple AND Linux Options Here
find_package( ZLIB REQUIRED )
Expand Down
68 changes: 68 additions & 0 deletions HelperScripts/build_tcl.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
rem this script should be spawned from directory containing TCL sources.
rem built library will be installed to %INVICTUS_ROOT%/tcl
rem potential problems to solve: manual elimination of -debug:full option from files: makefile.vc (replace to -debug)
rem manual elimination of -WX switches from makefile.vc since in debug build warnings are generated.

setlocal

set TCL_VERSION=8.6.1

set INVICTUS_ROOT=%~dp0..\..
echo Using %INVICTUS_ROOT% as Invictus root directory

call "%VS120COMNTOOLS%\..\..\VC\vcvarsall.bat"

rem goto buildTK
echo "Building TCL library"

set CL=/MP
set LINK=/DEBUG

rem goto buildTK

pushd win
echo Building release version

nmake -f makefile.vc clean
nmake -f makefile.vc release || exit /b 1
nmake -f makefile.vc release install INSTALLDIR="%INVICTUS_ROOT%\tcl" || exit /b 2

echo Building DEBUG version

nmake -f makefile.vc clean OPTS=symbols
nmake -f makefile.vc OPTS=symbols || exit /b 3
nmake -f makefile.vc install OPTS=symbols INSTALLDIR="%INVICTUS_ROOT%\tcl" || exit /b 4

popd

:buildTK
echo "Building TK library"
set TCLDIR=%CD%
set INSTALLDIR=%INVICTUS_ROOT%\tcl
pushd ..\tk%TCL_VERSION%\win
rem call buildall.vc.bat || exit 10

nmake -f makefile.vc TCLDIR=%TCLDIR% || exit /b 5
nmake -f makefile.vc TCLDIR=%TCLDIR% install INSTALLDIR="%INVICTUS_ROOT%\tcl" || exit /b 6
nmake -f makefile.vc OPTS=symbols TCLDIR=%TCLDIR% || exit /b 7
nmake -f makefile.vc OPTS=symbols install TCLDIR=%TCLDIR% INSTALLDIR="%INVICTUS_ROOT%\tcl" || exit /b 8
popd

rem Copy generated binaries to the names been accepted by CMake (it doesn't recognize names suffixed by 't')
pushd %INVICTUS_ROOT%\tcl\bin
copy /Y tclsh86t.exe tclsh.exe
copy /Y tclsh86t.exe tclsh86.exe
copy /Y wish86t.exe wish86.exe
copy /Y wish86t.exe wish.exe
popd

pushd %INVICTUS_ROOT%\tcl\lib
copy /Y tcl86t.lib tcl86.lib
copy /Y tcl86tg.lib tcl86g.lib
copy /Y tk86t.lib tk86.lib
copy /Y tk86tg.lib tk86g.lib
pushd

:end
endlocal

15 changes: 15 additions & 0 deletions HelperScripts/build_tcl64.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
rem this script should be spawned from directory containing TCL sources.
rem built library will be installed to %INVICTUS_ROOT%/tcl

set INVICTUS_ROOT=%~dp0..\..\
echo Using %INVICTUS_ROOT% as Invictus root directory

call "%VS120COMNTOOLS%\..\..\VC\vcvarsall.bat" amd64

pushd win
nmake -f makefile.vc release || exit /b 1
nmake -f makefile.vc release install INSTALLDIR="%INVICTUS_ROOT%\tcl.x64" || exit /b 2
nmake -f makefile.vc OPTS=symbols || exit /b 3
nmake -f makefile.vc OPTS=symbols install INSTALLDIR="%INVICTUS_ROOT%\tcl.x64" || exit /b 4
popd

8 changes: 4 additions & 4 deletions libraries/api/wallet_api.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
{
"method_name": "wallet_import_bitcoin",
"description": "Imports a Bitcoin Core or BitShares PTS wallet",
"return_type": "void",
"return_type": "uint32_t",
"parameters" : [
{
"name" : "wallet_filename",
Expand All @@ -118,7 +118,7 @@
{
"method_name": "wallet_import_armory",
"description": "Imports an Armory wallet",
"return_type": "void",
"return_type": "uint32_t",
"parameters" : [
{
"name" : "wallet_filename",
Expand All @@ -141,7 +141,7 @@
{
"method_name": "wallet_import_electrum",
"description": "Imports an Electrum wallet",
"return_type": "void",
"return_type": "uint32_t",
"parameters" : [
{
"name" : "wallet_filename",
Expand All @@ -164,7 +164,7 @@
{
"method_name": "wallet_import_multibit",
"description": "Imports a Multibit wallet",
"return_type": "void",
"return_type": "uint32_t",
"parameters" : [
{
"name" : "wallet_filename",
Expand Down
2 changes: 1 addition & 1 deletion libraries/blockchain/genesis.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"timestamp" : "20140816T000000",
"timestamp" : "20140819T000000",
"market_assets": [
{
"symbol": "PTS",
Expand Down
2 changes: 1 addition & 1 deletion libraries/blockchain/include/bts/blockchain/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/* Set to true only for test network */
#define BTS_TEST_NETWORK false
#define BTS_TEST_NETWORK_VERSION 17
#define BTS_TEST_NETWORK_VERSION 18

/** @file bts/blockchain/config.hpp
* @brief Defines global constants that determine blockchain behavior
Expand Down
141 changes: 77 additions & 64 deletions libraries/blockchain/market_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,70 +321,6 @@ class market_engine
_pending_state->store_asset_record( *quote_asset );
_pending_state->store_asset_record( *base_asset );

if( trading_volume.amount > 0 && get_next_bid() && get_next_ask() )
{
market_history_key key(quote_id, base_id, market_history_key::each_block, _db_impl._head_block_header.timestamp);
market_history_record new_record(_current_bid->get_price(), _current_ask->get_price(), trading_volume.amount);
auto asset_rec = _db_impl.self->get_asset_record(quote_id);
FC_ASSERT(asset_rec, "There is trading volume on an asset that doesn't exist??");
if(market_stat)
new_record.recent_average_price = market_stat->avg_price_24h;

//LevelDB iterators are dumb and don't support proper past-the-end semantics.
auto last_key_itr = _db_impl._market_history_db.lower_bound(key);
if( !last_key_itr.valid() )
last_key_itr = _db_impl._market_history_db.last();
else
--last_key_itr;

key.timestamp = timestamp;

//Unless the previous record for this market is the same as ours...
if( (!(last_key_itr.valid()
&& last_key_itr.key().quote_id == quote_id
&& last_key_itr.key().base_id == base_id
&& last_key_itr.key().granularity == market_history_key::each_block
&& last_key_itr.value() == new_record)) )
{
//...add a new entry to the history table.
_pending_state->market_history[key] = new_record;
}

fc::time_point_sec start_of_this_hour = timestamp - (timestamp.sec_since_epoch() % (60*60));
market_history_key old_key(quote_id, base_id, market_history_key::each_hour, start_of_this_hour);
if( auto opt = _db_impl._market_history_db.fetch_optional(old_key) )
{
auto old_record = *opt;
old_record.volume += new_record.volume;
if( new_record.highest_bid > old_record.highest_bid || new_record.lowest_ask < old_record.lowest_ask )
{
old_record.highest_bid = std::max(new_record.highest_bid, old_record.highest_bid);
old_record.lowest_ask = std::min(new_record.lowest_ask, old_record.lowest_ask);
old_record.recent_average_price = new_record.recent_average_price;
_pending_state->market_history[old_key] = old_record;
}
}
else
_pending_state->market_history[old_key] = new_record;

fc::time_point_sec start_of_this_day = timestamp - (timestamp.sec_since_epoch() % (60*60*24));
old_key = market_history_key(quote_id, base_id, market_history_key::each_day, start_of_this_day);
if( auto opt = _db_impl._market_history_db.fetch_optional(old_key) )
{
auto old_record = *opt;
old_record.volume += new_record.volume;
if( new_record.highest_bid > old_record.highest_bid || new_record.lowest_ask < old_record.lowest_ask )
{
old_record.highest_bid = std::max(new_record.highest_bid, old_record.highest_bid);
old_record.lowest_ask = std::min(new_record.lowest_ask, old_record.lowest_ask);
old_record.recent_average_price = new_record.recent_average_price;
_pending_state->market_history[old_key] = old_record;
}
}
else
_pending_state->market_history[old_key] = new_record;
}

market_stat->last_error.reset();

if( _current_bid && _current_ask && order_did_execute )
Expand All @@ -396,11 +332,15 @@ class market_engine
// limit the maximum movement rate of the price.
if( _current_bid->get_price() > min_cover_ask )
market_stat->avg_price_24h.ratio += _current_bid->get_price().ratio;
else if( _current_bid->get_price() < max_short_bid )
market_stat->avg_price_24h.ratio += max_short_bid.ratio;
else
market_stat->avg_price_24h.ratio += min_cover_ask.ratio;

if( _current_ask->get_price() < max_short_bid )
market_stat->avg_price_24h.ratio += _current_ask->get_price().ratio;
else if( _current_ask->get_price() > min_cover_ask )
market_stat->avg_price_24h.ratio += min_cover_ask.ratio;
else
market_stat->avg_price_24h.ratio += max_short_bid.ratio;

Expand All @@ -420,6 +360,8 @@ class market_engine
}
_pending_state->store_market_status( *market_stat );

update_market_history( trading_volume, market_stat, timestamp );

wlog( "done matching orders" );
_pending_state->apply_changes();
}
Expand Down Expand Up @@ -740,6 +682,77 @@ class market_engine
return _current_ask.valid();
} FC_CAPTURE_AND_RETHROW() }


/**
* This method should not effect market execution or validation and
* is for historical purposes only.
*/
void update_market_history( const asset& trading_volume, const omarket_status& market_stat, const fc::time_point_sec& timestamp )
{
if( trading_volume.amount > 0 && get_next_bid() && get_next_ask() )
{
market_history_key key(_quote_id, _base_id, market_history_key::each_block, _db_impl._head_block_header.timestamp);
market_history_record new_record(_current_bid->get_price(), _current_ask->get_price(), trading_volume.amount);

FC_ASSERT( market_stat );
new_record.recent_average_price = market_stat->avg_price_24h;

//LevelDB iterators are dumb and don't support proper past-the-end semantics.
auto last_key_itr = _db_impl._market_history_db.lower_bound(key);
if( !last_key_itr.valid() )
last_key_itr = _db_impl._market_history_db.last();
else
--last_key_itr;

key.timestamp = timestamp;

//Unless the previous record for this market is the same as ours...
if( (!(last_key_itr.valid()
&& last_key_itr.key().quote_id == _quote_id
&& last_key_itr.key().base_id == _base_id
&& last_key_itr.key().granularity == market_history_key::each_block
&& last_key_itr.value() == new_record)) )
{
//...add a new entry to the history table.
_pending_state->market_history[key] = new_record;
}

fc::time_point_sec start_of_this_hour = timestamp - (timestamp.sec_since_epoch() % (60*60));
market_history_key old_key(_quote_id, _base_id, market_history_key::each_hour, start_of_this_hour);
if( auto opt = _db_impl._market_history_db.fetch_optional(old_key) )
{
auto old_record = *opt;
old_record.volume += new_record.volume;
if( new_record.highest_bid > old_record.highest_bid || new_record.lowest_ask < old_record.lowest_ask )
{
old_record.highest_bid = std::max(new_record.highest_bid, old_record.highest_bid);
old_record.lowest_ask = std::min(new_record.lowest_ask, old_record.lowest_ask);
old_record.recent_average_price = new_record.recent_average_price;
_pending_state->market_history[old_key] = old_record;
}
}
else
_pending_state->market_history[old_key] = new_record;

fc::time_point_sec start_of_this_day = timestamp - (timestamp.sec_since_epoch() % (60*60*24));
old_key = market_history_key(_quote_id, _base_id, market_history_key::each_day, start_of_this_day);
if( auto opt = _db_impl._market_history_db.fetch_optional(old_key) )
{
auto old_record = *opt;
old_record.volume += new_record.volume;
if( new_record.highest_bid > old_record.highest_bid || new_record.lowest_ask < old_record.lowest_ask )
{
old_record.highest_bid = std::max(new_record.highest_bid, old_record.highest_bid);
old_record.lowest_ask = std::min(new_record.lowest_ask, old_record.lowest_ask);
old_record.recent_average_price = new_record.recent_average_price;
_pending_state->market_history[old_key] = old_record;
}
}
else
_pending_state->market_history[old_key] = new_record;
}
}

pending_chain_state_ptr _pending_state;
pending_chain_state_ptr _prior_state;
chain_database_impl& _db_impl;
Expand Down
Loading

0 comments on commit 949f878

Please sign in to comment.