87 lines
2.2 KiB
C++
87 lines
2.2 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;
|
|
enum FillType{
|
|
BASE,
|
|
SOD,
|
|
DAY
|
|
};
|
|
struct BasePositionEntry{
|
|
timeval current_as_of;
|
|
api::position::PositionEntry pos;
|
|
};
|
|
// 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);
|
|
const bts::api::position::PositionUnit &
|
|
_on_manual_fill(const api::position::ManualFill &fill, bool is_add);
|
|
void _periodic_poll();
|
|
void _compute_pnl_and_publish();
|
|
void _set_admin_data(const api::admin::AdminData &admin_data);
|
|
//FillType _fill_type(const bts::api::orderman::Fill &fill) const;
|
|
// this is when we have to reset the
|
|
void _recompute_all();
|
|
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::PositionServiceResponse>
|
|
&reply) override;
|
|
|
|
~PositionServiceServer();
|
|
};
|
|
} // namespace position
|
|
} // namespace bts
|