Work in progress for manual fills
This commit is contained in:
1 parent
1f01d974e3
commit
3be2aedfe3
3 files changed
+94
-30
No files matched your search
@@ -3,6 +3,7 @@ package bts.api.position;
|
||||
option csharp_namespace="bts.api.position";
|
||||
import "lib/api/apioptions.proto";
|
||||
import "lib/api/apicore.proto";
|
||||
import "lib/domain_model/Security.proto";
|
||||
|
||||
message PositionUnit{
|
||||
int32 record_id = 1 [(bts.api.key)=true];
|
||||
@@ -18,8 +19,38 @@ message PositionUnit{
|
||||
double day_short_avg_price = 100;
|
||||
}
|
||||
|
||||
message ManualFill {
|
||||
int32 record_id = 1 [(bts.api.key)=true];
|
||||
uint32 security_key = 2;
|
||||
uint32 account_id = 3;
|
||||
uint32 user_id = 4;
|
||||
api.Side side = 5;
|
||||
uint32 quantity = 6;
|
||||
double price = 7;
|
||||
}
|
||||
|
||||
message ManualFillBatch {
|
||||
repeated ManualFill manual_fill = 1;
|
||||
}
|
||||
|
||||
message PositionServiceOpResponse {
|
||||
bool ok = 1;
|
||||
string msg = 2;
|
||||
}
|
||||
|
||||
message PositionServiceResponse {
|
||||
repeated PositionServiceOpResponse response = 1;
|
||||
}
|
||||
|
||||
service PositionService {
|
||||
option (bts.api.service_description) = "Provides Position and PNL, per security, per account";
|
||||
// subscription
|
||||
rpc position_data(bts.api.VoidMessage) returns (stream PositionUnit);
|
||||
option (bts.api.service_description) = "Provides Position and PNL, per security, per account";
|
||||
|
||||
rpc create_manual_fill (ManualFillBatch) returns (PositionServiceResponse);
|
||||
rpc update_manual_fill (ManualFillBatch) returns (PositionServiceResponse);
|
||||
rpc remove_manual_fill (ManualFillBatch) returns (PositionServiceResponse);
|
||||
|
||||
// subscription
|
||||
rpc manual_fills(bts.api.VoidMessage) returns (stream ManualFill);
|
||||
rpc position_data(bts.api.VoidMessage) returns (stream PositionUnit);
|
||||
|
||||
}
|
||||
@@ -160,4 +160,20 @@ std::string PositionServiceServer::_fill_account(const Fill& fill){
|
||||
}
|
||||
PositionServiceServer::~PositionServiceServer(){
|
||||
}
|
||||
}}
|
||||
|
||||
void PositionServiceServer::create_manual_fill(
|
||||
const ::bts::api::position::ManualFillBatch &,
|
||||
const api::Response<::bts::api::position::PositionServiceResponse> &)
|
||||
{}
|
||||
|
||||
void PositionServiceServer::update_manual_fill(
|
||||
const ::bts::api::position::ManualFillBatch &,
|
||||
const api::Response<::bts::api::position::PositionServiceResponse> &)
|
||||
{}
|
||||
|
||||
void PositionServiceServer::remove_manual_fill(
|
||||
const ::bts::api::position::ManualFillBatch &,
|
||||
const api::Response<::bts::api::position::PositionServiceResponse> &)
|
||||
{}
|
||||
|
||||
}}
|
||||
@@ -1,42 +1,59 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include "lib/api/services/PositionService.server.pb.h"
|
||||
#include "lib/utils/bts_no_copy.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace bts {
|
||||
namespace api {class ServiceContext;}
|
||||
namespace api {namespace orderman {class Fill;}}
|
||||
namespace position{
|
||||
namespace api {
|
||||
class ServiceContext;
|
||||
}
|
||||
namespace api {
|
||||
namespace orderman {
|
||||
class Fill;
|
||||
}
|
||||
} // namespace api
|
||||
namespace position {
|
||||
|
||||
class PositionServiceServer : public bts::api::position::PositionServiceBase
|
||||
{
|
||||
private:
|
||||
class PositionServiceServer : public bts::api::position::PositionServiceBase {
|
||||
private:
|
||||
struct PImpl;
|
||||
std::unique_ptr<PImpl> me;
|
||||
private:
|
||||
|
||||
private:
|
||||
// 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_fill(const bts::api::orderman::Fill &fill, bool is_add);
|
||||
// given an account and key, finds (or adds if absent)
|
||||
// the PositionUnit entry
|
||||
bts::api::position::PositionUnit& _get_or_add (const std::string& acct,
|
||||
uint32_t sec_id);
|
||||
static void _avg_price_qty(double base_p,
|
||||
double base_q,
|
||||
double fill_p,
|
||||
double fill_q,
|
||||
bool is_add,
|
||||
const std::string& fill_id,
|
||||
double& avg_price,
|
||||
double& tot_qty);
|
||||
static std::string _fill_account(const bts::api::orderman::Fill& fill);
|
||||
public:
|
||||
PositionServiceServer(bts::api::ServiceContext& context);
|
||||
bts::api::position::PositionUnit &_get_or_add(const std::string &acct,
|
||||
uint32_t sec_id);
|
||||
static void _avg_price_qty(double base_p, double base_q, double fill_p,
|
||||
double fill_q, bool is_add,
|
||||
const std::string &fill_id, double &avg_price,
|
||||
double &tot_qty);
|
||||
static std::string _fill_account(const bts::api::orderman::Fill &fill);
|
||||
|
||||
public:
|
||||
PositionServiceServer(bts::api::ServiceContext &context);
|
||||
|
||||
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;
|
||||
~PositionServiceServer();
|
||||
};
|
||||
}}
|
||||
} // namespace position
|
||||
} // namespace bts
|
||||
Reference in new issue
Block a user