95 lines
2.7 KiB
C++
95 lines
2.7 KiB
C++
#pragma once
|
|
|
|
#include "lib/api/services/PositionService.server.pb.h"
|
|
#include "lib/utils/bts_no_copy.h"
|
|
#include <memory>
|
|
|
|
namespace bts {
|
|
namespace md {
|
|
class MDClient;
|
|
}
|
|
namespace api {
|
|
class ServiceContext;
|
|
}
|
|
namespace api {
|
|
namespace orderman {
|
|
class Fill;
|
|
}
|
|
} // namespace api
|
|
namespace api {
|
|
namespace admin {
|
|
class AdminData;
|
|
}
|
|
} // namespace api
|
|
namespace api {
|
|
namespace position {
|
|
class ManualFill;
|
|
}
|
|
} // namespace api
|
|
|
|
namespace position {
|
|
|
|
class MDClient;
|
|
|
|
class PositionServiceServer : public bts::api::position::PositionServiceBase {
|
|
private:
|
|
struct PImpl;
|
|
std::unique_ptr<PImpl> me;
|
|
// this function deleted all local fills with
|
|
// a timestamp less than SOD
|
|
void _delete_presod_local_on_start() const;
|
|
// this is the function that aggrgates the
|
|
// position. is_add is to indicate if a row
|
|
// is added or removed
|
|
const bts::api::position::PositionUnit &_on_fill(
|
|
const bts::api::orderman::Fill &fill, bool is_add);
|
|
// analogous to the above, for manual fills (this inclused
|
|
// both client(local) and server(admin) fills)
|
|
const bts::api::position::PositionUnit &_on_manual_fill(
|
|
const api::position::ManualFill &fill, bool is_add);
|
|
void _periodic_poll();
|
|
// recomputes the whole pnl (no increments) and publishes it
|
|
void _compute_pnl_and_publish();
|
|
void _set_admin_data(const api::admin::AdminData &admin_data);
|
|
void _clear_and_publish_pos();
|
|
void _load_security_params();
|
|
|
|
public:
|
|
PositionServiceServer(bts::api::ServiceContext &context, md::MDClient &);
|
|
|
|
void create_manual_fill(
|
|
const ::bts::api::position::ManualFillBatch &,
|
|
const api::Response<::bts::api::position::PositionServiceResponse> &)
|
|
override;
|
|
|
|
void update_manual_fill(
|
|
const ::bts::api::position::ManualFillBatch &,
|
|
const api::Response<::bts::api::position::PositionServiceResponse> &)
|
|
override;
|
|
|
|
void remove_manual_fill(
|
|
const ::bts::api::position::ManualFillBatch &,
|
|
const api::Response<::bts::api::position::PositionServiceResponse> &)
|
|
override;
|
|
|
|
void set_base_position(
|
|
const ::bts::api::position::BasePositionBatch &request,
|
|
const api::Response<::bts::api::position::SetBasePositionResponse>
|
|
&reply) override;
|
|
|
|
void update_security_parameters(
|
|
const ::bts::api::position::SecurityParametersBatchOp &request,
|
|
const api::Response<
|
|
::bts::api::position::SecurityParametersBatchOpResponse> &reply)
|
|
override;
|
|
|
|
void reset_position(
|
|
const ::bts::api::position::ResetPositionParameters &,
|
|
const api::Response<::bts::api::position::PositionServiceResponse> &)
|
|
override;
|
|
|
|
~PositionServiceServer();
|
|
};
|
|
} // namespace position
|
|
} // namespace bts
|