desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
''
| def profit(self, contract=None):
| pass
|
''
| def day_profit(self, contract=None):
| pass
|
'åœæ ¹baræ¶éŽç»ç¹æ®ååçå¯çšèµéïŒçšäºæµè¯ã'
| def test_cash(self):
| self.process_trading_events(at_baropen=False)
return self.cash()
|
'åœæ ¹baræ¶éŽç»ç¹æ®ååçæçïŒçšäºæµè¯ã'
| def test_equity(self):
| self.process_trading_events(at_baropen=False)
return self.equity()
|
'Args:
pcontracts (list): list of pcontracts(string)
dt_start (datetime/str): start time of all pcontracts
dt_end (datetime/str): end time of all pcontracts
n (int): last n bars
spec_date (dict): time range for specific pcontracts'
| def __init__(self, pcontracts, dt_start='1980-1-1', dt_end='2100-1-1', n=None, spec_date={}):
| self.finished_data = []
pcontracts = list(map((lambda x: x.upper()), pcontracts))
self.pcontracts = pcontracts
self._combs = []
self._data_manager = DataManager()
if (settings['source'] == 'csv'):
self.pcontracts = self._parse_pcontracts(self.pcontracts)
self._default_pcontract = sel... |
'Args:
comb (list): äžäžªçç¥ç»å'
| def add_comb(self, comb, settings):
| self._combs.append(comb)
num_strategy = len(comb)
if ('capital' not in settings):
settings['capital'] = 1000000.0
logger.info('BackTesting with default capital 1000000.0.')
assert (settings['capital'] > 0)
if (num_strategy == 1):
settings['ratio'] = [1]
elif (... |
''
| @abstractmethod
def connect(self):
| pass
|
''
| @abstractmethod
def query_contract(self, contract, sync=False):
| pass
|
''
| @abstractmethod
def query_tick(self, contract, sync=False):
| pass
|
''
| @abstractmethod
def query_captital(self, sync=False):
| pass
|
''
| @abstractmethod
def query_position(self, sync=False):
| pass
|
':param Order order: å§æè®¢åã'
| @abstractmethod
def order(self, order, sync=False):
| pass
|
''
| @abstractmethod
def cancel_order(self, orderid, sync=False):
| pass
|
''
| def on_transaction(self, trans):
| pass
|
'tickæ°æ®åè°'
| def on_tick(self, tick):
| pass
|
''
| def on_capital(self, tick):
| pass
|
''
| def on_position(self, tick):
| pass
|
''
| def connect(self):
| pass
|
''
| def query_contract(self, contract):
| pass
|
''
| def query_tick(self, contract):
| pass
|
''
| def query_captital(self):
| pass
|
''
| def query_position(self):
| pass
|
''
| def order(self, order):
| pass
|
''
| def cancel_order(self, orderid):
| pass
|
''
| def on_transaction(self, trans):
| pass
|
'tickæ°æ®åè°'
| def on_tick(self, tick):
| pass
|
''
| def on_capital(self, tick):
| pass
|
''
| def on_position(self, tick):
| pass
|
''
| def connect(self):
| pass
|
''
| def query_contract(self, contract):
| pass
|
''
| def query_tick(self, contract):
| pass
|
''
| def query_captital(self):
| pass
|
''
| def query_position(self):
| pass
|
''
| def order(self, order):
| self._events.put(OrderEvent(order))
|
''
| def cancel_order(self, orderid):
| pass
|
''
| def on_transaction(self, trans):
| self._blotter.update_fill(trans)
|
'tickæ°æ®åè°'
| def on_tick(self, tick):
| pass
|
''
| def on_capital(self, tick):
| pass
|
''
| def on_position(self, tick):
| pass
|
'nameçšæ¥è·èžª'
| def __init__(self, data=[], name='series', indic=None, default=None):
| self.curbar = 0
self._window_size = len(data)
self._indic = indic
self._default = default
self._realtime = False
self.name = name
if (len(data) == 0):
self.data = np.array(([self._default] * self._window_size))
else:
self.data = data
|
'Args:
data (list|ndarray|pd.Series): æ°æ®ïŒç±»åäžºæ¯æçŽ¢åŒçæ°æ®ç»æ
wwsize (int): çªå£å€§å°'
| def reset_data(self, data, wsize):
| self._window_size = wsize
if (len(data) == 0):
self.data = np.array(([self._default] * self._window_size))
else:
self.data = data
|
'æŽæ°åœåBar玢åŒ'
| def update_curbar(self, curbar):
| self.curbar = curbar
|
''
| def update(self, v):
| if isinstance(v, SeriesBase):
self.data[self.curbar] = v[0]
else:
self.data[self.curbar] = v
|
''
| def duplicate_last_element(self):
| try:
pre_elem = self.data[((self.curbar - 1) % self._window_size)]
except KeyError:
return
else:
self.data[self.curbar] = pre_elem
|
''
| def make_market(self, bars, at_baropen):
| if (len(self._open_orders) == 0):
return
fill_orders = set()
for order in self._open_orders:
if (order.side == TradeSide.CANCEL):
fill_orders.add(order)
transact = Transaction(order)
self.events.put(FillEvent(transact))
continue
try:
... |
''
| def insert_order(self, event):
| if (event.order in self._open_orders):
self._open_orders.remove(event.order)
self._open_orders.add(event.order)
|
'check ep for data, add it to queue and sleep for interval'
| def _read(self):
| while self._rxactive:
try:
rv = self._ep_in.read(self._ep_in.wMaxPacketSize)
if self._isFTDI:
status = rv[:2]
if ((status[0] != 1) or (status[1] != 96)):
log.info(u'USB Status: 0x{0:02X} 0x{1:02X}'.format(*status))
... |
'reset the FTDI device'
| def _resetFTDI(self):
| if (not self._isFTDI):
return
txdir = 0
req_type = 2
recipient = 0
req_type = (((txdir << 7) + (req_type << 5)) + recipient)
self.device.ctrl_transfer(bmRequestType=req_type, bRequest=0, wValue=0, wIndex=1, data_or_wLength=0)
|
'flush rx / tx buffers for ftdi device'
| def _flushFTDI(self, rx=True, tx=True):
| if (not self._isFTDI):
return
txdir = 0
req_type = (2 if self._isFTDI else 1)
recipient = (0 if self._isFTDI else 1)
req_type = (((txdir << 7) + (req_type << 5)) + recipient)
if rx:
self.device.ctrl_transfer(bmRequestType=req_type, bRequest=0, wValue=1, wIndex=1, data_or_wLength=... |
'Initialize the object.
This initializes the USBError object. The strerror and errno are passed
to the parent object. The error_code parameter is attributed to the
backend_error_code member variable.'
| def __init__(self, strerror, error_code=None, errno=None):
| IOError.__init__(self, errno, strerror)
self.backend_error_code = error_code
|
'Initialize the Endpoint object.
The device parameter is the device object returned by the find()
function. endpoint is the endpoint logical index (not the endpoint
address). The configuration parameter is the logical index of the
configuration (not the bConfigurationValue field). The interface
parameter is the interfa... | def __init__(self, device, endpoint, interface=0, alternate_setting=0, configuration=0):
| self.device = device
self.index = endpoint
backend = device._ctx.backend
desc = backend.get_endpoint_descriptor(device._ctx.dev, endpoint, interface, alternate_setting, configuration)
_set_attr(desc, self, ('bLength', 'bDescriptorType', 'bEndpointAddress', 'bmAttributes', 'wMaxPacketSize', 'bInterva... |
'Write data to the endpoint.
The parameter data contains the data to be sent to the endpoint and
timeout is the time limit of the operation. The transfer type and
endpoint address are automatically inferred.
The method returns the number of bytes written.
For details, see the Device.write() method.'
| def write(self, data, timeout=None):
| return self.device.write(self, data, timeout)
|
'Read data from the endpoint.
The parameter size_or_buffer is either the number of bytes to
read or an array object where the data will be put in and timeout is the
time limit of the operation. The transfer type and endpoint address
are automatically inferred.
The method returns either an array object or the number of ... | def read(self, size_or_buffer, timeout=None):
| return self.device.read(self, size_or_buffer, timeout)
|
'Clear the halt/status condition of the endpoint.'
| def clear_halt(self):
| self.device.clear_halt(self.bEndpointAddress)
|
'Initialize the interface object.
The device parameter is the device object returned by the find()
function. The configuration parameter is the logical index of the
configuration (not the bConfigurationValue field). The interface
parameter is the interface logical index (not the bInterfaceNumber
field) and alternate_se... | def __init__(self, device, interface=0, alternate_setting=0, configuration=0):
| self.device = device
self.alternate_index = alternate_setting
self.index = interface
self.configuration = configuration
backend = device._ctx.backend
desc = backend.get_interface_descriptor(self.device._ctx.dev, interface, alternate_setting, configuration)
_set_attr(desc, self, ('bLength', '... |
'Show all information for the interface.'
| def __str__(self):
| string = self._get_full_descriptor_str()
for endpoint in self:
string += ('\n' + str(endpoint))
return string
|
'Return a tuple of the interface endpoints.'
| def endpoints(self):
| return tuple(self)
|
'Set the interface alternate setting.'
| def set_altsetting(self):
| self.device.set_interface_altsetting(self.bInterfaceNumber, self.bAlternateSetting)
|
'Iterate over all endpoints of the interface.'
| def __iter__(self):
| for i in range(self.bNumEndpoints):
(yield Endpoint(self.device, i, self.index, self.alternate_index, self.configuration))
|
'Return the Endpoint object in the given position.'
| def __getitem__(self, index):
| return Endpoint(self.device, index, self.index, self.alternate_index, self.configuration)
|
'Initialize the configuration object.
The device parameter is the device object returned by the find()
function. The configuration parameter is the logical index of the
configuration (not the bConfigurationValue field). By "logical index"
we mean the relative order of the configurations returned by the
peripheral as a ... | def __init__(self, device, configuration=0):
| self.device = device
self.index = configuration
backend = device._ctx.backend
desc = backend.get_configuration_descriptor(self.device._ctx.dev, configuration)
_set_attr(desc, self, ('bLength', 'bDescriptorType', 'wTotalLength', 'bNumInterfaces', 'bConfigurationValue', 'iConfiguration', 'bmAttributes... |
'Return a tuple of the configuration interfaces.'
| def interfaces(self):
| return tuple(self)
|
'Set this configuration as the active one.'
| def set(self):
| self.device.set_configuration(self.bConfigurationValue)
|
'Iterate over all interfaces of the configuration.'
| def __iter__(self):
| for i in range(self.bNumInterfaces):
alt = 0
try:
while True:
(yield Interface(self.device, i, alt, self.index))
alt += 1
except (USBError, IndexError):
pass
|
'Return the Interface object in the given position.
index is a tuple of two values with interface index and
alternate setting index, respectivally. Example:
>>> interface = config[(0, 0)]'
| def __getitem__(self, index):
| return Interface(self.device, index[0], index[1], self.index)
|
'Return a tuple of the device configurations.'
| def configurations(self):
| return tuple(self)
|
'Initialize the Device object.
Library users should normally get a Device instance through
the find function. The dev parameter is the identification
of a device to the backend and its meaning is opaque outside
of it. The backend parameter is a instance of a backend
object.'
| def __init__(self, dev, backend):
| self._ctx = _ResourceManager(dev, backend)
self.__default_timeout = _DEFAULT_TIMEOUT
(self._serial_number, self._product, self._manufacturer) = (None, None, None)
self._langids = None
desc = backend.get_device_descriptor(dev)
_set_attr(desc, self, ('bLength', 'bDescriptorType', 'bcdUSB', 'bDevic... |
'Return the USB device\'s supported language ID codes.
These are 16-bit codes familiar to Windows developers, where for
example instead of en-US you say 0x0409. USB_LANGIDS.pdf on the usb.org
developer site for more info. String requests using a LANGID not
in this array should not be sent to the device.
This property w... | @property
def langids(self):
| if (self._langids is None):
try:
self._langids = util.get_langids(self)
except USBError:
self._langids = ()
return self._langids
|
'Return the USB device\'s serial number string descriptor.
This property will cause some USB traffic the first time it is accessed
and cache the resulting value for future use.'
| @property
def serial_number(self):
| if (self._serial_number is None):
self._serial_number = util.get_string(self, self.iSerialNumber)
return self._serial_number
|
'Return the USB device\'s product string descriptor.
This property will cause some USB traffic the first time it is accessed
and cache the resulting value for future use.'
| @property
def product(self):
| if (self._product is None):
self._product = util.get_string(self, self.iProduct)
return self._product
|
'Return the USB device\'s manufacturer string descriptor.
This property will cause some USB traffic the first time it is accessed
and cache the resulting value for future use.'
| @property
def manufacturer(self):
| if (self._manufacturer is None):
self._manufacturer = util.get_string(self, self.iManufacturer)
return self._manufacturer
|
'Return the backend being used by the device.'
| @property
def backend(self):
| return self._ctx.backend
|
'Set the active configuration.
The configuration parameter is the bConfigurationValue field of the
configuration you want to set as active. If you call this method
without parameter, it will use the first configuration found. As a
device hardly ever has more than one configuration, calling the method
without arguments... | def set_configuration(self, configuration=None):
| self._ctx.managed_set_configuration(self, configuration)
|
'Return a Configuration object representing the current
configuration set.'
| def get_active_configuration(self):
| return self._ctx.get_active_configuration(self)
|
'Set the alternate setting for an interface.
When you want to use an interface and it has more than one alternate
setting, you should call this method to select the appropriate
alternate setting. If you call the method without one or the two
parameters, it will be selected the first one found in the Device in
the same ... | def set_interface_altsetting(self, interface=None, alternate_setting=None):
| self._ctx.managed_set_interface(self, interface, alternate_setting)
|
'Clear the halt/stall condition for the endpoint ep.'
| def clear_halt(self, ep):
| if isinstance(ep, Endpoint):
ep = ep.bEndpointAddress
self._ctx.managed_open()
self._ctx.backend.clear_halt(self._ctx.handle, ep)
|
'Reset the device.'
| def reset(self):
| self._ctx.managed_open()
self._ctx.dispose(self, False)
self._ctx.backend.reset_device(self._ctx.handle)
self._ctx.dispose(self, True)
|
'Write data to the endpoint.
This method is used to send data to the device. The endpoint parameter
corresponds to the bEndpointAddress member whose endpoint you want to
communicate with.
The data parameter should be a sequence like type convertible to
the array type (see array module).
The timeout is specified in mili... | def write(self, endpoint, data, timeout=None):
| backend = self._ctx.backend
fn_map = {util.ENDPOINT_TYPE_BULK: backend.bulk_write, util.ENDPOINT_TYPE_INTR: backend.intr_write, util.ENDPOINT_TYPE_ISO: backend.iso_write}
(intf, ep) = self._ctx.setup_request(self, endpoint)
fn = fn_map[util.endpoint_type(ep.bmAttributes)]
return fn(self._ctx.handle,... |
'Read data from the endpoint.
This method is used to receive data from the device. The endpoint
parameter corresponds to the bEndpointAddress member whose endpoint
you want to communicate with. The size_or_buffer parameter either
tells how many bytes you want to read or supplies the buffer to
receive the data (it *must... | def read(self, endpoint, size_or_buffer, timeout=None):
| backend = self._ctx.backend
fn_map = {util.ENDPOINT_TYPE_BULK: backend.bulk_read, util.ENDPOINT_TYPE_INTR: backend.intr_read, util.ENDPOINT_TYPE_ISO: backend.iso_read}
(intf, ep) = self._ctx.setup_request(self, endpoint)
fn = fn_map[util.endpoint_type(ep.bmAttributes)]
if isinstance(size_or_buffer, ... |
'Do a control transfer on the endpoint 0.
This method is used to issue a control transfer over the endpoint 0
(endpoint 0 is required to always be a control endpoint).
The parameters bmRequestType, bRequest, wValue and wIndex are the same
of the USB Standard Control Request format.
Control requests may or may not have ... | def ctrl_transfer(self, bmRequestType, bRequest, wValue=0, wIndex=0, data_or_wLength=None, timeout=None):
| try:
buff = util.create_buffer(data_or_wLength)
except TypeError:
buff = _interop.as_array(data_or_wLength)
self._ctx.managed_open()
recipient = (bmRequestType & 3)
rqtype = (bmRequestType & (3 << 5))
if ((recipient == util.CTRL_RECIPIENT_INTERFACE) and (rqtype != util.CTRL_TYPE_... |
'Determine if there is kernel driver associated with the interface.
If a kernel driver is active, the object will be unable to perform
I/O.
The interface parameter is the device interface number to check.'
| def is_kernel_driver_active(self, interface):
| self._ctx.managed_open()
return self._ctx.backend.is_kernel_driver_active(self._ctx.handle, interface)
|
'Detach a kernel driver.
If successful, you will then be able to perform I/O.
The interface parameter is the device interface number to detach the
driver from.'
| def detach_kernel_driver(self, interface):
| self._ctx.managed_open()
self._ctx.backend.detach_kernel_driver(self._ctx.handle, interface)
|
'Re-attach an interface\'s kernel driver, which was previously
detached using detach_kernel_driver().
The interface parameter is the device interface number to attach the
driver to.'
| def attach_kernel_driver(self, interface):
| self._ctx.managed_open()
self._ctx.backend.attach_kernel_driver(self._ctx.handle, interface)
|
'Iterate over all configurations of the device.'
| def __iter__(self):
| for i in range(self.bNumConfigurations):
(yield Configuration(self, i))
|
'Return the Configuration object in the given position.'
| def __getitem__(self, index):
| return Configuration(self, index)
|
'Actually finalizes the object (frees allocated resources etc.).
Returns: None
Derived classes should implement this.'
| def _finalize_object(self):
| pass
|
'Creates a new object instance and adds the private finalizer
attributes to it.
Returns: new object instance
Arguments:
* *args, **kwargs -- ignored'
| def __new__(cls, *args, **kwargs):
| instance = super(_AutoFinalizedObjectBase, cls).__new__(cls)
instance._finalize_called = False
return instance
|
'Helper method that finalizes the object if not already done.
Returns: None'
| def _do_finalize_object(self):
| if (not self._finalize_called):
self._finalize_called = True
self._finalize_object()
|
'Finalizes the object if not already done.
Returns: None'
| def finalize(self):
| raise NotImplementedError('finalize() must be implemented by AutoFinalizedObject.')
|
'Perform a bulk write request to the endpoint specified.
Arguments:
endpoint: endpoint number.
buffer: sequence data buffer to write.
This parameter can be any sequence type.
timeout: operation timeout in milliseconds. (default: 100)
Returns the number of bytes written.'
| def bulkWrite(self, endpoint, buffer, timeout=100):
| return self.dev.write(endpoint, buffer, timeout)
|
'Performs a bulk read request to the endpoint specified.
Arguments:
endpoint: endpoint number.
size: number of bytes to read.
timeout: operation timeout in milliseconds. (default: 100)
Returns a tuple with the data read.'
| def bulkRead(self, endpoint, size, timeout=100):
| return self.dev.read(endpoint, size, timeout)
|
'Perform a interrupt write request to the endpoint specified.
Arguments:
endpoint: endpoint number.
buffer: sequence data buffer to write.
This parameter can be any sequence type.
timeout: operation timeout in milliseconds. (default: 100)
Returns the number of bytes written.'
| def interruptWrite(self, endpoint, buffer, timeout=100):
| return self.dev.write(endpoint, buffer, timeout)
|
'Performs a interrupt read request to the endpoint specified.
Arguments:
endpoint: endpoint number.
size: number of bytes to read.
timeout: operation timeout in milliseconds. (default: 100)
Returns a tuple with the data read.'
| def interruptRead(self, endpoint, size, timeout=100):
| return self.dev.read(endpoint, size, timeout)
|
'Perform a control request to the default control pipe on a device.
Arguments:
requestType: specifies the direction of data flow, the type
of request, and the recipient.
request: specifies the request.
buffer: if the transfer is a write transfer, buffer is a sequence
with the transfer data, otherwise, buffer is the num... | def controlMsg(self, requestType, request, buffer, value=0, index=0, timeout=100):
| return self.dev.ctrl_transfer(requestType, request, wValue=value, wIndex=index, data_or_wLength=buffer, timeout=timeout)
|
'Clears any halt status on the specified endpoint.
Arguments:
endpoint: endpoint number.'
| def clearHalt(self, endpoint):
| self.dev.clear_halt(endpoint)
|
'Claims the interface with the Operating System.
Arguments:
interface: interface number or an Interface object.'
| def claimInterface(self, interface):
| if isinstance(interface, Interface):
interface = interface.interfaceNumber
util.claim_interface(self.dev, interface)
self.__claimed_interface = interface
|
'Release an interface previously claimed with claimInterface.'
| def releaseInterface(self):
| util.release_interface(self.dev, self.__claimed_interface)
self.__claimed_interface = (-1)
|
'Reset the specified device by sending a RESET
down the port it is connected to.'
| def reset(self):
| self.dev.reset()
|
'Reset all states for the specified endpoint.
Arguments:
endpoint: endpoint number.'
| def resetEndpoint(self, endpoint):
| self.clearHalt(endpoint)
|
'Set the active configuration of a device.
Arguments:
configuration: a configuration value or a Configuration object.'
| def setConfiguration(self, configuration):
| if isinstance(configuration, Configuration):
configuration = configuration.value
self.dev.set_configuration(configuration)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.